Skip to content

Commit c5d6009

Browse files
authored
Merge pull request ecamp#5171 from BacLuc/frontend-add-tests-for-slot-forwarding
frontend add tests for slot forwarding
2 parents fe4a8da + 1ce7844 commit c5d6009

File tree

6 files changed

+131
-9
lines changed

6 files changed

+131
-9
lines changed

frontend/src/components/form/base/__tests__/ECheckbox.spec.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import formBaseComponents from '@/plugins/formBaseComponents'
55

66
import { mount as mountComponent } from '@vue/test-utils'
77
import ECheckbox from '../ECheckbox.vue'
8+
import { screen } from '@testing-library/vue'
89

910
Vue.use(Vuetify)
1011
Vue.use(formBaseComponents)
@@ -22,7 +23,9 @@ describe('An ECheckbox', () => {
2223
},
2324
template: `
2425
<div data-app>
25-
<e-checkbox label="test" v-model="data"/>
26+
<e-checkbox label="test" v-model="data">
27+
${options?.children}
28+
</e-checkbox>
2629
</div>
2730
`,
2831
})
@@ -82,4 +85,16 @@ describe('An ECheckbox', () => {
8285
await input.trigger('click')
8386
expect(wrapper.vm.data).toBe(false)
8487
})
88+
89+
test('allows to use the append slot', async () => {
90+
mount({
91+
children: `
92+
<template #append>
93+
<span>append</span>
94+
</template>
95+
`,
96+
})
97+
98+
expect(await screen.findByText('append')).toBeVisible()
99+
})
85100
})

frontend/src/components/form/base/__tests__/ENumberField.spec.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import formBaseComponents from '@/plugins/formBaseComponents'
55

66
import { mount as mountComponent } from '@vue/test-utils'
77
import ENumberField from '../ENumberField.vue'
8+
import { screen } from '@testing-library/vue'
89

910
Vue.use(Vuetify)
1011
Vue.use(formBaseComponents)
@@ -20,7 +21,13 @@ describe('An ENumberField', () => {
2021
data: null,
2122
}
2223
},
23-
template: `<div data-app><e-number-field label="test" v-model="data"/></div>`,
24+
template: `
25+
<div data-app>
26+
<e-number-field label="test" v-model="data">
27+
${options?.children}
28+
</e-number-field>
29+
</div>
30+
`,
2431
})
2532
return mountComponent(app, { vuetify, attachTo: document.body, ...options })
2633
}
@@ -110,4 +117,16 @@ describe('An ENumberField', () => {
110117

111118
expect(wrapper.vm.data).toBe(expected)
112119
})
120+
121+
test('allows to use the append slot', async () => {
122+
mount({
123+
children: `
124+
<template #append>
125+
<span>append</span>
126+
</template>
127+
`,
128+
})
129+
130+
expect(await screen.findByText('append')).toBeVisible()
131+
})
113132
})

frontend/src/components/form/base/__tests__/EParseField.spec.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import formBaseComponents from '@/plugins/formBaseComponents'
55

66
import EParseField from '@/components/form/base/EParseField.vue'
77
import { mount as mountComponent } from '@vue/test-utils'
8+
import { screen } from '@testing-library/vue'
89

910
Vue.use(Vuetify)
1011
Vue.use(formBaseComponents)
@@ -28,7 +29,13 @@ describe('An EParseField', () => {
2829
return value === null ? '' : `${value}`
2930
},
3031
},
31-
template: `<div data-app><e-parse-field label="test" :parse="parse" :format="format" v-model="data"/></div>`,
32+
template: `
33+
<div data-app>
34+
<e-parse-field label="test" :parse="parse" :format="format" v-model="data" :value="data">
35+
${options?.children}
36+
</e-parse-field>
37+
</div>
38+
`,
3239
})
3340
return mountComponent(app, { vuetify, attachTo: document.body, ...options })
3441
}
@@ -86,4 +93,16 @@ describe('An EParseField', () => {
8693

8794
expect(wrapper.vm.data).toBe(expected)
8895
})
96+
97+
test('allows to use the append slot', async () => {
98+
mount({
99+
children: `
100+
<template #append>
101+
<span>append</span>
102+
</template>
103+
`,
104+
})
105+
106+
expect(await screen.findByText('append')).toBeVisible()
107+
})
89108
})

frontend/src/components/form/base/__tests__/ESelect.spec.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { formBaseComponents } from '@/plugins'
55

66
import { mount as mountComponent } from '@vue/test-utils'
77
import ESelect from '../ESelect.vue'
8+
import { screen } from '@testing-library/vue'
89

910
Vue.use(Vuetify)
1011
Vue.use(formBaseComponents)
@@ -36,10 +37,12 @@ describe('An ESelect', () => {
3637
}
3738
},
3839
template: `
39-
<div data-app>
40-
<e-select label='test' :items="selectValues" v-model="data"/>
41-
</div>
42-
`,
40+
<div data-app>
41+
<e-select label="test" :items="selectValues" v-model="data">
42+
${options?.children}
43+
</e-select>
44+
</div>
45+
`,
4346
})
4447
return mountComponent(app, { vuetify, attachTo: document.body, ...options })
4548
}
@@ -101,4 +104,36 @@ describe('An ESelect', () => {
101104
wrapper.findAll('[role="option"]').at(0).element.getAttribute('aria-selected')
102105
).not.toBe('true')
103106
})
107+
108+
test('allows to use the append slot', async () => {
109+
mount({
110+
children: `
111+
<template #append>
112+
<span>append</span>
113+
</template>
114+
`,
115+
})
116+
117+
expect(await screen.findByText('append')).toBeVisible()
118+
})
119+
120+
test('allows to use the append slot with scope', async () => {
121+
const textText = 'myTestText'
122+
const wrapper = mount({
123+
children: `
124+
<template #item="{ item, on, attrs }">
125+
<v-list-item-title :key="item.text" v-bind="attrs" v-on="on">
126+
{{ item }}
127+
</v-list-item-title>
128+
<v-list-item-subtitle>
129+
${textText}
130+
</v-list-item-subtitle>
131+
</template>
132+
`,
133+
})
134+
135+
await wrapper.find('.v-input__slot').trigger('click')
136+
137+
expect(await screen.findAllByText(textText)).toHaveLength(3)
138+
})
104139
})

frontend/src/components/form/base/__tests__/ESwitch.spec.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import formBaseComponents from '@/plugins/formBaseComponents'
66
import { mount as mountComponent } from '@vue/test-utils'
77
import ESwitch from '@/components/form/base/ESwitch.vue'
88
import { touch } from '@/test/util'
9+
import { screen } from '@testing-library/vue'
910

1011
Vue.use(Vuetify)
1112
Vue.use(formBaseComponents)
@@ -23,7 +24,9 @@ describe('An ESwitch', () => {
2324
},
2425
template: `
2526
<div data-app>
26-
<e-switch label="test" v-model="data"/>
27+
<e-switch label="test" v-model="data">
28+
${options?.children}
29+
</e-switch>
2730
</div>
2831
`,
2932
})
@@ -107,4 +110,16 @@ describe('An ESwitch', () => {
107110
input.trigger('keydown.left')
108111
expect(wrapper.vm.data).toBe(false)
109112
})
113+
114+
test('allows to use the append slot', async () => {
115+
mount({
116+
children: `
117+
<template #append>
118+
<span>append</span>
119+
</template>
120+
`,
121+
})
122+
123+
expect(await screen.findByText('append')).toBeVisible()
124+
})
110125
})

frontend/src/components/form/base/__tests__/ETextField.spec.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import formBaseComponents from '@/plugins/formBaseComponents'
55

66
import { mount as mountComponent } from '@vue/test-utils'
77
import ETextField from '../ETextField.vue'
8+
import { screen } from '@testing-library/vue'
89

910
Vue.use(Vuetify)
1011
Vue.use(formBaseComponents)
@@ -20,7 +21,13 @@ describe('An ETextField', () => {
2021
data: null,
2122
}
2223
},
23-
template: `<div data-app><e-text-field label="test" v-model="data"/></div>`,
24+
template: `
25+
<div data-app>
26+
<e-text-field label="test" v-model="data">
27+
${options?.children}
28+
</e-text-field>
29+
</div>
30+
`,
2431
})
2532
return mountComponent(app, { vuetify, attachTo: document.body, ...options })
2633
}
@@ -64,4 +71,16 @@ describe('An ETextField', () => {
6471

6572
expect(wrapper.vm.data).toBe(text)
6673
})
74+
75+
test('allows to use the append slot', async () => {
76+
mount({
77+
children: `
78+
<template #append>
79+
<span>append</span>
80+
</template>
81+
`,
82+
})
83+
84+
expect(await screen.findByText('append')).toBeVisible()
85+
})
6786
})

0 commit comments

Comments
 (0)