File tree 4 files changed +63
-15
lines changed
.storybook/composable-templates
4 files changed +63
-15
lines changed Original file line number Diff line number Diff line change
1
+ import { DefineComponent } from 'vue'
2
+ import { getStoryId } from '../interaction-utils/storySelector'
3
+ import { expect } from '@storybook/jest'
4
+ import { StoryFn } from '@storybook/vue3'
5
+
6
+ export const UseStatefulTemplate = (
7
+ component : Record < string , DefineComponent > ,
8
+ input : ( el : HTMLElement ) => void = el => el . click ( ) ,
9
+ defaultValue = false
10
+ ) : StoryFn => {
11
+ const story = ( ) => ( {
12
+ setup ( ) {
13
+ return {
14
+ component,
15
+ defaultValue,
16
+ }
17
+ } ,
18
+ template : `
19
+ <p>[true]</p>
20
+ <component
21
+ data-testid="true"
22
+ :is="component"
23
+ :stateful="defaultValue === true ? undefined : true"
24
+ />
25
+
26
+ <p>[false]</p>
27
+ <component
28
+ data-testid="false"
29
+ :is="component"
30
+ :stateful="defaultValue === false ? undefined : false"
31
+ />
32
+ ` ,
33
+ } )
34
+ story . play = async ( ) => {
35
+ /**
36
+ * To test stateful we need to test 2 things:
37
+ * * On user input for stateful="true" - there should be change
38
+ * * On user input for stateful="false" - there should be no change
39
+ */
40
+ input ( getStoryId ( 'true' ) )
41
+ input ( getStoryId ( 'false' ) )
42
+
43
+ // We rely on visual tests here
44
+ expect ( true ) . toBe ( true )
45
+ }
46
+ return story
47
+ }
Original file line number Diff line number Diff line change 1
1
import { VaCheckbox } from './'
2
2
import { VaButton } from '../va-button'
3
3
import { defineStory } from '../../../.storybook/types'
4
+ import {
5
+ UseStatefulTemplate ,
6
+ } from '../../../.storybook/composable-templates/useStateful-template'
4
7
5
8
export default {
6
9
title : 'VaCheckbox' ,
@@ -16,15 +19,10 @@ export const Default = () => ({
16
19
` ,
17
20
} )
18
21
19
- export const Stateful = ( ) => ( {
20
- components : { VaCheckbox } ,
21
- template : `
22
- [true]
23
- <VaCheckbox stateful/>
24
- [false]
25
- <VaCheckbox :stateful="false"/>
26
- ` ,
27
- } )
22
+ export const Stateful = UseStatefulTemplate (
23
+ VaCheckbox ,
24
+ ( el ) => ( el . children [ 0 ] as HTMLInputElement ) . click ( ) , // Clicking on checkbox container doesn't change value. see #4187
25
+ )
28
26
29
27
export const Color = ( ) => ( {
30
28
components : { VaCheckbox } ,
Original file line number Diff line number Diff line change 207
207
indeterminate-value =" middle"
208
208
/>
209
209
</VbCard >
210
- <VbCard title =" Stateless switch without v-model" >
211
- <va-switch />
212
- </VbCard >
213
- <VbCard title =" Stateful" >
214
- <va-switch stateful />
215
- </VbCard >
216
210
</VbDemo >
217
211
</template >
218
212
Original file line number Diff line number Diff line change @@ -3,6 +3,10 @@ import { defineComponent } from 'vue'
3
3
import VaSwitchDemo from './VaSwitch.demo.vue'
4
4
import VaSwitch from './VaSwitch.vue'
5
5
import { defineStory } from '../../../.storybook/types'
6
+ import { expect } from '@storybook/jest'
7
+ import {
8
+ UseStatefulTemplate ,
9
+ } from '../../../.storybook/composable-templates/useStateful-template'
6
10
7
11
export default {
8
12
title : 'VaSwitch' ,
@@ -14,6 +18,11 @@ export const Default = () => defineComponent({
14
18
template : '<VaSwitch/>' ,
15
19
} )
16
20
21
+ export const Stateful = UseStatefulTemplate (
22
+ VaSwitch ,
23
+ el => ( el . children [ 0 ] . children [ 0 ] . children [ 0 ] as HTMLInputElement ) . click ( ) , // Clicking on checkbox container doesn't change value. see #4187
24
+ )
25
+
17
26
export const ChangeEvent = defineStory ( {
18
27
story : ( ) => ( {
19
28
components : { VaSwitch } ,
You can’t perform that action at this time.
0 commit comments