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'
44import 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
8699export 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
114132export 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
168191export 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
194222export 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
220253export 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+ }
0 commit comments