-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1780 from microsoft/corinagum/1713
#1713 Switch High Contrast based off System Preferences
- Loading branch information
Showing
5 changed files
with
162 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. | ||
// | ||
// Microsoft Bot Framework: http://botframework.com | ||
// | ||
// Bot Framework Emulator Github: | ||
// https://github.com/Microsoft/BotFramwork-Emulator | ||
// | ||
// Copyright (c) Microsoft Corporation | ||
// All rights reserved. | ||
// | ||
// MIT License: | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// | ||
|
||
import * as path from 'path'; | ||
|
||
import { CommandServiceImpl, CommandServiceInstance } from '@bfemulator/sdk-shared'; | ||
import { SharedConstants } from '@bfemulator/app-shared'; | ||
import { systemPreferences } from 'electron'; | ||
|
||
import { emulatorApplication } from './main'; | ||
|
||
jest.mock('electron', () => ({ | ||
app: { | ||
on: () => void 0, | ||
setName: () => void 0, | ||
}, | ||
ipcMain: new Proxy( | ||
{}, | ||
{ | ||
get(): any { | ||
return () => ({}); | ||
}, | ||
has() { | ||
return true; | ||
}, | ||
} | ||
), | ||
ipcRenderer: new Proxy( | ||
{}, | ||
{ | ||
get(): any { | ||
return () => ({}); | ||
}, | ||
has() { | ||
return true; | ||
}, | ||
} | ||
), | ||
systemPreferences: { | ||
isInvertedColorScheme: jest.fn(() => true), | ||
on: jest.fn(() => null), | ||
onInvertedColorSchemeChanged: jest.fn(() => true), | ||
}, | ||
})); | ||
|
||
describe('main', () => { | ||
let commandService: CommandServiceImpl; | ||
let emulatorAppSpy; | ||
|
||
beforeEach(() => { | ||
emulatorAppSpy = jest.spyOn(emulatorApplication as any, 'onInvertedColorSchemeChanged'); | ||
const decorator = CommandServiceInstance(); | ||
const descriptor = decorator({ descriptor: {} }, 'none') as any; | ||
commandService = descriptor.descriptor.get(); | ||
}); | ||
|
||
afterEach(() => { | ||
emulatorAppSpy.mockClear(); | ||
}); | ||
|
||
it('should call `onInvertedColorSchemeChanged` when `inverted-color-scheme-changed` event is triggered', () => { | ||
const onSpy = jest.spyOn(systemPreferences, 'on'); | ||
|
||
(emulatorApplication as any).initializeSystemPreferencesListeners(); | ||
|
||
expect(onSpy).toHaveBeenCalledWith('inverted-color-scheme-changed', jasmine.any(Function)); | ||
|
||
onSpy.mockClear(); | ||
}); | ||
|
||
it('should call command to invert colors `onInvertedColorSchemeChanged`', () => { | ||
const commandServiceSpy = jest.spyOn(commandService, 'remoteCall'); | ||
|
||
(emulatorApplication as any).onInvertedColorSchemeChanged(); | ||
|
||
expect(commandServiceSpy).toHaveBeenCalledTimes(1); | ||
expect(commandServiceSpy).toHaveBeenCalledWith( | ||
SharedConstants.Commands.UI.SwitchTheme, | ||
'high-contrast', | ||
path.join('.', 'themes', 'high-contrast.css') | ||
); | ||
|
||
commandServiceSpy.mockClear(); | ||
}); | ||
|
||
it('should not change to high contrast when theme is not high contrast', () => { | ||
const commandServiceSpy = jest.spyOn(commandService, 'remoteCall'); | ||
|
||
(systemPreferences.isInvertedColorScheme as any).mockImplementationOnce(() => false); | ||
|
||
(emulatorApplication as any).onInvertedColorSchemeChanged(); | ||
|
||
expect(commandServiceSpy).toBeCalledTimes(1); | ||
|
||
expect(commandServiceSpy).toHaveBeenCalledWith( | ||
SharedConstants.Commands.UI.SwitchTheme, | ||
'Light', | ||
'./themes/light.css' | ||
); | ||
|
||
commandServiceSpy.mockClear(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters