-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathButtonAddFriend.stories.ts
More file actions
98 lines (84 loc) · 2.16 KB
/
Copy pathButtonAddFriend.stories.ts
File metadata and controls
98 lines (84 loc) · 2.16 KB
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
import { html } from 'lit'
import { DataBrowserContext } from 'pane-registry'
import { defineAuthStoryRender, USER_OPTIONS } from '@/storybook'
import './ButtonAddFriend'
type StoryArgs = {
user: typeof USER_OPTIONS.control
subject: string
friendExists: boolean
simulateError: boolean
}
const meta = {
title: 'ButtonAddFriend',
args: {
user: 'Guest',
subject: 'https://example.com/profile/card#me',
friendExists: false,
simulateError: false,
},
argTypes: {
user: USER_OPTIONS.control,
subject: { control: 'text' },
friendExists: { control: 'boolean' },
simulateError: { control: 'boolean' },
},
} as const
function createMockContext (friendExists: boolean, simulateError: boolean): DataBrowserContext {
const store = {
fetcher: {
load: async () => undefined,
},
updater: {
update: async () => {
if (simulateError) {
throw new Error('Error adding friend, friend not added')
}
return undefined
},
},
whether: () => (friendExists ? 1 : 0),
}
return {
dom: document,
environment: { layout: 'desktop' },
session: { store },
} as unknown as DataBrowserContext
}
const render = defineAuthStoryRender<StoryArgs>(({ subject, friendExists, simulateError }) => {
const context = createMockContext(friendExists, simulateError)
return html`
<solid-ui-button-add-friend .context=${context} subject=${subject}></solid-ui-button-add-friend>
`
})
export default meta
export const Guest = {
render,
}
export const LoggedIn = {
render,
args: {
user: 'Alice',
},
}
export const FriendExists = {
render,
args: {
user: 'Alice',
friendExists: true,
},
}
export const ErrorStatus = {
render,
args: {
user: 'Alice',
simulateError: true,
},
play: async ({ canvasElement }) => {
await Promise.resolve()
const button = canvasElement.querySelector('solid-ui-button-add-friend') as HTMLElement & { shadowRoot?: ShadowRoot | null } | null
const innerButton = button?.shadowRoot?.querySelector('solid-ui-button') as HTMLElement & { shadowRoot?: ShadowRoot | null } | null
const nativeButton = innerButton?.shadowRoot?.querySelector('button') as HTMLButtonElement | null
nativeButton?.click()
await Promise.resolve()
}
}