-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: attempt at unified stateful test
- Loading branch information
Showing
4 changed files
with
63 additions
and
15 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/ui/.storybook/composable-templates/useStateful-template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { DefineComponent } from 'vue' | ||
import { getStoryId } from '../interaction-utils/storySelector' | ||
import { expect } from '@storybook/jest' | ||
import { StoryFn } from '@storybook/vue3' | ||
|
||
export const UseStatefulTemplate = ( | ||
component: Record<string, DefineComponent>, | ||
input: (el: HTMLElement) => void = el => el.click(), | ||
defaultValue = false | ||
): StoryFn => { | ||
const story = () => ({ | ||
setup () { | ||
return { | ||
component, | ||
defaultValue, | ||
} | ||
}, | ||
template: ` | ||
<p>[true]</p> | ||
<component | ||
data-testid="true" | ||
:is="component" | ||
:stateful="defaultValue === true ? undefined : true" | ||
/> | ||
<p>[false]</p> | ||
<component | ||
data-testid="false" | ||
:is="component" | ||
:stateful="defaultValue === false ? undefined : false" | ||
/> | ||
`, | ||
}) | ||
story.play = async () => { | ||
/** | ||
* To test stateful we need to test 2 things: | ||
* * On user input for stateful="true" - there should be change | ||
* * On user input for stateful="false" - there should be no change | ||
*/ | ||
input(getStoryId('true')) | ||
input(getStoryId('false')) | ||
|
||
// We rely on visual tests here | ||
expect(true).toBe(true) | ||
} | ||
return story | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters