forked from GetmeUK/ContentTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodal.coffee
More file actions
113 lines (78 loc) · 3.47 KB
/
Copy pathmodal.coffee
File metadata and controls
113 lines (78 loc) · 3.47 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
# ModalUI
describe 'ContentTools.ModalUI', () ->
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.ModalUI()', () ->
it 'should return an instance of a ModalUI', () ->
modal = new ContentTools.ModalUI(true, false)
expect(modal instanceof ContentTools.ModalUI).toBe true
describe 'ContentTools.ModalUI.mount()', () ->
it 'should mount the component', () ->
modal = new ContentTools.ModalUI(true, true)
editor.attach(modal)
modal.show()
expect(modal.isMounted()).toBe true
it 'should apply transparent flag', () ->
# Check that the transparency and allowScrolling flags are set
modal = new ContentTools.ModalUI(true, true)
editor.attach(modal)
modal.show()
# Check transparency flag is set
classes = modal.domElement().getAttribute('class').split(' ')
expect(classes.indexOf('ct-modal--transparent') > -1).toBe true
it 'should apply no-scrolling flag', () ->
# Check that the transparency and allowScrolling flags are set
modal = new ContentTools.ModalUI(true, false)
editor.attach(modal)
modal.show()
# Check no scrolling flag is not set
classes = (document.body.getAttribute('class') or '').split(' ')
expect(classes.indexOf('ct--no-scroll') > -1).toBe true
describe 'ContentTools.ModalUI.unmount()', () ->
it 'should unmount the component', () ->
modal = new ContentTools.ModalUI(true, true)
editor.attach(modal)
modal.show()
modal.unmount()
expect(modal.isMounted()).toBe false
it 'should remove no-scrolling flag', () ->
# Check that the transparency and allowScrolling flags are set
modal = new ContentTools.ModalUI(true, false)
editor.attach(modal)
modal.show()
modal.unmount()
# Check no scrolling flag is not set
classes = (document.body.getAttribute('class') or '').split(' ')
expect(classes.indexOf('ct--no-scroll') > -1).toBe false
# Events
describe 'ContentTools.ModalUI > Events', () ->
it 'should trigger a `click` event if clicked', () ->
modal = new ContentTools.ModalUI(true, true)
editor.attach(modal)
modal.show()
# Create function we can spy on to ensure the event is triggered
foo = {
handleFoo: () ->
return
}
spyOn(foo, 'handleFoo')
# Bind the spied on function to the event
modal.addEventListener('click', foo.handleFoo)
# Create a fake click event against the modal's DOM element
clickEvent = document.createEvent('CustomEvent')
clickEvent.initCustomEvent('click', false, false, null)
modal.domElement().dispatchEvent(clickEvent)
expect(foo.handleFoo).toHaveBeenCalled()