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 * `defaults` Object - a dictionary of (`key: value`) user defaults
* `key` String * `key` String
* `value` (String | Boolean | Number) - object of type `string`, `boolean`, `integer`, `float`, `double`, * `value` (String | Boolean | Int | Float | Double | Array | Dictionary)
`url`, `array`, or `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_ ### `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 () { before(function () {
if (process.platform !== 'darwin') this.skip() if (process.platform !== 'darwin') this.skip()
}) })
it('registers defaults', () => { it('registers defaults', () => {
const userDefaults = { const defaultsDict = {
'one': 'ONE', 'one': 'ONE',
'two': 'TWO', 'two': 2,
'three': 'THREE' '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)) { systemPreferences.registerDefaults(defaultsDict)
const actualValue = systemPreferences.getUserDefault(key, 'string')
assert.equal(actualValue, expectedValue) 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', () => { it('throws when bad defaults are passed', () => {
const badDefaults1 = { 'one': null } const badDefaults1 = { 'one': null }
//const badDefaults1 = { 'one': null }
assert.throws(() => { assert.throws(() => {
systemPreferences.registerDefaults(badDefaults1) systemPreferences.registerDefaults(badDefaults1)
}, 'Invalid userDefault data provided') }, 'Invalid userDefault data provided')
//
// assert.throws(() => {
// systemPreferences.registerDefaults(badDefaults1)
// }, 'Invalid userDefault data provided')
}) })
}) })