mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 01:11:06 +08:00
100 lines
2.6 KiB
Plaintext
100 lines
2.6 KiB
Plaintext
```ts
|
|
// YourPage.stories.ts
|
|
|
|
import { Meta, moduleMetadata, Story } from '@storybook/angular';
|
|
|
|
import { CommonModule } from '@angular/common';
|
|
import { HttpClientModule } from '@angular/common/http';
|
|
|
|
import { rest } from 'msw';
|
|
|
|
import { DocumentScreen } from './YourPage.component';
|
|
import { DocumentList } from './DocumentList.component';
|
|
import { DocumentHeader } from './DocumentHeader.component';
|
|
import { PageLayout } from './PageLayout.component';
|
|
|
|
export default {
|
|
/* 👇 The title prop is optional.
|
|
* See https://storybook.js.org/docs/7.0/angular/configure/overview#configure-story-loading
|
|
* to learn how to generate automatic titles
|
|
*/
|
|
title: 'DocumentScreen',
|
|
component: DocumentScreen,
|
|
decorators: [
|
|
moduleMetadata({
|
|
declarations: [DocumentList, DocumentHeader, PageLayout],
|
|
imports: [CommonModule, HttpClientModule],
|
|
}),
|
|
],
|
|
} as 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',
|
|
},
|
|
{
|
|
id: 2,
|
|
userID: 1,
|
|
title: 'Something else',
|
|
content:
|
|
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
status: 'awaiting review',
|
|
},
|
|
{
|
|
id: 3,
|
|
userID: 2,
|
|
title: 'Another document',
|
|
content:
|
|
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
status: 'approved',
|
|
},
|
|
{
|
|
id: 4,
|
|
userID: 2,
|
|
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: [
|
|
rest.get('https://your-restful-endpoint', (_req, res, ctx) => {
|
|
return res(ctx.json(TestData));
|
|
}),
|
|
],
|
|
},
|
|
};
|
|
|
|
export const MockedError: Story = {
|
|
parameters: {
|
|
msw: [
|
|
rest.get('https://your-restful-endpoint', (_req, res, ctx) => {
|
|
return res(ctx.delay(800), ctx.status(403));
|
|
}),
|
|
],
|
|
},
|
|
};
|
|
```
|