@windward/core 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { mount, createLocalVue } from '@vue/test-utils'
|
|
2
|
+
import Vue from 'vue'
|
|
3
|
+
import Vuetify from 'vuetify'
|
|
4
|
+
import VueI18n from 'vue-i18n'
|
|
5
|
+
import GlossaryToolTip from '../../../../components/utils/glossary/GlossaryToolTip.vue'
|
|
6
|
+
|
|
7
|
+
Vue.use(Vuetify)
|
|
8
|
+
Vue.use(VueI18n)
|
|
9
|
+
|
|
10
|
+
describe('GlossaryToolTip', () => {
|
|
11
|
+
const localVue = createLocalVue()
|
|
12
|
+
let vuetify
|
|
13
|
+
let i18n
|
|
14
|
+
let wrapper
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
vuetify = new Vuetify()
|
|
18
|
+
i18n = new VueI18n({
|
|
19
|
+
locale: 'en',
|
|
20
|
+
messages: {
|
|
21
|
+
en: {
|
|
22
|
+
'windward.core.components.utils.tiny_mce_wrapper.definition': 'Definition',
|
|
23
|
+
'windward.core.components.utils.tiny_mce_wrapper.alternate_forms': 'Alternate Forms',
|
|
24
|
+
'windward.core.components.utils.tiny_mce_wrapper.related_terms': 'Related Terms'
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// Create data-app element for Vuetify
|
|
30
|
+
const app = document.createElement('div')
|
|
31
|
+
app.setAttribute('data-app', 'true')
|
|
32
|
+
document.body.appendChild(app)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
wrapper.destroy()
|
|
37
|
+
// Clean up data-app element
|
|
38
|
+
const app = document.querySelector('[data-app=true]')
|
|
39
|
+
if (app) {
|
|
40
|
+
document.body.removeChild(app)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const mountComponent = (options = {}) => {
|
|
45
|
+
return mount(GlossaryToolTip, {
|
|
46
|
+
localVue,
|
|
47
|
+
vuetify,
|
|
48
|
+
i18n,
|
|
49
|
+
attachTo: document.body,
|
|
50
|
+
slots: {
|
|
51
|
+
term: '<span>Test Term</span>',
|
|
52
|
+
definition: '<span>Test Definition</span>'
|
|
53
|
+
},
|
|
54
|
+
...options
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const waitForMenuTransition = async () => {
|
|
59
|
+
await new Promise(resolve => setTimeout(resolve, 300))
|
|
60
|
+
await Vue.nextTick()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
it('renders the term in the activator slot', () => {
|
|
64
|
+
wrapper = mountComponent()
|
|
65
|
+
expect(wrapper.find('.glossary-word').text()).toContain('Test Term')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('starts with menu closed', () => {
|
|
69
|
+
wrapper = mountComponent()
|
|
70
|
+
expect(wrapper.vm.show).toBe(false)
|
|
71
|
+
expect(wrapper.find('.v-menu__content').exists()).toBe(false)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('opens menu on click', async () => {
|
|
75
|
+
wrapper = mountComponent()
|
|
76
|
+
const activator = wrapper.find('.glossary-word span')
|
|
77
|
+
|
|
78
|
+
await activator.trigger('click')
|
|
79
|
+
await waitForMenuTransition()
|
|
80
|
+
|
|
81
|
+
expect(wrapper.vm.show).toBe(true)
|
|
82
|
+
const menu = document.querySelector('.v-menu__content')
|
|
83
|
+
expect(menu).toBeTruthy()
|
|
84
|
+
expect(getComputedStyle(menu).display).not.toBe('none')
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('closes menu when clicking outside', async () => {
|
|
88
|
+
wrapper = mountComponent()
|
|
89
|
+
const activator = wrapper.find('.glossary-word span')
|
|
90
|
+
|
|
91
|
+
// Open menu
|
|
92
|
+
await activator.trigger('click')
|
|
93
|
+
await waitForMenuTransition()
|
|
94
|
+
expect(wrapper.vm.show).toBe(true)
|
|
95
|
+
|
|
96
|
+
// Click outside
|
|
97
|
+
document.body.click()
|
|
98
|
+
await waitForMenuTransition()
|
|
99
|
+
|
|
100
|
+
expect(wrapper.vm.show).toBe(false)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('renders definition content when menu is open', async () => {
|
|
104
|
+
wrapper = mountComponent()
|
|
105
|
+
const activator = wrapper.find('.glossary-word span')
|
|
106
|
+
|
|
107
|
+
await activator.trigger('click')
|
|
108
|
+
await waitForMenuTransition()
|
|
109
|
+
|
|
110
|
+
expect(document.body.textContent).toContain('Test Definition')
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('applies active class when menu is open', async () => {
|
|
114
|
+
wrapper = mountComponent()
|
|
115
|
+
const activator = wrapper.find('.glossary-word span')
|
|
116
|
+
|
|
117
|
+
await activator.trigger('click')
|
|
118
|
+
await waitForMenuTransition()
|
|
119
|
+
|
|
120
|
+
expect(wrapper.find('.glossary-word').classes()).toContain('active')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('removes active class when menu is closed', async () => {
|
|
124
|
+
wrapper = mountComponent()
|
|
125
|
+
const activator = wrapper.find('.glossary-word span')
|
|
126
|
+
|
|
127
|
+
// Open then close
|
|
128
|
+
await activator.trigger('click')
|
|
129
|
+
await waitForMenuTransition()
|
|
130
|
+
|
|
131
|
+
document.body.click()
|
|
132
|
+
await waitForMenuTransition()
|
|
133
|
+
|
|
134
|
+
expect(wrapper.find('.glossary-word').classes()).not.toContain('active')
|
|
135
|
+
})
|
|
136
|
+
})
|