test: add tests for systemPreferences apis (#19419)
This commit is contained in:
parent
898adbce5c
commit
9dfc4eb2ff
2 changed files with 51 additions and 2 deletions
|
@ -338,6 +338,8 @@ See the [Windows docs][windows-colors] and the [MacOS docs][macos-colors] for mo
|
||||||
* `red`
|
* `red`
|
||||||
* `yellow`
|
* `yellow`
|
||||||
|
|
||||||
|
Returns `String` - The standard system color formatted as `#RRGGBBAA`.
|
||||||
|
|
||||||
Returns one of several standard system colors that automatically adapt to vibrancy and changes in accessibility settings like 'Increase contrast' and 'Reduce transparency'. See [Apple Documentation](https://developer.apple.com/design/human-interface-guidelines/macos/visual-design/color#system-colors) for more details.
|
Returns one of several standard system colors that automatically adapt to vibrancy and changes in accessibility settings like 'Increase contrast' and 'Reduce transparency'. See [Apple Documentation](https://developer.apple.com/design/human-interface-guidelines/macos/visual-design/color#system-colors) for more details.
|
||||||
|
|
||||||
### `systemPreferences.isInvertedColorScheme()` _Windows_
|
### `systemPreferences.isInvertedColorScheme()` _Windows_
|
||||||
|
@ -371,6 +373,8 @@ Gets the macOS appearance setting that you have declared you want for
|
||||||
your application, maps to [NSApplication.appearance](https://developer.apple.com/documentation/appkit/nsapplication/2967170-appearance?language=objc).
|
your application, maps to [NSApplication.appearance](https://developer.apple.com/documentation/appkit/nsapplication/2967170-appearance?language=objc).
|
||||||
You can use the `setAppLevelAppearance` API to set this value.
|
You can use the `setAppLevelAppearance` API to set this value.
|
||||||
|
|
||||||
|
**[Deprecated](modernization/property-updates.md)**
|
||||||
|
|
||||||
### `systemPreferences.setAppLevelAppearance(appearance)` _macOS_
|
### `systemPreferences.setAppLevelAppearance(appearance)` _macOS_
|
||||||
|
|
||||||
* `appearance` String | null - Can be `dark` or `light`
|
* `appearance` String | null - Can be `dark` or `light`
|
||||||
|
@ -451,3 +455,5 @@ your application. This maps to values in: [NSApplication.appearance](https://dev
|
||||||
system default as well as the value of `getEffectiveAppearance`.
|
system default as well as the value of `getEffectiveAppearance`.
|
||||||
|
|
||||||
Possible values that can be set are `dark` and `light`, and possible return values are `dark`, `light`, and `unknown`.
|
Possible values that can be set are `dark` and `light`, and possible return values are `dark`, `light`, and `unknown`.
|
||||||
|
|
||||||
|
This property is only available on macOS 10.14 Mojave or newer.
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { systemPreferences } from 'electron'
|
import { systemPreferences } from 'electron'
|
||||||
|
import { ifdescribe } from './spec-helpers'
|
||||||
const ifdescribe = (condition: boolean) => (condition ? describe : describe.skip)
|
|
||||||
|
|
||||||
describe('systemPreferences module', () => {
|
describe('systemPreferences module', () => {
|
||||||
ifdescribe(process.platform === 'win32')('systemPreferences.getAccentColor', () => {
|
ifdescribe(process.platform === 'win32')('systemPreferences.getAccentColor', () => {
|
||||||
|
@ -117,6 +116,17 @@ describe('systemPreferences module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ifdescribe(process.platform === 'darwin')('systemPreferences.getSystemColor(color)', () => {
|
||||||
|
it('returns a valid system color', () => {
|
||||||
|
const colors = ['blue', 'brown', 'gray', 'green', 'orange', 'pink', 'purple', 'red', 'yellow']
|
||||||
|
|
||||||
|
colors.forEach(color => {
|
||||||
|
const sysColor = systemPreferences.getSystemColor(color as any)
|
||||||
|
expect(sysColor).to.be.a('string')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
ifdescribe(process.platform === 'darwin')('systemPreferences.appLevelAppearance', () => {
|
ifdescribe(process.platform === 'darwin')('systemPreferences.appLevelAppearance', () => {
|
||||||
it('has an appLevelAppearance property', () => {
|
it('has an appLevelAppearance property', () => {
|
||||||
expect(systemPreferences).to.have.property('appLevelAppearance')
|
expect(systemPreferences).to.have.property('appLevelAppearance')
|
||||||
|
@ -146,6 +156,39 @@ describe('systemPreferences module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('systemPreferences.isHighContrastColorScheme()', () => {
|
||||||
|
it('returns a boolean', () => {
|
||||||
|
expect(systemPreferences.isHighContrastColorScheme()).to.be.a('boolean')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
ifdescribe(process.platform === 'darwin')('systemPreferences.canPromptTouchID()', () => {
|
||||||
|
it('returns a boolean', () => {
|
||||||
|
expect(systemPreferences.canPromptTouchID()).to.be.a('boolean')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
ifdescribe(process.platform === 'darwin')('systemPreferences.isTrustedAccessibilityClient(prompt)', () => {
|
||||||
|
it('returns a boolean', () => {
|
||||||
|
const trusted = systemPreferences.isTrustedAccessibilityClient(false)
|
||||||
|
expect(trusted).to.be.a('boolean')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
ifdescribe(process.platform === 'darwin')('systemPreferences.getMediaAccessStatus(mediaType)', () => {
|
||||||
|
const statuses = ['not-determined', 'granted', 'denied', 'restricted', 'unknown']
|
||||||
|
|
||||||
|
it('returns an access status for a camera access request', () => {
|
||||||
|
const cameraStatus = systemPreferences.getMediaAccessStatus('camera')
|
||||||
|
expect(statuses).to.include(cameraStatus)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns an access status for a microphone access request', () => {
|
||||||
|
const microphoneStatus = systemPreferences.getMediaAccessStatus('microphone')
|
||||||
|
expect(statuses).to.include(microphoneStatus)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('systemPreferences.getAnimationSettings()', () => {
|
describe('systemPreferences.getAnimationSettings()', () => {
|
||||||
it('returns an object with all properties', () => {
|
it('returns an object with all properties', () => {
|
||||||
const settings = systemPreferences.getAnimationSettings()
|
const settings = systemPreferences.getAnimationSettings()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue