fixes from review
This commit is contained in:
parent
027e78639a
commit
a8e67e7f61
2 changed files with 15 additions and 26 deletions
|
@ -150,7 +150,6 @@ void SystemPreferences::RegisterDefaults(mate::Arguments* args) {
|
||||||
if(!args->GetNext(&value)) {
|
if(!args->GetNext(&value)) {
|
||||||
args->ThrowError("Invalid userDefault data provided");
|
args->ThrowError("Invalid userDefault data provided");
|
||||||
} else {
|
} else {
|
||||||
args->GetNext(&value);
|
|
||||||
@try {
|
@try {
|
||||||
NSDictionary* dict = DictionaryValueToNSDictionary(value);
|
NSDictionary* dict = DictionaryValueToNSDictionary(value);
|
||||||
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
|
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
|
||||||
|
|
|
@ -41,45 +41,35 @@ describe('systemPreferences module', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('registers defaults', () => {
|
it('registers defaults', () => {
|
||||||
// to pass into registerDefaults
|
|
||||||
const defaultsDict = {
|
|
||||||
'one': 'ONE',
|
|
||||||
'two': 2,
|
|
||||||
'three': [1, 2, 3]
|
|
||||||
}
|
|
||||||
|
|
||||||
// to test type
|
|
||||||
const defaultsMap = [
|
const defaultsMap = [
|
||||||
{ key: 'one', type: 'string', value: 'ONE' },
|
{ key: 'one', type: 'string', value: 'ONE' },
|
||||||
{ key: 'two', value: 2, type: 'integer' },
|
{ key: 'two', value: 2, type: 'integer' },
|
||||||
{ key: 'three', value: [1, 2, 3], type: 'array' }
|
{ key: 'three', value: [1, 2, 3], type: 'array' }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const defaultsDict = {}
|
||||||
|
defaultsMap.forEach(row => { defaultsDict[row.key] = row.value })
|
||||||
|
|
||||||
systemPreferences.registerDefaults(defaultsDict)
|
systemPreferences.registerDefaults(defaultsDict)
|
||||||
|
|
||||||
for (const def of defaultsMap) {
|
for (const userDefault of defaultsMap) {
|
||||||
const [key, expectedValue, type] = [def.key, def.value, def.type]
|
const { key, value: expectedValue, type } = userDefault
|
||||||
const actualValue = systemPreferences.getUserDefault(key, type)
|
const actualValue = systemPreferences.getUserDefault(key, type)
|
||||||
assert.deepEqual(actualValue, expectedValue)
|
assert.deepEqual(actualValue, expectedValue)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws when bad defaults are passed', () => {
|
it('throws when bad defaults are passed', () => {
|
||||||
const badDefaults1 = { 'one': null } // catches null values
|
for (const badDefaults of [
|
||||||
const badDefaults2 = 1 // argument must be a dictionary
|
{ 'one': null }, // catches null values
|
||||||
const badDefaults3 = null // argument can't be null
|
1, // argument must be a dictionary
|
||||||
|
null, // argument can't be null
|
||||||
assert.throws(() => {
|
new Date() // shouldn't be able to pass date object
|
||||||
systemPreferences.registerDefaults(badDefaults1)
|
]) {
|
||||||
}, 'Invalid userDefault data provided')
|
assert.throws(() => {
|
||||||
|
systemPreferences.registerDefaults(badDefaults)
|
||||||
assert.throws(() => {
|
}, 'Invalid userDefault data provided')
|
||||||
systemPreferences.registerDefaults(badDefaults2)
|
}
|
||||||
}, 'Invalid userDefault data provided')
|
|
||||||
|
|
||||||
assert.throws(() => {
|
|
||||||
systemPreferences.registerDefaults(badDefaults3)
|
|
||||||
}, 'Invalid userDefault data provided')
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue