Skip to content

Commit 47494c3

Browse files
committed
test(DsfrButton): ✅ use storybook play function
and remove cypress tests
1 parent 7b14568 commit 47494c3

File tree

3 files changed

+54
-32
lines changed

3 files changed

+54
-32
lines changed

src/components/DsfrButton/DsfrButton.e2e.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/components/DsfrButton/DsfrButton.stories.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import VIcon from '../VIcon/VIcon.vue'
2-
import { fn } from '@storybook/test'
1+
import { expect, fn, within } from '@storybook/test'
32

3+
import VIcon from '../VIcon/VIcon.vue'
44
import DsfrButton from './DsfrButton.vue'
55

66
/**
@@ -54,6 +54,10 @@ export const BoutonPrimaire = (args) => ({
5454
data () {
5555
return {
5656
...args,
57+
onClickWrapper () {
58+
this.theClick()
59+
this.onClick()
60+
},
5761
}
5862
},
5963
template: `
@@ -67,7 +71,7 @@ export const BoutonPrimaire = (args) => ({
6771
:no-outline="noOutline"
6872
:icon-only="iconOnly"
6973
:icon-right="iconRight"
70-
@click="onClick"
74+
@click="onClickWrapper()"
7175
/>
7276
`,
7377
})
@@ -81,6 +85,15 @@ BoutonPrimaire.args = {
8185
iconRight: false,
8286
noOutline: false,
8387
size: undefined,
88+
theClick: fn(),
89+
}
90+
91+
BoutonPrimaire.play = async ({ canvasElement }) => {
92+
const canvas = within(canvasElement)
93+
const button = canvas.getByRole('button')
94+
expect(BoutonPrimaire.args.theClick).not.toHaveBeenCalled()
95+
button.click()
96+
expect(BoutonPrimaire.args.theClick).toHaveBeenCalledOnce()
8497
}
8598

8699
export const BoutonPrimaireAvecIcone = (args) => ({
@@ -110,6 +123,11 @@ BoutonPrimaireAvecIcone.args = {
110123
noOutline: false,
111124
size: undefined,
112125
}
126+
BoutonPrimaireAvecIcone.play = async ({ canvasElement }) => {
127+
const canvas = within(canvasElement)
128+
const button = canvas.getByRole('button')
129+
expect(button.firstElementChild?.nextElementSibling).toContainHTML('<svg')
130+
}
113131

114132
export const BoutonPrimaireAvecIconeAnimee = (args) => ({
115133
components: { DsfrButton },
@@ -164,6 +182,11 @@ BoutonSecondaire.args = {
164182
noOutline: false,
165183
size: undefined,
166184
}
185+
BoutonSecondaire.play = async ({ canvasElement }) => {
186+
const canvas = within(canvasElement)
187+
const button = canvas.getByRole('button')
188+
expect(button).toHaveClass('fr-btn--secondary')
189+
}
167190

168191
export const BoutonTertiaire = (args) => ({
169192
components: { DsfrButton },
@@ -190,6 +213,11 @@ BoutonTertiaire.args = {
190213
noOutline: false,
191214
size: undefined,
192215
}
216+
BoutonTertiaire.play = async ({ canvasElement }) => {
217+
const canvas = within(canvasElement)
218+
const button = canvas.getByRole('button')
219+
expect(button).toHaveClass('fr-btn--tertiary')
220+
}
193221

194222
export const BoutonTertiaireSansBordure = (args) => ({
195223
components: { DsfrButton },
@@ -216,6 +244,11 @@ BoutonTertiaireSansBordure.args = {
216244
noOutline: true,
217245
size: undefined,
218246
}
247+
BoutonTertiaireSansBordure.play = async ({ canvasElement }) => {
248+
const canvas = within(canvasElement)
249+
const button = canvas.getByRole('button')
250+
expect(button).toHaveClass('fr-btn--tertiary-no-outline')
251+
}
219252

220253
export const SuiteDeBoutons = (args) => ({
221254
components: {
@@ -269,3 +302,12 @@ SuiteDeBoutons.args = {
269302
},
270303
],
271304
}
305+
306+
SuiteDeBoutons.play = async ({ canvasElement }) => {
307+
const canvas = within(canvasElement)
308+
const buttons = canvas.getAllByRole('button')
309+
expect(buttons).toHaveLength(4)
310+
for (const button of buttons) {
311+
expect(button).toBeVisible()
312+
}
313+
}

src/components/DsfrButton/DsfrButtonGroup.stories.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fn } from '@storybook/test'
1+
import { expect, fn, within } from '@storybook/test'
22

33
import VIcon from '../VIcon/VIcon.vue'
44
import DsfrButtonGroup from './DsfrButtonGroup.vue'
@@ -107,3 +107,11 @@ GroupeDeBoutons.args = {
107107
},
108108
],
109109
}
110+
GroupeDeBoutons.play = async ({ canvasElement }) => {
111+
const canvas = within(canvasElement)
112+
const buttons = canvas.getAllByRole('button')
113+
expect(buttons).toHaveLength(4)
114+
for (const button of buttons) {
115+
expect(button).toBeVisible()
116+
}
117+
}

0 commit comments

Comments
 (0)