From 9dfc4eb2ff675f8bd01d0603f9e1ab62e21a1f7c Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 24 Jul 2019 10:40:12 -0700 Subject: [PATCH] test: add tests for systemPreferences apis (#19419) --- docs/api/system-preferences.md | 6 +++ spec-main/api-system-preferences-spec.ts | 47 +++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index 7f500da1cf52..672709817a3c 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -338,6 +338,8 @@ See the [Windows docs][windows-colors] and the [MacOS docs][macos-colors] for mo * `red` * `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. ### `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). You can use the `setAppLevelAppearance` API to set this value. +**[Deprecated](modernization/property-updates.md)** + ### `systemPreferences.setAppLevelAppearance(appearance)` _macOS_ * `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`. 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. diff --git a/spec-main/api-system-preferences-spec.ts b/spec-main/api-system-preferences-spec.ts index ec85577893a4..98b77b2899b5 100644 --- a/spec-main/api-system-preferences-spec.ts +++ b/spec-main/api-system-preferences-spec.ts @@ -1,7 +1,6 @@ import { expect } from 'chai' import { systemPreferences } from 'electron' - -const ifdescribe = (condition: boolean) => (condition ? describe : describe.skip) +import { ifdescribe } from './spec-helpers' describe('systemPreferences module', () => { 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', () => { it('has an appLevelAppearance property', () => { 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()', () => { it('returns an object with all properties', () => { const settings = systemPreferences.getAnimationSettings()