update docs and spec

This commit is contained in:
Shelley Vohr 2017-12-11 13:06:23 -05:00
parent c5aeda1fdd
commit 765f223fef
No known key found for this signature in database
GPG key ID: F13993A75599653C
2 changed files with 22 additions and 11 deletions

View file

@ -110,10 +110,9 @@ Same as `unsubscribeNotification`, but removes the subscriber from `NSNotificati
* `defaults` Object - a dictionary of (`key: value`) user defaults
* `key` String
* `value` (String | Boolean | Number) - object of type `string`, `boolean`, `integer`, `float`, `double`,
`url`, `array`, or `dictionary`.
* `value` (String | Boolean | Int | Float | Double | Array | Dictionary)
Allows for registering of your application's preference defaults in `NSUserDefaults`.
Add the specified defaults to your application's `NSUserDefaults`.
### `systemPreferences.getUserDefault(key, type)` _macOS_

View file

@ -35,32 +35,44 @@ describe('systemPreferences module', () => {
})
})
describe('systemPreferences.registerDefaults(defaults)', () => {
describe.only('systemPreferences.registerDefaults(defaults)', () => {
before(function () {
if (process.platform !== 'darwin') this.skip()
})
it('registers defaults', () => {
const userDefaults = {
const defaultsDict = {
'one': 'ONE',
'two': 'TWO',
'three': 'THREE'
'two': 2,
'three': [1, 2, 3]
}
systemPreferences.registerDefaults(userDefaults)
const defaultsMap = [
{ key: 'one', type: 'string', value: 'ONE' },
{ key: 'two', value: 2, type: 'integer' },
{ key: 'three', value: [1, 2, 3], type: 'array' }
]
for (const [key, expectedValue] of Object.entries(userDefaults)) {
const actualValue = systemPreferences.getUserDefault(key, 'string')
assert.equal(actualValue, expectedValue)
systemPreferences.registerDefaults(defaultsDict)
for (const def of defaultsMap) {
const [key, expectedValue, type] = [def.key, def.value, def.type]
const actualValue = systemPreferences.getUserDefault(key, type)
assert.deepEqual(actualValue, expectedValue)
}
})
it('throws when bad defaults are passed', () => {
const badDefaults1 = { 'one': null }
//const badDefaults1 = { 'one': null }
assert.throws(() => {
systemPreferences.registerDefaults(badDefaults1)
}, 'Invalid userDefault data provided')
//
// assert.throws(() => {
// systemPreferences.registerDefaults(badDefaults1)
// }, 'Invalid userDefault data provided')
})
})