2020-03-20 20:28:31 +00:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import { nativeTheme, systemPreferences } from 'electron';
|
|
|
|
import * as os from 'os';
|
|
|
|
import * as semver from 'semver';
|
2019-09-05 17:57:04 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
import { delay, ifdescribe } from './spec-helpers';
|
|
|
|
import { emittedOnce } from './events-helpers';
|
2019-08-14 20:42:55 +00:00
|
|
|
|
2019-09-16 23:08:41 +00:00
|
|
|
describe('nativeTheme module', () => {
|
2019-08-14 20:42:55 +00:00
|
|
|
describe('nativeTheme.shouldUseDarkColors', () => {
|
|
|
|
it('returns a boolean', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nativeTheme.shouldUseDarkColors).to.be.a('boolean');
|
|
|
|
});
|
|
|
|
});
|
2019-08-14 20:42:55 +00:00
|
|
|
|
2019-09-05 17:57:04 +00:00
|
|
|
describe('nativeTheme.themeSource', () => {
|
2019-09-16 23:08:01 +00:00
|
|
|
afterEach(async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
nativeTheme.themeSource = 'system';
|
2019-09-16 23:08:01 +00:00
|
|
|
// Wait for any pending events to emit
|
2020-03-20 20:28:31 +00:00
|
|
|
await delay(20);
|
|
|
|
});
|
2019-09-05 17:57:04 +00:00
|
|
|
|
|
|
|
it('is system by default', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nativeTheme.themeSource).to.equal('system');
|
|
|
|
});
|
2019-09-05 17:57:04 +00:00
|
|
|
|
|
|
|
it('should override the value of shouldUseDarkColors', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
nativeTheme.themeSource = 'dark';
|
|
|
|
expect(nativeTheme.shouldUseDarkColors).to.equal(true);
|
|
|
|
nativeTheme.themeSource = 'light';
|
|
|
|
expect(nativeTheme.shouldUseDarkColors).to.equal(false);
|
|
|
|
});
|
2019-09-05 17:57:04 +00:00
|
|
|
|
2019-09-16 23:08:01 +00:00
|
|
|
it('should emit the "updated" event when it is set and the resulting "shouldUseDarkColors" value changes', async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let updatedEmitted = emittedOnce(nativeTheme, 'updated');
|
|
|
|
nativeTheme.themeSource = 'dark';
|
|
|
|
await updatedEmitted;
|
|
|
|
updatedEmitted = emittedOnce(nativeTheme, 'updated');
|
|
|
|
nativeTheme.themeSource = 'light';
|
|
|
|
await updatedEmitted;
|
|
|
|
});
|
2019-09-05 17:57:04 +00:00
|
|
|
|
2019-09-16 23:08:01 +00:00
|
|
|
it('should not emit the "updated" event when it is set and the resulting "shouldUseDarkColors" value is the same', async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
nativeTheme.themeSource = 'dark';
|
2019-09-16 23:08:01 +00:00
|
|
|
// Wait a few ticks to allow an async events to flush
|
2020-03-20 20:28:31 +00:00
|
|
|
await delay(20);
|
|
|
|
let called = false;
|
2019-09-05 17:57:04 +00:00
|
|
|
nativeTheme.once('updated', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
called = true;
|
|
|
|
});
|
|
|
|
nativeTheme.themeSource = 'dark';
|
2019-09-16 23:08:01 +00:00
|
|
|
// Wait a few ticks to allow an async events to flush
|
2020-03-20 20:28:31 +00:00
|
|
|
await delay(20);
|
|
|
|
expect(called).to.equal(false);
|
|
|
|
});
|
2019-09-05 17:57:04 +00:00
|
|
|
|
|
|
|
ifdescribe(process.platform === 'darwin' && semver.gte(os.release(), '18.0.0'))('on macOS 10.14', () => {
|
|
|
|
it('should update appLevelAppearance when set', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
nativeTheme.themeSource = 'dark';
|
|
|
|
expect(systemPreferences.appLevelAppearance).to.equal('dark');
|
|
|
|
nativeTheme.themeSource = 'light';
|
|
|
|
expect(systemPreferences.appLevelAppearance).to.equal('light');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-09-05 17:57:04 +00:00
|
|
|
|
2019-08-14 20:42:55 +00:00
|
|
|
describe('nativeTheme.shouldUseInvertedColorScheme', () => {
|
|
|
|
it('returns a boolean', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nativeTheme.shouldUseInvertedColorScheme).to.be.a('boolean');
|
|
|
|
});
|
|
|
|
});
|
2019-08-14 20:42:55 +00:00
|
|
|
|
|
|
|
describe('nativeTheme.shouldUseHighContrastColors', () => {
|
|
|
|
it('returns a boolean', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(nativeTheme.shouldUseHighContrastColors).to.be.a('boolean');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|