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/Vue3: add interactions to vue3 cli template #18031

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions cypress/generated/addon-interactions.spec.ts
Expand Up @@ -42,4 +42,8 @@ describe('addon-interactions', () => {
onlyOn('svelte', () => {
it('should have interactions', test);
});

onlyOn('vue3', () => {
it('should have interactions', test);
});
});
8 changes: 7 additions & 1 deletion lib/cli/src/frameworks/vue3/Header.stories.js
Expand Up @@ -3,6 +3,10 @@ import MyHeader from './Header.vue';
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) => ({
Expand All @@ -19,7 +23,9 @@ const Template = (args) => ({

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/vue3/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" @click="$emit('logout')" label="Log out" v-if="user" />
<my-button size="small" @click="$emit('login')" label="Log in" v-if="!user" />
<my-button primary size="small" @click="$emit('createAccount')" label="Sign up" v-if="!user" />
Expand Down
33 changes: 16 additions & 17 deletions lib/cli/src/frameworks/vue3/Page.stories.js
@@ -1,30 +1,29 @@
import { within, userEvent } from '@storybook/testing-library';
import MyPage from './Page.vue';
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) => ({
const Template = () => ({
// Components used in your story `template` are defined in the `components` object
components: { MyPage },
// The story's `args` need to be mapped into the template through the `setup()` method
setup() {
// Story args can be mapped to keys in the returned object
return { user: args.user };
},
// Then, those values can be accessed directly in the template
template: '<my-page :user="user" />',
});

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,
};
// Here we define the `template`
template: '<my-page />',
});

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 });
await userEvent.click(loginButton);
};
26 changes: 18 additions & 8 deletions lib/cli/src/frameworks/vue3/Page.vue
Expand Up @@ -2,9 +2,9 @@
<article>
<my-header
:user="user"
@login="$emit('login')"
@logout="$emit('logout')"
@createAccount="$emit('createAccount')"
@login="onLogin"
@logout="onLogout"
@createAccount="onCreateAccount"
/>

<section>
Expand Down Expand Up @@ -67,12 +67,22 @@ export default {

components: { MyHeader },

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

emits: ['login', 'logout', 'createAccount'],
methods: {
onLogin() {
this.user = { name: 'Jane Doe' };
},
onLogout() {
this.user = null;
},
onCreateAccount() {
this.user = { name: 'Jane Doe' };
},
},
};
</script>
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'].includes(framework);
['react', 'angular', 'preact', 'svelte', 'vue3'].includes(framework);

export async function baseGenerator(
packageManager: JsPackageManager,
Expand Down