forked from GetmeUK/ContentTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialogs.coffee
More file actions
153 lines (100 loc) · 4.31 KB
/
Copy pathdialogs.coffee
File metadata and controls
153 lines (100 loc) · 4.31 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
# AnchoredDialogUI
describe 'ContentTools.AnchoredDialogUI', () ->
div = null
editor = null
beforeEach ->
# Create an editable region
div = document.createElement('div')
div.setAttribute('class', 'editable')
document.body.appendChild(div)
# 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.AnchoredDialogUI()', () ->
it 'should return an instance of a AnchoredDialogUI', () ->
dialog = new ContentTools.AnchoredDialogUI()
expect(dialog instanceof ContentTools.AnchoredDialogUI).toBe true
describe 'ContentTools.AnchoredDialogUI.mount()', () ->
it 'should mount the dialog', () ->
dialog = new ContentTools.AnchoredDialogUI()
editor.attach(dialog)
dialog.mount()
expect(dialog.isMounted()).toBe true
describe 'ContentTools.AnchoredDialogUI.position()', () ->
it 'should set/get the dialog\'s position', () ->
dialog = new ContentTools.AnchoredDialogUI()
editor.attach(dialog)
dialog.mount()
# Initially the should be dialog's position should be [0, 0]
expect(dialog.position()).toEqual [0 ,0]
# Set a new position and check that it's been applied
dialog.position([7, 7])
style = dialog.domElement().style
expect(dialog.position()).toEqual [7 ,7]
expect(style.top).toBe '7px'
expect(style.left).toBe '7px'
# DialogUI
describe 'ContentTools.DialogUI', () ->
div = null
editor = null
beforeEach ->
# Create an editable region
div = document.createElement('div')
div.setAttribute('class', 'editable')
document.body.appendChild(div)
# 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.DialogUI()', () ->
it 'should return an instance of a DialogUI', () ->
dialog = new ContentTools.DialogUI('foo')
expect(dialog instanceof ContentTools.DialogUI).toBe true
describe 'ContentTools.DialogUI.busy()', () ->
it 'should set/get the busy state for the dialog', () ->
dialog = new ContentTools.DialogUI('foo')
editor.attach(dialog)
dialog.mount()
# Check that the default dialog busy state is false
expect(dialog.busy()).toBe false
classes = dialog.domElement().getAttribute('class')
expect(classes.indexOf('ct-dialog--busy')).toBe -1
# Check we can change it
dialog.busy(true)
expect(dialog.busy()).toBe true
classes = dialog.domElement().getAttribute('class')
expect(classes.indexOf('ct-dialog--busy') > 0).toBe true
describe 'ContentTools.DialogUI.position()', () ->
it 'should set/get the dialog\'s caption', () ->
dialog = new ContentTools.DialogUI('foo')
editor.attach(dialog)
dialog.mount()
# Initially the should be dialog's should be 'foo'
expect(dialog.caption()).toEqual 'foo'
expect(dialog._domCaption.textContent).toEqual 'foo'
# Set a new caption and check the change has been applied
dialog.caption('bar')
expect(dialog.caption()).toEqual 'bar'
expect(dialog._domCaption.textContent).toEqual 'bar'
describe 'ContentTools.DialogUI.mount()', () ->
it 'should mount the dialog', () ->
dialog = new ContentTools.DialogUI()
editor.attach(dialog)
dialog.mount()
expect(dialog.isMounted()).toBe true
describe 'ContentTools.DialogUI.unmount()', () ->
it 'should unmount the component', () ->
dialog = new ContentTools.DialogUI()
editor.attach(dialog)
dialog.mount()
dialog.unmount()
expect(dialog.isMounted()).toBe false