mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 06:41:25 +08:00
8.3 KiB
8.3 KiB
import type { Meta, StoryObj } from '@storybook/angular';
import { http, HttpResponse, delay } from 'msw';
import { DocumentScreen } from './YourPage.component';
const meta: Meta<DocumentScreen> = {
component: DocumentScreen,
};
export default meta;
type Story = StoryObj<DocumentScreen>;
// 👇 The mocked data that will be used in the story
const TestData = {
user: {
userID: 1,
name: 'Someone',
},
document: {
id: 1,
userID: 1,
title: 'Something',
brief: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
status: 'approved',
},
subdocuments: [
{
id: 1,
userID: 1,
title: 'Something',
content:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
status: 'approved',
},
],
};
export const MockedSuccess: Story = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint/', () => {
return HttpResponse.json(TestData);
}),
],
},
},
};
export const MockedError: Story = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint', async () => {
await delay(800);
return new HttpResponse(null, {
status: 403,
});
}),
],
},
},
};
import { http, HttpResponse, delay } from 'msw';
import { DocumentScreen } from './YourPage';
export default {
component: DocumentScreen,
};
// 👇 The mocked data that will be used in the story
const TestData = {
user: {
userID: 1,
name: 'Someone',
},
document: {
id: 1,
userID: 1,
title: 'Something',
brief: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
status: 'approved',
},
subdocuments: [
{
id: 1,
userID: 1,
title: 'Something',
content:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
status: 'approved',
},
],
};
export const MockedSuccess = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint/', () => {
return HttpResponse.json(TestData);
}),
],
},
},
};
export const MockedError = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint', async () => {
await delay(800);
return new HttpResponse(null, {
status: 403,
});
}),
],
},
},
};
// Replace your-framework with the name of your framework (e.g. nextjs, vue3-vite)
import type { Meta, StoryObj } from '@storybook/your-framework';
import { http, HttpResponse, delay } from 'msw';
import { MyComponent } from './MyComponent';
const meta = {
component: DocumentScreen,
} satisfies Meta<typeof MyComponent>;
export default meta;
type Story = StoryObj<typeof meta>;
// 👇 The mocked data that will be used in the story
const TestData = {
user: {
userID: 1,
name: 'Someone',
},
document: {
id: 1,
userID: 1,
title: 'Something',
brief: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
status: 'approved',
},
subdocuments: [
{
id: 1,
userID: 1,
title: 'Something',
content:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
status: 'approved',
},
],
};
export const MockedSuccess: Story = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint/', () => {
return HttpResponse.json(TestData);
}),
],
},
},
};
export const MockedError: Story = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint', async () => {
await delay(800);
return new HttpResponse(null, {
status: 403,
});
}),
],
},
},
};
// Replace your-framework with the name of your framework (e.g. nextjs, vue3-vite)
import type { Meta, StoryObj } from '@storybook/your-framework';
import { http, HttpResponse, delay } from 'msw';
import { MyComponent } from './MyComponent';
const meta: Meta<typeof MyComponent> = {
component: DocumentScreen,
};
export default meta;
type Story = StoryObj<typeof MyComponent>;
// 👇 The mocked data that will be used in the story
const TestData = {
user: {
userID: 1,
name: 'Someone',
},
document: {
id: 1,
userID: 1,
title: 'Something',
brief: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
status: 'approved',
},
subdocuments: [
{
id: 1,
userID: 1,
title: 'Something',
content:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
status: 'approved',
},
],
};
export const MockedSuccess: Story = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint/', () => {
return HttpResponse.json(TestData);
}),
],
},
},
};
export const MockedError: Story = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint', async () => {
await delay(800);
return new HttpResponse(null, {
status: 403,
});
}),
],
},
},
};
import { http, HttpResponse, delay } from 'msw';
export default {
component: 'demo-document-screen',
};
// 👇 The mocked data that will be used in the story
const TestData = {
user: {
userID: 1,
name: 'Someone',
},
document: {
id: 1,
userID: 1,
title: 'Something',
brief: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
status: 'approved',
},
subdocuments: [
{
id: 1,
userID: 1,
title: 'Something',
content:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
status: 'approved',
},
],
};
export const MockedSuccess = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint/', () => {
return HttpResponse.json(TestData);
}),
],
},
},
};
export const MockedError = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint', async () => {
await delay(800);
return new HttpResponse(null, {
status: 403,
});
}),
],
},
},
};
import type { Meta, StoryObj } from '@storybook/web-components';
import { http, HttpResponse, delay } from 'msw';
const meta: Meta = {
component: 'demo-document-screen',
};
export default meta;
type Story = StoryObj;
// 👇 The mocked data that will be used in the story
const TestData = {
user: {
userID: 1,
name: 'Someone',
},
document: {
id: 1,
userID: 1,
title: 'Something',
brief: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
status: 'approved',
},
subdocuments: [
{
id: 1,
userID: 1,
title: 'Something',
content:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
status: 'approved',
},
],
};
export const MockedSuccess: Story = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint/', () => {
return HttpResponse.json(TestData);
}),
],
},
},
};
export const MockedError: Story = {
parameters: {
msw: {
handlers: [
http.get('https://your-restful-endpoint', async () => {
await delay(800);
return new HttpResponse(null, {
status: 403,
});
}),
],
},
},
};