Activate all packages before loading the settings config panel

This commit is contained in:
probablycorey
2013-06-27 16:11:22 -07:00
parent 7385bd97c6
commit 4dc2e48e8c
2 changed files with 62 additions and 38 deletions

View File

@@ -1,6 +1,8 @@
{$$, View} = require 'space-pen'
$ = require 'jquery'
_ = require 'underscore'
async = require 'async'
AtomPackage = require 'atom-package'
###
# Internal #
@@ -12,12 +14,29 @@ module.exports =
class SettingsPanel extends View
@content: ->
@form id: 'settings-panel', class: 'form-horizontal', =>
@div outlet: "loadingElement", class: 'alert alert-info loading-area', "Loading settings"
initialize: ->
window.setTimeout (=> @activatePackages => @showSettings()), 1
showSettings: ->
@loadingElement.hide()
@appendSettings(name, settings) for name, settings of config.getSettings()
@bindFormFields()
@bindEditors()
activatePackages: (finishedCallback) ->
iterator = (pack, callback) ->
try
if pack instanceof AtomPackage and not pack.isActive()
pack.activate({immediate: true})
catch e
console.error e
finally
callback()
async.map atom.getLoadedPackages(), iterator, finishedCallback
appendSettings: (namespace, settings) ->
return if _.isEmpty(settings)

View File

@@ -1,75 +1,80 @@
SettingsPanel = require '../lib/settings-panel'
Editor = require 'editor'
getValueForId = (panel, id) ->
element = panel.find("##{id.replace('.', '\\.')}")
if element.is("input")
element.attr('checked')?
else
element.view().getText()
setValueForId = (panel, id, value) ->
element = panel.find("##{id.replace('.', '\\.')}")
if element.is("input")
element.attr('checked', if value then 'checked' else '')
element.change()
else
element.view().setText(value?.toString())
window.advanceClock(10000) # wait for contents-modified to be triggered
describe "SettingsPanel", ->
it "automatically binds named fields to their corresponding config keys", ->
panel = null
getValueForId = (id) ->
element = panel.find("##{id.replace('.', '\\.')}")
if element.is("input")
element.attr('checked')?
else
element.view().getText()
setValueForId = (id, value) ->
element = panel.find("##{id.replace('.', '\\.')}")
if element.is("input")
element.attr('checked', if value then 'checked' else '')
element.change()
else
element.view().setText(value?.toString())
window.advanceClock(10000) # wait for contents-modified to be triggered
beforeEach ->
config.set('foo.int', 22)
config.set('foo.float', 0.1)
config.set('foo.boolean', true)
config.set('foo.string', 'hey')
panel = new SettingsPanel()
expect(getValueForId(panel, 'foo.int')).toBe '22'
expect(getValueForId(panel, 'foo.float')).toBe '0.1'
expect(getValueForId(panel, 'foo.boolean')).toBeTruthy()
expect(getValueForId(panel, 'foo.string')).toBe 'hey'
spyOn(panel, "showSettings").andCallThrough()
window.advanceClock(10000)
waitsFor ->
panel.showSettings.callCount > 0
it "automatically binds named fields to their corresponding config keys", ->
expect(getValueForId('foo.int')).toBe '22'
expect(getValueForId('foo.float')).toBe '0.1'
expect(getValueForId('foo.boolean')).toBeTruthy()
expect(getValueForId('foo.string')).toBe 'hey'
config.set('foo.int', 222)
config.set('foo.float', 0.11)
config.set('foo.boolean', false)
config.set('foo.string', 'hey again')
expect(getValueForId(panel, 'foo.int')).toBe '222'
expect(getValueForId(panel, 'foo.float')).toBe '0.11'
expect(getValueForId(panel, 'foo.boolean')).toBeFalsy()
expect(getValueForId(panel, 'foo.string')).toBe 'hey again'
expect(getValueForId('foo.int')).toBe '222'
expect(getValueForId('foo.float')).toBe '0.11'
expect(getValueForId('foo.boolean')).toBeFalsy()
expect(getValueForId('foo.string')).toBe 'hey again'
setValueForId(panel, 'foo.int', 90)
setValueForId(panel, 'foo.float', 89.2)
setValueForId(panel, 'foo.string', "oh hi")
setValueForId(panel, 'foo.boolean', true)
setValueForId('foo.int', 90)
setValueForId('foo.float', 89.2)
setValueForId('foo.string', "oh hi")
setValueForId('foo.boolean', true)
expect(config.get('foo.int')).toBe 90
expect(config.get('foo.float')).toBe 89.2
expect(config.get('foo.boolean')).toBe true
expect(config.get('foo.string')).toBe 'oh hi'
setValueForId(panel, 'foo.int', '')
setValueForId(panel, 'foo.float', '')
setValueForId(panel, 'foo.string', '')
setValueForId('foo.int', '')
setValueForId('foo.float', '')
setValueForId('foo.string', '')
expect(config.get('foo.int')).toBeUndefined()
expect(config.get('foo.float')).toBeUndefined()
expect(config.get('foo.string')).toBeUndefined()
it "does not save the config value until it has been changed to a new value", ->
config.set('foo.int', 1)
observeHandler = jasmine.createSpy("observeHandler")
config.observe "foo.int", observeHandler
observeHandler.reset()
testPanel = new SettingsPanel
window.advanceClock(10000) # wait for contents-modified to be triggered
expect(observeHandler).not.toHaveBeenCalled()
setValueForId(testPanel, 'foo.int', 2)
setValueForId('foo.int', 2)
expect(observeHandler).toHaveBeenCalled()
observeHandler.reset()
setValueForId(testPanel, 'foo.int', 2)
setValueForId('foo.int', 2)
expect(observeHandler).not.toHaveBeenCalled()