Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend add tests for slot forwarding #5171

Merged
merged 2 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion frontend/src/components/form/base/__tests__/ECheckbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -22,7 +23,9 @@ describe('An ECheckbox', () => {
},
template: `
<div data-app>
<e-checkbox label="test" v-model="data"/>
<e-checkbox label="test" v-model="data">
${options?.children}
</e-checkbox>
</div>
`,
})
Expand Down Expand Up @@ -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: `
<template #append>
<span>append</span>
</template>
`,
})

expect(await screen.findByText('append')).toBeVisible()
})
})
21 changes: 20 additions & 1 deletion frontend/src/components/form/base/__tests__/ENumberField.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -20,7 +21,13 @@ describe('An ENumberField', () => {
data: null,
}
},
template: `<div data-app><e-number-field label="test" v-model="data"/></div>`,
template: `
<div data-app>
<e-number-field label="test" v-model="data">
${options?.children}
</e-number-field>
</div>
`,
})
return mountComponent(app, { vuetify, attachTo: document.body, ...options })
}
Expand Down Expand Up @@ -110,4 +117,16 @@ describe('An ENumberField', () => {

expect(wrapper.vm.data).toBe(expected)
})

test('allows to use the append slot', async () => {
mount({
children: `
<template #append>
<span>append</span>
</template>
`,
})

expect(await screen.findByText('append')).toBeVisible()
})
})
21 changes: 20 additions & 1 deletion frontend/src/components/form/base/__tests__/EParseField.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,7 +29,13 @@ describe('An EParseField', () => {
return value === null ? '' : `${value}`
},
},
template: `<div data-app><e-parse-field label="test" :parse="parse" :format="format" v-model="data"/></div>`,
template: `
<div data-app>
<e-parse-field label="test" :parse="parse" :format="format" v-model="data" :value="data">
${options?.children}
</e-parse-field>
</div>
`,
})
return mountComponent(app, { vuetify, attachTo: document.body, ...options })
}
Expand Down Expand Up @@ -86,4 +93,16 @@ describe('An EParseField', () => {

expect(wrapper.vm.data).toBe(expected)
})

test('allows to use the append slot', async () => {
mount({
children: `
<template #append>
<span>append</span>
</template>
`,
})

expect(await screen.findByText('append')).toBeVisible()
})
})
43 changes: 39 additions & 4 deletions frontend/src/components/form/base/__tests__/ESelect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -36,10 +37,12 @@ describe('An ESelect', () => {
}
},
template: `
<div data-app>
<e-select label='test' :items="selectValues" v-model="data"/>
</div>
`,
<div data-app>
<e-select label="test" :items="selectValues" v-model="data">
${options?.children}
</e-select>
</div>
`,
})
return mountComponent(app, { vuetify, attachTo: document.body, ...options })
}
Expand Down Expand Up @@ -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: `
<template #append>
<span>append</span>
</template>
`,
})

expect(await screen.findByText('append')).toBeVisible()
})

test('allows to use the append slot with scope', async () => {
const textText = 'myTestText'
const wrapper = mount({
children: `
<template #item="{ item, on, attrs }">
<v-list-item-title :key="item.text" v-bind="attrs" v-on="on">
{{ item }}
</v-list-item-title>
<v-list-item-subtitle>
${textText}
</v-list-item-subtitle>
</template>
`,
})

await wrapper.find('.v-input__slot').trigger('click')

expect(await screen.findAllByText(textText)).toHaveLength(3)
})
})
17 changes: 16 additions & 1 deletion frontend/src/components/form/base/__tests__/ESwitch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -23,7 +24,9 @@ describe('An ESwitch', () => {
},
template: `
<div data-app>
<e-switch label="test" v-model="data"/>
<e-switch label="test" v-model="data">
${options?.children}
</e-switch>
</div>
`,
})
Expand Down Expand Up @@ -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: `
<template #append>
<span>append</span>
</template>
`,
})

expect(await screen.findByText('append')).toBeVisible()
})
})
21 changes: 20 additions & 1 deletion frontend/src/components/form/base/__tests__/ETextField.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -20,7 +21,13 @@ describe('An ETextField', () => {
data: null,
}
},
template: `<div data-app><e-text-field label="test" v-model="data"/></div>`,
template: `
<div data-app>
<e-text-field label="test" v-model="data">
${options?.children}
</e-text-field>
</div>
`,
})
return mountComponent(app, { vuetify, attachTo: document.body, ...options })
}
Expand Down Expand Up @@ -64,4 +71,16 @@ describe('An ETextField', () => {

expect(wrapper.vm.data).toBe(text)
})

test('allows to use the append slot', async () => {
mount({
children: `
<template #append>
<span>append</span>
</template>
`,
})

expect(await screen.findByText('append')).toBeVisible()
})
})
Loading