Browse Source

test: add tests for systemPreferences apis (#19419)

Shelley Vohr 5 years ago
parent
commit
9dfc4eb2ff
2 changed files with 51 additions and 2 deletions
  1. 6 0
      docs/api/system-preferences.md
  2. 45 2
      spec-main/api-system-preferences-spec.ts

+ 6 - 0
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.

+ 45 - 2
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()