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 pathripple.spec.js
169 lines (162 loc) · 4.4 KB
/
ripple.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
import ripple from 'src/ripple.js'
import { createVM } from '../helpers/utils.js'
import { nextTick } from '../helpers/wait-for-update.js'
describe('Ripple', function () {
it('upgrades a div', function (done) {
const vm = createVM(this, function (h) {
return (
<div class='my-ripple' v-ripple>Simple</div>
)
}, {
directives: { ripple },
})
nextTick().then(() => {
const ripple = vm.$('.my-ripple')
ripple.should.have.class('mdc-ripple-surface')
}).then(() => {
const ripple = vm.$('.my-ripple')
ripple.should.have.class('mdc-ripple-upgraded')
}).then(done)
})
it('can use custom class', function (done) {
const vm = createVM(
this,
`<div class='my-ripple' v-ripple.custom>Custom</div>`,
{ directives: { ripple }}
)
nextTick().then(() => {
const ripple = vm.$('.my-ripple')
ripple.should.not.have.class('mdc-ripple-surface')
}).then(() => {
const ripple = vm.$('.my-ripple')
ripple.should.have.class('mdc-ripple-upgraded')
}).then(done)
})
it('unbounds events and clases', function (done) {
const vm = createVM(this, function (h) {
const opts = {
directives: [],
}
if (this.show) {
opts.directives.push({
name: 'ripple',
})
}
return (
<div class='my-ripple' {...opts}>Unbind</div>
)
}, {
data: {
show: true,
},
directives: { ripple },
})
vm.show = false
nextTick().then(() => {
const ripple = vm.$('.my-ripple')
ripple.should.not.have.class('mdc-ripple-upgraded')
ripple.should.not.have.class('mdc-ripple-surface')
}).then(done)
})
it('works with regular elements', function (done) {
const vm = createVM(
this,
`<div class="my-ripple" v-ripple :key="text">A div</div>`,
{
data: {
text: 'foo',
},
directives: { ripple },
}
)
const oldEl = vm.$('.my-ripple')
vm.text = 'bar'
nextTick().then(() => {
// we need to wait an extra tick
}).then(() => {
const ripple = vm.$('.my-ripple')
oldEl.should.not.equal(ripple)
ripple.should.have.class('mdc-ripple-upgraded')
ripple.should.have.class('mdc-ripple-surface')
}).then(done)
})
it('works with regular components', function (done) {
const vm = createVM(
this,
`<foo class="my-ripple" v-ripple :key="text">A foo</foo>`,
{
data: {
text: 'foo',
},
directives: { ripple },
components: {
Foo: {
template: '<div><slot/></div>',
},
},
}
)
const oldEl = vm.$('.my-ripple')
vm.text = 'bar'
nextTick().then(() => {
// we need to wait an extra tick
}).then(() => {
const ripple = vm.$('.my-ripple')
oldEl.should.not.equal(ripple)
ripple.should.have.class('mdc-ripple-upgraded')
ripple.should.have.class('mdc-ripple-surface')
}).then(done)
})
it('works with functional components', function (done) {
const vm = createVM(
this,
`<foo class="my-ripple" v-ripple>{{text}}</foo>`,
{
data: {
text: 'foo',
},
directives: { ripple },
components: {
Foo: {
functional: true,
render: (h, { data, children }) => h('div', data, children),
},
},
}
)
const oldEl = vm.$('.my-ripple')
vm.text = 'bar'
nextTick().then(() => {
// we need to wait an extra tick
}).then(() => {
const ripple = vm.$('.my-ripple')
// The same object is reused
oldEl.should.equal(ripple)
ripple.should.have.class('mdc-ripple-upgraded')
ripple.should.have.class('mdc-ripple-surface')
}).then(done)
})
it('works when the node is reused', function (done) {
const vm = createVM(
this,
`<div class="my-ripple" v-ripple>{{text}}</div>`,
{
data: {
text: 'foo',
},
directives: { ripple },
}
)
const oldEl = vm.$('.my-ripple')
vm.text = 'bar'
nextTick().then(() => {
// we need to wait an extra tick
}).then(() => {
const ripple = vm.$('.my-ripple')
// The same object is reused
oldEl.should.equal(ripple)
ripple.should.have.class('mdc-ripple-upgraded')
ripple.should.have.class('mdc-ripple-surface')
}).then(done)
})
})