This repository has been archived by the owner on Jun 10, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathDrawer.spec.js
185 lines (168 loc) · 6.06 KB
/
Drawer.spec.js
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
import Drawer from 'src/Drawer/Drawer'
import DrawerNav from 'src/Drawer/DrawerNav'
import DrawerNavItem from 'src/Drawer/DrawerNavItem'
import DrawerHeader from 'src/Drawer/DrawerHeader'
import ListDivider from 'src/List/ListDivider'
import {
createVM,
dataPropagationTest,
foundationDetroyTest,
nextTick,
} from '../helpers'
describe('Drawer', function () {
it('keeps original tag data', dataPropagationTest(Drawer))
it('is temporary by default', function () {
const vm = createVM(this, h => (
<Drawer ref='drawer'>
</Drawer>
))
vm.$refs.drawer.$el.should.have.class('mdc-temporary-drawer')
})
it('calls foundation destroy', foundationDetroyTest(Drawer))
describe('temporary', function () {
describe('no content', function () {
beforeEach(function () {
this.vm = createVM(this, function (h) {
return (
<div>
<Drawer ref='drawer'>
</Drawer>
<button onClick={() => this.$refs.drawer.open()}>Open</button>
</div>
)
})
})
afterEach(function () {
this.vm.$refs.drawer.close()
})
it('makes the body unscrollable while open', function () {
const scrollBlock = 'mdc-dialog-scroll-lock'
document.body.should.not.have.class(scrollBlock)
this.vm.$refs.drawer.open()
document.body.should.have.class(scrollBlock)
this.vm.$refs.drawer.close()
document.body.should.not.have.class(scrollBlock)
})
it('can be closed', function (done) {
this.vm.$refs.drawer.$el.should.not.have.class('mdc-temporary-drawer--open')
this.vm.$refs.drawer.close()
nextTick().then(() => {
this.vm.$refs.drawer.$el.should.not.have.class('mdc-temporary-drawer--open')
}).then(done)
})
it('closes when clicking outside, function ()', function () {
this.vm.$refs.drawer.open()
this.vm.$refs.drawer.$el.should.have.class('mdc-temporary-drawer--open')
this.vm.$('.mdc-temporary-drawer').click()
this.vm.$refs.drawer.$el.should.not.have.class('mdc-temporary-drawer--open')
})
it('can be opened', function (done) {
this.vm.$refs.drawer.$el.should.not.have.class('mdc-temporary-drawer--open')
this.vm.$refs.drawer.open()
nextTick().then(() => {
this.vm.$refs.drawer.$el.should.have.class('mdc-temporary-drawer--open')
// should do nothing
this.vm.$refs.drawer.open()
}).then(() => {
this.vm.$refs.drawer.$el.should.have.class('mdc-temporary-drawer--open')
this.vm.$refs.drawer.close()
}).then(done)
})
})
describe('with a nav', function () {
beforeEach(function () {
this.vm = createVM(this, function (h) {
const select = e => {
this.selected = e.target.textContent
}
const menu1 = [
{ icon: 'inbox', text: 'Inbox' },
{ icon: 'star', text: 'Star' },
{ icon: 'send', text: 'Sent Mail' },
{ icon: 'drafts', text: 'Drafts' },
]
const menu2 = [
{ icon: 'email', text: 'All Mail' },
{ icon: 'delete', text: 'Trash' },
{ icon: 'report', text: 'Spam' },
]
const isSelected = id => id === this.selected
return (
<div>
<Drawer ref='drawer'>
<DrawerHeader
slot='header'
>
Header Here
</DrawerHeader>
<DrawerNav>
{menu1.map(({ icon, text }) => (
<DrawerNavItem href='#'
nativeOnClick={select}
selected={isSelected(icon + text)}
>
<i class='material-icons mdc-list-item__start-detail'
aria-hidden='true'>{icon}</i>{text}
</DrawerNavItem>
))}
</DrawerNav>
<ListDivider/>
<DrawerNav>
{menu2.map(({ icon, text }) => (
<DrawerNavItem href='#'
nativeOnClick={select}
selected={isSelected(icon + text)}
>
<i class='material-icons mdc-list-item__start-detail'
aria-hidden='true'>{icon}</i>{text}
</DrawerNavItem>
))}
</DrawerNav>
</Drawer>
<button onClick={() => this.$refs.drawer.open()}>Open</button>
</div>
)
}, {
data: {
selected: 'inboxInbox',
},
})
})
it('holds a header and nav', function () {
this.vm.$('.mdc-temporary-drawer__header').should.exist
this.vm.$('.mdc-temporary-drawer__content').should.match('.mdc-list-group')
this.vm.$('.mdc-list-group .mdc-list').should.contain('.mdc-list-item')
this.vm.$('.mdc-list-item').should.have.text('inboxInbox')
this.vm.$('.mdc-list-item').should.have.class('mdc-temporary-drawer--selected')
})
})
})
describe('DrawerNav', function () {
it('is a nav by default', function () {
const vm = createVM(this, h => (
<DrawerNav ref='list'></DrawerNav>
))
vm.$('.mdc-list').should.exist.and.match('nav')
})
it('can render a custom tag', function () {
const vm = createVM(this, h => (
<DrawerNav ref='list' tag='div'></DrawerNav>
))
vm.$('.mdc-list').should.exist.and.match('div')
})
})
describe('DrawerNavItem', function () {
it('is an a by default', function () {
const vm = createVM(this, h => (
<DrawerNavItem ref='list'>Hello</DrawerNavItem>
))
vm.$('.mdc-list-item').should.exist.and.match('a')
})
it('can render a custom tag', function () {
const vm = createVM(this, h => (
<DrawerNavItem ref='list' tag='div'>Hello</DrawerNavItem>
))
vm.$('.mdc-list-item').should.exist.and.match('div')
})
})
})