Skip to content

Commit

Permalink
fixes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Dec 11, 2017
1 parent 027e786 commit a8e67e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
1 change: 0 additions & 1 deletion atom/browser/api/atom_api_system_preferences_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
if(!args->GetNext(&value)) {
args->ThrowError("Invalid userDefault data provided");
} else {
args->GetNext(&value);
@try {
NSDictionary* dict = DictionaryValueToNSDictionary(value);
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
Expand Down
40 changes: 15 additions & 25 deletions spec/api-system-preferences-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,35 @@ describe('systemPreferences module', () => {
})

it('registers defaults', () => {
// to pass into registerDefaults
const defaultsDict = {
'one': 'ONE',
'two': 2,
'three': [1, 2, 3]
}

// to test type
const defaultsMap = [
{ key: 'one', type: 'string', value: 'ONE' },
{ key: 'two', value: 2, type: 'integer' },
{ key: 'three', value: [1, 2, 3], type: 'array' }
]

const defaultsDict = {}
defaultsMap.forEach(row => { defaultsDict[row.key] = row.value })

systemPreferences.registerDefaults(defaultsDict)

for (const def of defaultsMap) {
const [key, expectedValue, type] = [def.key, def.value, def.type]
for (const userDefault of defaultsMap) {
const { key, value: expectedValue, type } = userDefault
const actualValue = systemPreferences.getUserDefault(key, type)
assert.deepEqual(actualValue, expectedValue)
}
})

it('throws when bad defaults are passed', () => {
const badDefaults1 = { 'one': null } // catches null values
const badDefaults2 = 1 // argument must be a dictionary
const badDefaults3 = null // argument can't be null

assert.throws(() => {
systemPreferences.registerDefaults(badDefaults1)
}, 'Invalid userDefault data provided')

assert.throws(() => {
systemPreferences.registerDefaults(badDefaults2)
}, 'Invalid userDefault data provided')

assert.throws(() => {
systemPreferences.registerDefaults(badDefaults3)
}, 'Invalid userDefault data provided')
for (const badDefaults of [
{ 'one': null }, // catches null values
1, // argument must be a dictionary
null, // argument can't be null
new Date() // shouldn't be able to pass date object
]) {
assert.throws(() => {
systemPreferences.registerDefaults(badDefaults)
}, 'Invalid userDefault data provided')
}
})
})

Expand Down

0 comments on commit a8e67e7

Please sign in to comment.