Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI/Vue: add interactions to vue cli template #18021

Merged
4 changes: 4 additions & 0 deletions cypress/generated/addon-interactions.spec.ts
Expand Up @@ -50,4 +50,8 @@ describe('addon-interactions', () => {
onlyOn('vue3', () => {
it('should have interactions', test);
});

onlyOn('vue', () => {
it('should have interactions', test);
});
});
8 changes: 7 additions & 1 deletion lib/cli/src/frameworks/vue/Header.stories.js
Expand Up @@ -3,6 +3,10 @@ import MyHeader from './Header';
export default {
title: 'Example/Header',
component: MyHeader,
parameters: {
// More on Story layout: https://storybook.js.org/docs/vue/configure/story-layout
layout: 'fullscreen',
},
};

const Template = (args, { argTypes }) => ({
Expand All @@ -14,7 +18,9 @@ const Template = (args, { argTypes }) => ({

export const LoggedIn = Template.bind({});
LoggedIn.args = {
user: {},
user: {
name: 'Jane Doe',
},
};

export const LoggedOut = Template.bind({});
Expand Down
1 change: 1 addition & 0 deletions lib/cli/src/frameworks/vue/Header.vue
Expand Up @@ -21,6 +21,7 @@
<h1>Acme</h1>
</div>
<div>
<span class="welcome" v-if="user">Welcome, <b>{{ user.name }}</b>!</span>
<my-button size="small" @onClick="onLogout" label="Log out" v-if="user" />
<my-button size="small" @onClick="onLogin" label="Log in" v-if="!user" />
<my-button primary size="small" @onClick="onCreateAccount" label="Sign up" v-if="!user" />
Expand Down
28 changes: 15 additions & 13 deletions lib/cli/src/frameworks/vue/Page.stories.js
@@ -1,25 +1,27 @@
import { within, userEvent } from '@storybook/testing-library';

import MyPage from './Page';
import * as HeaderStories from './Header.stories';

export default {
title: 'Example/Page',
component: MyPage,
parameters: {
// More on Story layout: https://storybook.js.org/docs/vue/configure/story-layout
layout: 'fullscreen',
},
};

const Template = (args, { argTypes }) => ({
props: Object.keys(argTypes),
const Template = () => ({
components: { MyPage },
template:
'<my-page :user="user" @onLogin="onLogin" @onLogout="onLogout" @onCreateAccount="onCreateAccount" />',
template: '<my-page />',
});

export const LoggedIn = Template.bind({});
LoggedIn.args = {
// More on composing args: https://storybook.js.org/docs/vue/writing-stories/args#args-composition
...HeaderStories.LoggedIn.args,
};

export const LoggedOut = Template.bind({});
LoggedOut.args = {
...HeaderStories.LoggedOut.args,

// More on interaction testing: https://storybook.js.org/docs/vue/writing-tests/interaction-testing
export const LoggedIn = Template.bind({});
LoggedIn.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', { name: /Log in/i });
yannbf marked this conversation as resolved.
Show resolved Hide resolved
await userEvent.click(loginButton);
};
14 changes: 7 additions & 7 deletions lib/cli/src/frameworks/vue/Page.vue
Expand Up @@ -67,21 +67,21 @@ export default {

components: { MyHeader },

props: {
user: {
type: Object,
},
data() {
return {
user: null,
};
},

methods: {
onLogin() {
this.$emit('onLogin');
this.user = { name: 'Jane Doe' };
},
onLogout() {
this.$emit('onLogout');
this.user = null;
},
onCreateAccount() {
this.$emit('onCreateAccount');
this.user = { name: 'Jane Doe' };
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/generators/baseGenerator.ts
Expand Up @@ -62,7 +62,7 @@ const builderDependencies = (builder: Builder) => {
const stripVersions = (addons: string[]) => addons.map((addon) => getPackageDetails(addon)[0]);

const hasInteractiveStories = (framework: SupportedFrameworks) =>
['react', 'angular', 'preact', 'svelte', 'vue3', 'html'].includes(framework);
['react', 'angular', 'preact', 'svelte', 'vue', 'vue3', 'html'].includes(framework);

export async function baseGenerator(
packageManager: JsPackageManager,
Expand Down