-
Notifications
You must be signed in to change notification settings - Fork 40
/
App.stories.tsx
executable file
·103 lines (91 loc) · 2.13 KB
/
App.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import React from 'react'
import { ApolloClient, ApolloProvider, InMemoryCache } from '@apollo/client'
import { graphql, HttpResponse, delay } from 'msw'
import { App } from './App'
const meta = {
title: 'Demos/Apollo',
component: App,
}
export default meta;
const defaultClient = new ApolloClient({
uri: 'https://swapi-graphql.netlify.app/.netlify/functions/index',
cache: new InMemoryCache(),
})
export const DefaultBehavior = () => (
<ApolloProvider client={defaultClient}>
<App />
</ApolloProvider>
)
const mockedClient = new ApolloClient({
uri: 'https://swapi-graphql.netlify.app/.netlify/functions/index',
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
fetchPolicy: 'no-cache',
errorPolicy: 'all',
},
query: {
fetchPolicy: 'no-cache',
errorPolicy: 'all',
},
},
})
const MockTemplate = () => (
<ApolloProvider client={mockedClient}>
<App />
</ApolloProvider>
)
const films = [
{
title: 'A New Hope',
episode_id: 4,
opening_crawl: `(Mocked) Rebel spaceships have won their first victory against the evil Galactic Empire.`,
},
{
title: 'Empire Strikes Back',
episode_id: 5,
opening_crawl: `(Mocked) Imperial troops are pursuing the Rebel forces across the galaxy.`,
},
{
title: 'Return of the Jedi',
episode_id: 6,
opening_crawl: `(Mocked) Luke Skywalker has returned to his home planet of Tatooine to rescue Han Solo.`,
},
]
export const MockedSuccess = {
render: MockTemplate,
parameters: {
msw: {
handlers: [
graphql.query('AllFilmsQuery', () => {
return HttpResponse.json({
data: {
allFilms: {
films,
},
},
})
}),
],
},
},
}
export const MockedError = {
render: MockTemplate,
parameters: {
msw: {
handlers: [
graphql.query('AllFilmsQuery', async () => {
await delay(300)
return HttpResponse.json({
errors: [
{
message: 'Access denied',
},
],
})
}),
],
},
},
}