-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storybook): interaction tests generators for angular
- Loading branch information
Showing
35 changed files
with
688 additions
and
423 deletions.
There are no files selected for viewing
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
15 changes: 7 additions & 8 deletions
15
packages/angular/src/generators/component-story/__snapshots__/component-story.spec.ts.snap
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
35 changes: 25 additions & 10 deletions
35
...ges/angular/src/generators/component-story/files/__componentFileName__.stories.ts__tmpl__
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 |
---|---|---|
@@ -1,16 +1,31 @@ | ||
import { Meta } from '@storybook/angular'; | ||
import type { Meta, StoryObj } from '@storybook/angular'; | ||
import { <%=componentName%> } from './<%=componentFileName%>'; | ||
<% if ( interactionTests ) { %> | ||
import { within } from '@storybook/testing-library'; | ||
import { expect } from '@storybook/jest'; | ||
<% } %> | ||
|
||
export default { | ||
title: '<%=componentName%>', | ||
component: <%=componentName%> | ||
} as Meta<<%=componentName%>>; | ||
const meta: Meta<<%= componentName %>> = { | ||
component: <%= componentName %>, | ||
title: '<%= componentName %>', | ||
}; | ||
export default meta; | ||
type Story = StoryObj<<%=componentName%>>; | ||
|
||
export const Primary = { | ||
render: (args: <%=componentName%>) => ({ | ||
props: args, | ||
}), | ||
export const Primary: Story = { | ||
args: {<% for (let prop of props) { %> | ||
<%= prop.name %>: <%- prop.defaultValue %>,<% } %> | ||
}, | ||
}; | ||
}; | ||
|
||
<% if ( interactionTests ) { %> | ||
export const Heading: Story = { | ||
args: {<% for (let prop of props) { %> | ||
<%= prop.name %>: <%- prop.defaultValue %>,<% } %> | ||
}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
expect(canvas.getByText(/<%=componentNameSimple%> works!/gi)).toBeTruthy(); | ||
}, | ||
}; | ||
<% } %> |
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
80 changes: 64 additions & 16 deletions
80
packages/angular/src/generators/stories/__snapshots__/stories-app.spec.ts.snap
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 |
---|---|---|
@@ -1,37 +1,85 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`angularStories generator: applications should generate stories file for inline scam component 1`] = ` | ||
"import { Meta } from '@storybook/angular'; | ||
"import type { Meta, StoryObj } from '@storybook/angular'; | ||
import { MyScamComponent } from './my-scam.component'; | ||
export default { | ||
title: 'MyScamComponent', | ||
import { within } from '@storybook/testing-library'; | ||
import { expect } from '@storybook/jest'; | ||
const meta: Meta<MyScamComponent> = { | ||
component: MyScamComponent, | ||
} as Meta<MyScamComponent>; | ||
title: 'MyScamComponent', | ||
}; | ||
export default meta; | ||
type Story = StoryObj<MyScamComponent>; | ||
export const Primary: Story = { | ||
args: {}, | ||
}; | ||
export const Heading: Story = { | ||
args: {}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
expect(canvas.getByText(/my-scam works!/gi)).toBeTruthy(); | ||
}, | ||
}; | ||
" | ||
`; | ||
exports[`angularStories generator: applications should generate stories file with interaction tests 1`] = ` | ||
"import type { Meta, StoryObj } from '@storybook/angular'; | ||
import { AppComponent } from './app.component'; | ||
export const Primary = { | ||
render: (args: MyScamComponent) => ({ | ||
props: args, | ||
}), | ||
import { within } from '@storybook/testing-library'; | ||
import { expect } from '@storybook/jest'; | ||
const meta: Meta<AppComponent> = { | ||
component: AppComponent, | ||
title: 'AppComponent', | ||
}; | ||
export default meta; | ||
type Story = StoryObj<AppComponent>; | ||
export const Primary: Story = { | ||
args: {}, | ||
}; | ||
export const Heading: Story = { | ||
args: {}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
expect(canvas.getByText(/app works!/gi)).toBeTruthy(); | ||
}, | ||
}; | ||
" | ||
`; | ||
exports[`angularStories generator: applications should ignore a path that has a nested component, but still generate nested component stories 1`] = ` | ||
"import { Meta } from '@storybook/angular'; | ||
"import type { Meta, StoryObj } from '@storybook/angular'; | ||
import { ComponentBComponent } from './component-b.component'; | ||
export default { | ||
title: 'ComponentBComponent', | ||
import { within } from '@storybook/testing-library'; | ||
import { expect } from '@storybook/jest'; | ||
const meta: Meta<ComponentBComponent> = { | ||
component: ComponentBComponent, | ||
} as Meta<ComponentBComponent>; | ||
title: 'ComponentBComponent', | ||
}; | ||
export default meta; | ||
type Story = StoryObj<ComponentBComponent>; | ||
export const Primary: Story = { | ||
args: {}, | ||
}; | ||
export const Primary = { | ||
render: (args: ComponentBComponent) => ({ | ||
props: args, | ||
}), | ||
export const Heading: Story = { | ||
args: {}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
expect(canvas.getByText(/component-b works!/gi)).toBeTruthy(); | ||
}, | ||
}; | ||
" | ||
`; |
Oops, something went wrong.