forked from GetmeUK/ContentTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspector.coffee
More file actions
199 lines (144 loc) · 6.03 KB
/
Copy pathinspector.coffee
File metadata and controls
199 lines (144 loc) · 6.03 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# InspectorUI
describe 'ContentTools.InspectorUI', () ->
div = null
editor = null
beforeEach ->
# Create an editable region
div = document.createElement('div')
div.setAttribute('class', 'editable')
div.setAttribute('id', 'foo')
document.body.appendChild(div)
div.innerHTML = '''
<p>bar</p>
<ul>
<li>zee</li>
</ul>
'''
# Initialize the editor
editor = ContentTools.EditorApp.get()
editor.init('.editable')
afterEach ->
# Shutdown the editor
editor.destroy()
# Remove the editable region
document.body.removeChild(div)
describe 'ContentTools.InspectorUI()', () ->
it 'should return an instance of a InspectorUI', () ->
inspector = new ContentTools.InspectorUI()
expect(inspector instanceof ContentTools.InspectorUI).toBe true
describe 'ContentTools.InspectorUI.mount()', () ->
it 'should mount the component', () ->
inspector = new ContentTools.InspectorUI()
editor.attach(inspector)
inspector.mount()
expect(inspector.isMounted()).toBe true
describe 'ContentTools.InspectorUI.unmount()', () ->
it 'should unmount the component', () ->
inspector = new ContentTools.InspectorUI()
editor.attach(inspector)
inspector.mount()
inspector.unmount()
expect(inspector.isMounted()).toBe false
describe 'ContentTools.InspectorUI.updateTags()', () ->
it 'should update the tags displayed to reflect the path to the current
element', () ->
# Start the editor so the document is editable
editor.start()
inspector = editor._inspector
region = editor.regions()['foo']
elements = region.children
# NOTE: Changing the focus of an element triggers the updateTags
# method.
# Select the first editable element (a <p> tag) and check the tag
# path.
elements[0].focus()
expect(inspector._tagUIs.length).toEqual 1
expect(inspector._tagUIs[0].element.tagName()).toEqual 'p'
# Select the second editable element (a <li> tag) and check the tag
# path.
elements[1].children[0].children[0].focus()
expect(inspector._tagUIs.length).toEqual 2
expect(inspector._tagUIs[0].element.tagName()).toEqual 'ul'
expect(inspector._tagUIs[1].element.tagName()).toEqual 'li'
editor.stop()
# TagUI
describe 'ContentTools.TagUI', () ->
div = null
editor = null
beforeEach ->
# Create an editable region
div = document.createElement('div')
div.setAttribute('class', 'editable')
div.setAttribute('id', 'foo')
document.body.appendChild(div)
div.innerHTML = '''
<p>bar</p>
<ul>
<li>zee</li>
</ul>
'''
# Initialize the editor
editor = ContentTools.EditorApp.get()
editor.init('.editable')
afterEach ->
# Shutdown the editor
editor.destroy()
# Remove the editable region
document.body.removeChild(div)
describe 'ContentTools.TagUI()', () ->
it 'should return an instance of a TagUI', () ->
tag = new ContentTools.TagUI()
expect(tag instanceof ContentTools.TagUI).toBe true
describe 'ContentTools.TagUI.mount()', () ->
it 'should mount the component', () ->
# Start the editor so the document is editable
editor.start()
inspector = editor._inspector
region = editor.regions()['foo']
elements = region.children
# Manually mout the element on to the inspector bar
tag = new ContentTools.TagUI(elements[0])
tag.mount(inspector._domTags)
expect(tag.isMounted()).toBe true
describe 'ContentTools.TagUI > Interaction', () ->
it 'should allow the properties dialog to be used', () ->
# Start the editor so the document is editable
editor.start()
inspector = editor._inspector
region = editor.regions()['foo']
element = region.children[0]
element.focus()
tag = inspector._tagUIs[0]
# Click the tag and check if a properties dialog is opened
mouseDownEvent = document.createEvent('CustomEvent')
mouseDownEvent.initCustomEvent('mousedown', false, false, null)
tag.domElement().dispatchEvent(mouseDownEvent)
# Check a properties dialog was opened
app = ContentTools.EditorApp.get()
dialog = app.children()[app.children().length - 1]
expect(dialog instanceof ContentTools.PropertiesDialog).toBe true
# Trigger a save event against the dialog and test that the changes
# are applied correctly.
dialog.dispatchEvent(
dialog.createEvent('save', {
changedAttributes: {title: 'bar'},
changedStyles: {'zee': true},
innerHTML: 'foo'
})
)
expect(element.attr('title')).toBe 'bar'
expect(element.hasCSSClass('zee')).toBe true
expect(element.content.html()).toBe 'foo'
# Test the changes can be reverted
tag.domElement().dispatchEvent(mouseDownEvent)
dialog = app.children()[app.children().length - 1]
dialog.dispatchEvent(
dialog.createEvent('save', {
changedAttributes: {title: null},
changedStyles: {'zee': false},
innerHTML: 'bar'
})
)
expect(element.attr('title')).toBe undefined
expect(element.hasCSSClass('zee')).toBe false
expect(element.content.html()).toBe 'bar'