1
1
import { MockTasks , MockUserOwner , mockApiError } from "testHelpers/entities" ;
2
- import { withAuthProvider } from "testHelpers/storybook" ;
2
+ import { withAuthProvider , withGlobalSnackbar } from "testHelpers/storybook" ;
3
3
import type { Meta , StoryObj } from "@storybook/react-vite" ;
4
4
import { API } from "api/api" ;
5
5
import { MockUsers } from "pages/UsersPage/storybookData/users" ;
6
- import { spyOn , userEvent , within } from "storybook/test" ;
6
+ import { expect , spyOn , userEvent , waitFor , within } from "storybook/test" ;
7
7
import { reactRouterParameters } from "storybook-addon-remix-react-router" ;
8
8
import { TasksSidebar } from "./TasksSidebar" ;
9
9
@@ -17,6 +17,18 @@ const meta: Meta<typeof TasksSidebar> = {
17
17
permissions :{
18
18
viewAllUsers :true ,
19
19
} ,
20
+ reactRouter :reactRouterParameters ( {
21
+ location :{
22
+ path :`/tasks/${ MockTasks [ 0 ] . workspace . name } ` ,
23
+ pathParams :{
24
+ workspace :MockTasks [ 0 ] . workspace . name ,
25
+ } ,
26
+ } ,
27
+ routing :[
28
+ { path :"/tasks/:workspace" , useStoryElement :true } ,
29
+ { path :"/tasks" , element :< div > Tasks Index Page</ div > } ,
30
+ ] ,
31
+ } ) ,
20
32
} ,
21
33
beforeEach :( ) => {
22
34
spyOn ( API , "getUsers" ) . mockResolvedValue ( {
@@ -49,16 +61,6 @@ export const Loaded: Story = {
49
61
beforeEach :( ) => {
50
62
spyOn ( API . experimental , "getTasks" ) . mockResolvedValue ( MockTasks ) ;
51
63
} ,
52
- parameters :{
53
- reactRouter :reactRouterParameters ( {
54
- location :{
55
- pathParams :{
56
- workspace :MockTasks [ 0 ] . workspace . name ,
57
- } ,
58
- } ,
59
- routing :{ path :"/tasks/:workspace" } ,
60
- } ) ,
61
- } ,
62
64
} ;
63
65
64
66
export const Empty :Story = {
@@ -71,19 +73,90 @@ export const Closed: Story = {
71
73
beforeEach :( ) => {
72
74
spyOn ( API . experimental , "getTasks" ) . mockResolvedValue ( MockTasks ) ;
73
75
} ,
74
- parameters :{
75
- reactRouter :reactRouterParameters ( {
76
- location :{
77
- pathParams :{
78
- workspace :MockTasks [ 0 ] . workspace . name ,
79
- } ,
80
- } ,
81
- routing :{ path :"/tasks/:workspace" } ,
82
- } ) ,
83
- } ,
84
76
play :async ( { canvasElement} ) => {
85
77
const canvas = within ( canvasElement ) ;
86
78
const button = canvas . getByRole ( "button" , { name :/ c l o s e s i d e b a r / i} ) ;
87
79
await userEvent . click ( button ) ;
88
80
} ,
89
81
} ;
82
+
83
+ export const OpenOptionsMenu :Story = {
84
+ beforeEach :( ) => {
85
+ spyOn ( API . experimental , "getTasks" ) . mockResolvedValue ( MockTasks ) ;
86
+ } ,
87
+ play :async ( { canvasElement} ) => {
88
+ const canvas = within ( canvasElement ) ;
89
+ const optionButtons = await canvas . findAllByRole ( "button" , {
90
+ name :/ t a s k o p t i o n s / i,
91
+ } ) ;
92
+ await userEvent . click ( optionButtons [ 0 ] ) ;
93
+ } ,
94
+ } ;
95
+
96
+ export const DeleteTaskDialog :Story = {
97
+ beforeEach :( ) => {
98
+ spyOn ( API . experimental , "getTasks" ) . mockResolvedValue ( MockTasks ) ;
99
+ } ,
100
+ play :async ( { canvasElement, step} ) => {
101
+ await step ( "Open menu" , async ( ) => {
102
+ const canvas = within ( canvasElement ) ;
103
+ const optionButtons = await canvas . findAllByRole ( "button" , {
104
+ name :/ t a s k o p t i o n s / i,
105
+ } ) ;
106
+ await userEvent . click ( optionButtons [ 0 ] ) ;
107
+ } ) ;
108
+ await step ( "Open delete dialog" , async ( ) => {
109
+ const body = within ( canvasElement . ownerDocument . body ) ;
110
+ const deleteButton = await body . findByRole ( "menuitem" , {
111
+ name :/ d e l e t e / i,
112
+ } ) ;
113
+ await userEvent . click ( deleteButton ) ;
114
+ } ) ;
115
+ } ,
116
+ } ;
117
+
118
+ export const DeleteTaskSuccess :Story = {
119
+ decorators :[ withGlobalSnackbar ] ,
120
+ parameters :{
121
+ chromatic :{
122
+ disableSnapshot :false ,
123
+ } ,
124
+ } ,
125
+ beforeEach :( ) => {
126
+ spyOn ( API . experimental , "getTasks" ) . mockResolvedValue ( MockTasks ) ;
127
+ spyOn ( API . experimental , "deleteTask" ) . mockResolvedValue ( ) ;
128
+ } ,
129
+ play :async ( { canvasElement, step} ) => {
130
+ const body = within ( canvasElement . ownerDocument . body ) ;
131
+ const canvas = within ( canvasElement ) ;
132
+
133
+ await step ( "Open menu" , async ( ) => {
134
+ const optionButtons = await canvas . findAllByRole ( "button" , {
135
+ name :/ t a s k o p t i o n s / i,
136
+ } ) ;
137
+ await userEvent . click ( optionButtons [ 0 ] ) ;
138
+ } ) ;
139
+
140
+ await step ( "Open delete dialog" , async ( ) => {
141
+ const deleteButton = await body . findByRole ( "menuitem" , {
142
+ name :/ d e l e t e / i,
143
+ } ) ;
144
+ await userEvent . click ( deleteButton ) ;
145
+ } ) ;
146
+
147
+ await step ( "Confirm delete" , async ( ) => {
148
+ const confirmButton = await body . findByRole ( "button" , {
149
+ name :/ d e l e t e / i,
150
+ } ) ;
151
+ await userEvent . click ( confirmButton ) ;
152
+ await step ( "Confirm delete" , async ( ) => {
153
+ await waitFor ( ( ) => {
154
+ expect ( API . experimental . deleteTask ) . toHaveBeenCalledWith (
155
+ MockTasks [ 0 ] . workspace . owner_name ,
156
+ MockTasks [ 0 ] . workspace . id ,
157
+ ) ;
158
+ } ) ;
159
+ } ) ;
160
+ } ) ;
161
+ } ,
162
+ } ;