From 1ce78448660bdfeaf7e25432230f260f85677bb0 Mon Sep 17 00:00:00 2001 From: BacLuc Date: Sun, 5 May 2024 17:28:08 +0200 Subject: [PATCH] frontend: add tests for slot forwarding That we have tests when we turn the following rules on: "vue/no-deprecated-dollar-scopedslots-api": "off", "vue/no-deprecated-slot-attribute": "off", "vue/no-deprecated-slot-scope-attribute": "off", Issue: #5121 Related to: #5170, #5122 --- .../form/base/__tests__/ECheckbox.spec.js | 17 +++++++- .../form/base/__tests__/ENumberField.spec.js | 21 +++++++-- .../form/base/__tests__/EParseField.spec.js | 17 +++++++- .../form/base/__tests__/ESelect.spec.js | 43 +++++++++++++++++-- .../form/base/__tests__/ESwitch.spec.js | 17 +++++++- .../form/base/__tests__/ETextField.spec.js | 17 +++++++- 6 files changed, 121 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/form/base/__tests__/ECheckbox.spec.js b/frontend/src/components/form/base/__tests__/ECheckbox.spec.js index e0c12b8f05..babda9d4cd 100644 --- a/frontend/src/components/form/base/__tests__/ECheckbox.spec.js +++ b/frontend/src/components/form/base/__tests__/ECheckbox.spec.js @@ -5,6 +5,7 @@ import formBaseComponents from '@/plugins/formBaseComponents' import { mount as mountComponent } from '@vue/test-utils' import ECheckbox from '../ECheckbox.vue' +import { screen } from '@testing-library/vue' Vue.use(Vuetify) Vue.use(formBaseComponents) @@ -22,7 +23,9 @@ describe('An ECheckbox', () => { }, template: `
- + + ${options?.children} +
`, }) @@ -82,4 +85,16 @@ describe('An ECheckbox', () => { await input.trigger('click') expect(wrapper.vm.data).toBe(false) }) + + test('allows to use the append slot', async () => { + mount({ + children: ` + + `, + }) + + expect(await screen.findByText('append')).toBeVisible() + }) }) diff --git a/frontend/src/components/form/base/__tests__/ENumberField.spec.js b/frontend/src/components/form/base/__tests__/ENumberField.spec.js index 38b0a76839..2db14480a8 100644 --- a/frontend/src/components/form/base/__tests__/ENumberField.spec.js +++ b/frontend/src/components/form/base/__tests__/ENumberField.spec.js @@ -5,6 +5,7 @@ import formBaseComponents from '@/plugins/formBaseComponents' import { mount as mountComponent } from '@vue/test-utils' import ENumberField from '../ENumberField.vue' +import { screen } from '@testing-library/vue' Vue.use(Vuetify) Vue.use(formBaseComponents) @@ -21,9 +22,11 @@ describe('An ENumberField', () => { } }, template: ` -
- -
+
+ + ${options?.children} + +
`, }) return mountComponent(app, { vuetify, attachTo: document.body, ...options }) @@ -114,4 +117,16 @@ describe('An ENumberField', () => { expect(wrapper.vm.data).toBe(expected) }) + + test('allows to use the append slot', async () => { + mount({ + children: ` + + `, + }) + + expect(await screen.findByText('append')).toBeVisible() + }) }) diff --git a/frontend/src/components/form/base/__tests__/EParseField.spec.js b/frontend/src/components/form/base/__tests__/EParseField.spec.js index 8457c6d1e4..5e41c85229 100644 --- a/frontend/src/components/form/base/__tests__/EParseField.spec.js +++ b/frontend/src/components/form/base/__tests__/EParseField.spec.js @@ -5,6 +5,7 @@ import formBaseComponents from '@/plugins/formBaseComponents' import EParseField from '@/components/form/base/EParseField.vue' import { mount as mountComponent } from '@vue/test-utils' +import { screen } from '@testing-library/vue' Vue.use(Vuetify) Vue.use(formBaseComponents) @@ -30,7 +31,9 @@ describe('An EParseField', () => { }, template: `
- + + ${options?.children} +
`, }) @@ -90,4 +93,16 @@ describe('An EParseField', () => { expect(wrapper.vm.data).toBe(expected) }) + + test('allows to use the append slot', async () => { + mount({ + children: ` + + `, + }) + + expect(await screen.findByText('append')).toBeVisible() + }) }) diff --git a/frontend/src/components/form/base/__tests__/ESelect.spec.js b/frontend/src/components/form/base/__tests__/ESelect.spec.js index b6113a5844..77bb783ae4 100644 --- a/frontend/src/components/form/base/__tests__/ESelect.spec.js +++ b/frontend/src/components/form/base/__tests__/ESelect.spec.js @@ -5,6 +5,7 @@ import { formBaseComponents } from '@/plugins' import { mount as mountComponent } from '@vue/test-utils' import ESelect from '../ESelect.vue' +import { screen } from '@testing-library/vue' Vue.use(Vuetify) Vue.use(formBaseComponents) @@ -36,10 +37,12 @@ describe('An ESelect', () => { } }, template: ` -
- -
- `, +
+ + ${options?.children} + +
+ `, }) return mountComponent(app, { vuetify, attachTo: document.body, ...options }) } @@ -101,4 +104,36 @@ describe('An ESelect', () => { wrapper.findAll('[role="option"]').at(0).element.getAttribute('aria-selected') ).not.toBe('true') }) + + test('allows to use the append slot', async () => { + mount({ + children: ` + + `, + }) + + expect(await screen.findByText('append')).toBeVisible() + }) + + test('allows to use the append slot with scope', async () => { + const textText = 'myTestText' + const wrapper = mount({ + children: ` + + `, + }) + + await wrapper.find('.v-input__slot').trigger('click') + + expect(await screen.findAllByText(textText)).toHaveLength(3) + }) }) diff --git a/frontend/src/components/form/base/__tests__/ESwitch.spec.js b/frontend/src/components/form/base/__tests__/ESwitch.spec.js index c8538a8cfc..02fc0c7ac4 100644 --- a/frontend/src/components/form/base/__tests__/ESwitch.spec.js +++ b/frontend/src/components/form/base/__tests__/ESwitch.spec.js @@ -6,6 +6,7 @@ import formBaseComponents from '@/plugins/formBaseComponents' import { mount as mountComponent } from '@vue/test-utils' import ESwitch from '@/components/form/base/ESwitch.vue' import { touch } from '@/test/util' +import { screen } from '@testing-library/vue' Vue.use(Vuetify) Vue.use(formBaseComponents) @@ -23,7 +24,9 @@ describe('An ESwitch', () => { }, template: `
- + + ${options?.children} +
`, }) @@ -107,4 +110,16 @@ describe('An ESwitch', () => { input.trigger('keydown.left') expect(wrapper.vm.data).toBe(false) }) + + test('allows to use the append slot', async () => { + mount({ + children: ` + + `, + }) + + expect(await screen.findByText('append')).toBeVisible() + }) }) diff --git a/frontend/src/components/form/base/__tests__/ETextField.spec.js b/frontend/src/components/form/base/__tests__/ETextField.spec.js index 98b587dec1..0e3c1e17bd 100644 --- a/frontend/src/components/form/base/__tests__/ETextField.spec.js +++ b/frontend/src/components/form/base/__tests__/ETextField.spec.js @@ -5,6 +5,7 @@ import formBaseComponents from '@/plugins/formBaseComponents' import { mount as mountComponent } from '@vue/test-utils' import ETextField from '../ETextField.vue' +import { screen } from '@testing-library/vue' Vue.use(Vuetify) Vue.use(formBaseComponents) @@ -22,7 +23,9 @@ describe('An ETextField', () => { }, template: `
- + + ${options?.children} +
`, }) @@ -68,4 +71,16 @@ describe('An ETextField', () => { expect(wrapper.vm.data).toBe(text) }) + + test('allows to use the append slot', async () => { + mount({ + children: ` + + `, + }) + + expect(await screen.findByText('append')).toBeVisible() + }) })