storybook/docs/snippets/web-components/documentscreen-story-msw-rest-request.js.mdx
Kyle Gach b97d94e005 Address feedback
- Newline following filename comment
- Fix URLs in comments
- Ensure consistent usage of `ts` vs `tsx` language
2023-01-12 14:17:39 -07:00

80 lines
1.8 KiB
Plaintext

```js
// YourPage.stories.js
import { rest } from 'msw';
export default {
title: 'DocumentScreen',
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',
},
{
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 = {
parameters: {
msw: [
rest.get('https://your-restful-endpoint/', (_req, res, ctx) => {
return res(ctx.json(TestData));
}),
],
},
};
export const MockedError = {
parameters: {
msw: [
rest.get('https://your-restful-endpoint', (_req, res, ctx) => {
return res(ctx.delay(800), ctx.status(403));
}),
],
},
};
```