/
App.stories.tsx
executable file
·92 lines (80 loc) · 1.86 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
import React from 'react'
import { createClient, Provider } from 'urql'
import { graphql, HttpResponse, delay } from 'msw'
import { App } from './App'
const meta = {
title: 'Demos/Urql',
component: App,
}
export default meta
const defaultClient = createClient({
url: 'https://swapi-graphql.netlify.app/.netlify/functions/index',
})
export const DefaultBehavior = () => (
<Provider value={defaultClient}>
<App />
</Provider>
)
const mockedClient = createClient({
url: 'https://swapi-graphql.netlify.app/.netlify/functions/index',
requestPolicy: 'network-only',
})
const MockTemplate = () => (
<Provider value={mockedClient}>
<App />
</Provider>
)
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',
},
],
})
}),
],
},
},
}