/
InteractionsPanel.stories.tsx
135 lines (118 loc) · 3.41 KB
/
InteractionsPanel.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React from 'react';
import type { StoryObj, Meta } from '@storybook/react';
import { CallStates } from '@storybook/instrumenter';
import { styled } from '@storybook/theming';
import { userEvent, within, waitFor, expect } from '@storybook/test';
import { isChromatic } from '../../../../ui/.storybook/isChromatic';
import { getCalls, getInteractions } from '../mocks';
import { InteractionsPanel } from './InteractionsPanel';
import SubnavStories from './Subnav.stories';
const StyledWrapper = styled.div(({ theme }) => ({
backgroundColor: theme.background.content,
color: theme.color.defaultText,
display: 'block',
height: '100%',
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
overflow: 'auto',
}));
const interactions = getInteractions(CallStates.DONE);
const meta = {
title: 'Addons/Interactions/InteractionsPanel',
component: InteractionsPanel,
decorators: [
(Story: any) => (
<StyledWrapper id="panel-tab-content">
<Story />
</StyledWrapper>
),
],
parameters: {
layout: 'fullscreen',
theme: 'light', // stacked will break interactions
},
args: {
calls: new Map(getCalls(CallStates.DONE).map((call) => [call.id, call])),
controls: SubnavStories.args.controls,
controlStates: SubnavStories.args.controlStates,
interactions,
fileName: 'addon-interactions.stories.tsx',
hasException: false,
isPlaying: false,
onScrollToEnd: () => {},
endRef: null,
// prop for the AddonPanel used as wrapper of Panel
active: true,
},
} as Meta<typeof InteractionsPanel>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Passing: Story = {
args: {
interactions: getInteractions(CallStates.DONE),
},
};
Passing.play = async ({ args, canvasElement }) => {
if (isChromatic()) return;
const canvas = within(canvasElement);
await waitFor(async () => {
await userEvent.click(canvas.getByLabelText('Go to start'));
await expect(args.controls.start).toHaveBeenCalled();
});
await waitFor(async () => {
await userEvent.click(canvas.getByLabelText('Go back'));
await expect(args.controls.back).toHaveBeenCalled();
});
await waitFor(async () => {
await userEvent.click(canvas.getByLabelText('Go forward'));
await expect(args.controls.next).not.toHaveBeenCalled();
});
await waitFor(async () => {
await userEvent.click(canvas.getByLabelText('Go to end'));
await expect(args.controls.end).not.toHaveBeenCalled();
});
await waitFor(async () => {
await userEvent.click(canvas.getByLabelText('Rerun'));
await expect(args.controls.rerun).toHaveBeenCalled();
});
};
export const Paused: Story = {
args: {
isPlaying: true,
interactions: getInteractions(CallStates.WAITING),
controlStates: {
start: false,
back: false,
goto: true,
next: true,
end: true,
},
pausedAt: interactions[interactions.length - 1].id,
},
};
export const Playing: Story = {
args: {
isPlaying: true,
interactions: getInteractions(CallStates.ACTIVE),
},
};
export const Failed: Story = {
args: {
hasException: true,
interactions: getInteractions(CallStates.ERROR),
},
};
export const NoInteractions: Story = {
args: {
interactions: [],
},
};
export const CaughtException: Story = {
args: {
hasException: true,
interactions: [],
caughtException: new TypeError("Cannot read properties of undefined (reading 'args')"),
},
};