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