forked from atom/settings-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor-panel-spec.coffee
110 lines (88 loc) · 4.44 KB
/
editor-panel-spec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
EditorPanel = require '../lib/editor-panel'
describe "EditorPanel", ->
panel = null
getValueForId = (id) ->
element = panel.element.querySelector("##{id.replace(/\./g, '\\.')}")
if element?.tagName is "INPUT"
element.checked
else if element?.tagName is "SELECT"
element.value
else if element?
element.getModel().getText()
else
return
setValueForId = (id, value) ->
element = panel.element.querySelector("##{id.replace(/\./g, '\\.')}")
if element.tagName is "INPUT"
element.checked = value
element.dispatchEvent(new Event('change', {bubbles: true}))
else if element.tagName is "SELECT"
element.value = value
element.dispatchEvent(new Event('change', {bubbles: true}))
else
element.getModel().setText(value?.toString())
window.advanceClock(10000) # wait for contents-modified to be triggered
beforeEach ->
atom.config.set('editor.boolean', true)
atom.config.set('editor.string', 'hey')
atom.config.set('editor.object', {boolean: true, int: 3, string: 'test'})
atom.config.set('editor.simpleArray', ['a', 'b', 'c'])
atom.config.set('editor.complexArray', ['a', 'b', {c: true}])
atom.config.setSchema('', type: 'object')
panel = new EditorPanel()
it "automatically binds named fields to their corresponding config keys", ->
expect(getValueForId('editor.boolean')).toBeTruthy()
expect(getValueForId('editor.string')).toBe 'hey'
expect(getValueForId('editor.object.boolean')).toBeTruthy()
expect(getValueForId('editor.object.int')).toBe '3'
expect(getValueForId('editor.object.string')).toBe 'test'
atom.config.set('editor.boolean', false)
atom.config.set('editor.string', 'hey again')
atom.config.set('editor.object.boolean', false)
atom.config.set('editor.object.int', 6)
atom.config.set('editor.object.string', 'hi')
expect(getValueForId('editor.boolean')).toBeFalsy()
expect(getValueForId('editor.string')).toBe 'hey again'
expect(getValueForId('editor.object.boolean')).toBeFalsy()
expect(getValueForId('editor.object.int')).toBe '6'
expect(getValueForId('editor.object.string')).toBe 'hi'
setValueForId('editor.string', "oh hi")
setValueForId('editor.boolean', true)
setValueForId('editor.object.boolean', true)
setValueForId('editor.object.int', 9)
setValueForId('editor.object.string', 'yo')
expect(atom.config.get('editor.boolean')).toBe true
expect(atom.config.get('editor.string')).toBe 'oh hi'
expect(atom.config.get('editor.object.boolean')).toBe true
expect(atom.config.get('editor.object.int')).toBe 9
expect(atom.config.get('editor.object.string')).toBe 'yo'
setValueForId('editor.string', '')
setValueForId('editor.object.int', '')
setValueForId('editor.object.string', '')
expect(atom.config.get('editor.string')).toBeUndefined()
expect(atom.config.get('editor.object.int')).toBeUndefined()
expect(atom.config.get('editor.object.string')).toBeUndefined()
it "does not save the config value until it has been changed to a new value", ->
observeHandler = jasmine.createSpy("observeHandler")
atom.config.observe "editor.simpleArray", observeHandler
observeHandler.reset()
window.advanceClock(10000) # wait for contents-modified to be triggered
expect(observeHandler).not.toHaveBeenCalled()
setValueForId('editor.simpleArray', 2)
expect(observeHandler).toHaveBeenCalled()
observeHandler.reset()
setValueForId('editor.simpleArray', 2)
expect(observeHandler).not.toHaveBeenCalled()
it "does not update the editor text unless the value it parses to changes", ->
setValueForId('editor.simpleArray', "a, b,")
expect(atom.config.get('editor.simpleArray')).toEqual ['a', 'b']
expect(getValueForId('editor.simpleArray')).toBe 'a, b,'
it "only adds editors for arrays when all the values in the array are strings", ->
expect(getValueForId('editor.simpleArray')).toBe 'a, b, c'
expect(getValueForId('editor.complexArray')).toBeUndefined()
setValueForId('editor.simpleArray', 'a, d')
expect(atom.config.get('editor.simpleArray')).toEqual ['a', 'd']
expect(atom.config.get('editor.complexArray')).toEqual ['a', 'b', {c: true}]
it "shows the package settings notes for core and editor settings", ->
expect(panel.element.querySelector('#editor-settings-note')).toExist()
expect(panel.element.querySelector('#editor-settings-note').textContent).toContain('Check language settings')