-
Notifications
You must be signed in to change notification settings - Fork 668
/
Copy pathisVisible.spec.js
152 lines (124 loc) · 5.55 KB
/
isVisible.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
import { compileToFunctions } from 'vue-template-compiler'
import ComponentWithVShow from '~resources/components/component-with-v-show.vue'
import ComponentWithVIf from '~resources/components/component-with-v-if.vue'
import { describeWithShallowAndMount } from '~resources/utils'
import Vue from 'vue'
describeWithShallowAndMount('isVisible', mountingMethod => {
it('returns true if element has no inline style', () => {
const compiled = compileToFunctions(
'<div><div><span class="visible"></span></div></div>'
)
const wrapper = mountingMethod(compiled)
const element = wrapper.find('.visible')
expect(element.isVisible()).to.equal(true)
})
it('returns false if element has inline style display: none', () => {
const compiled = compileToFunctions(
'<div><div><span style="display: none;" class="visible"></span></div></div>'
)
const wrapper = mountingMethod(compiled)
const element = wrapper.find('.visible')
expect(element.isVisible()).to.equal(false)
})
it('returns false if element has inline style visibility: hidden', () => {
const compiled = compileToFunctions(
'<div><div><span style="visibility: hidden;" class="visible"></span></div></div>'
)
const wrapper = mountingMethod(compiled)
const element = wrapper.find('.visible')
expect(element.isVisible()).to.equal(false)
})
it('returns false if element has hidden attribute', () => {
const compiled = compileToFunctions(
'<div><div><span class="visible" hidden></span></div></div>'
)
const wrapper = mountingMethod(compiled)
const element = wrapper.find('.visible')
expect(element.isVisible()).to.equal(false)
})
it('returns true if element has v-show true', async () => {
const wrapper = mountingMethod(ComponentWithVShow)
wrapper.vm.$set(wrapper.vm, 'ready', true)
await Vue.nextTick()
const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.isVisible()).to.equal(false)
const readyElement = wrapper.find('.parent.ready')
expect(readyElement.isVisible()).to.equal(true)
})
it('returns false if element has v-show true', async () => {
const wrapper = mountingMethod(ComponentWithVShow)
wrapper.vm.$set(wrapper.vm, 'ready', true)
await Vue.nextTick()
const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.isVisible()).to.equal(false)
const readyElement = wrapper.find('.parent.ready')
expect(readyElement.isVisible()).to.equal(true)
})
it('returns true if parent element has v-show true', async () => {
const wrapper = mountingMethod(ComponentWithVShow)
wrapper.vm.$set(wrapper.vm, 'ready', true)
await Vue.nextTick()
const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.isVisible()).to.equal(false)
const readyChildElement = wrapper.find('.child.ready')
expect(readyChildElement.isVisible()).to.equal(true)
})
it('returns false if parent element has v-show false', async () => {
const wrapper = mountingMethod(ComponentWithVShow)
wrapper.vm.$set(wrapper.vm, 'ready', true)
await Vue.nextTick()
const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.isVisible()).to.equal(false)
const readyChildElement = wrapper.find('.child.ready')
expect(readyChildElement.isVisible()).to.equal(true)
})
it('returns false if root element has v-show false and parent has v-show true', async () => {
const wrapper = mountingMethod(ComponentWithVShow)
wrapper.vm.$set(wrapper.vm, 'ready', true)
wrapper.vm.$set(wrapper.vm, 'rootReady', false)
await Vue.nextTick()
const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.isVisible()).to.equal(false)
const readyChildElement = wrapper.find('.child.ready')
expect(readyChildElement.isVisible()).to.equal(false)
})
it('returns false if root element has v-show true and parent has v-show false', async () => {
const wrapper = mountingMethod(ComponentWithVShow)
wrapper.vm.$set(wrapper.vm, 'ready', false)
wrapper.vm.$set(wrapper.vm, 'rootReady', true)
await Vue.nextTick()
const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.isVisible()).to.equal(true)
const readyChildElement = wrapper.find('.child.ready')
expect(readyChildElement.isVisible()).to.equal(false)
})
it('returns true if all elements are visible', async () => {
const wrapper = mountingMethod(ComponentWithVShow)
wrapper.vm.$set(wrapper.vm, 'ready', true)
wrapper.vm.$set(wrapper.vm, 'rootReady', true)
await Vue.nextTick()
const readyChildElement = wrapper.find('.ready')
expect(readyChildElement.isVisible()).to.equal(true)
})
it('returns false if one element is not visible', async () => {
const wrapper = mountingMethod(ComponentWithVShow)
wrapper.vm.$set(wrapper.vm, 'ready', true)
wrapper.vm.$set(wrapper.vm, 'rootReady', true)
await Vue.nextTick()
const readyChildElement = wrapper.find('.ready, .not-ready')
expect(readyChildElement.isVisible()).to.equal(false)
})
it('fails if one element is absent', async () => {
const wrapper = mountingMethod(ComponentWithVIf)
wrapper.vm.$set(wrapper.vm, 'ready', false)
await Vue.nextTick()
const fn = () => wrapper.find('.child.ready').isVisible()
expect(fn).to.throw()
})
it('returns true if one element is present', async () => {
const wrapper = mountingMethod(ComponentWithVIf)
wrapper.vm.$set(wrapper.vm, 'ready', true)
await Vue.nextTick()
expect(wrapper.find('.child.ready').isVisible()).to.equal(true)
})
})