1
+ import type { Meta , StoryObj } from "@storybook/react" ;
2
+ import { expect , userEvent , waitFor , within } from "@storybook/test" ;
1
3
import {
2
4
MockOutdatedWorkspace ,
3
5
MockTemplate ,
4
6
MockTemplateVersion ,
7
+ MockTemplateVersionWithMarkdownMessage ,
5
8
MockWorkspace ,
6
9
} from "testHelpers/entities" ;
7
- import { WorkspaceNotifications } from "./WorkspaceNotifications" ;
8
- import type { Meta , StoryObj } from "@storybook/react" ;
9
- import { withDashboardProvider } from "testHelpers/storybook" ;
10
10
import { getWorkspaceResolveAutostartQueryKey } from "api/queries/workspaceQuota" ;
11
+ import { withDashboardProvider } from "testHelpers/storybook" ;
12
+ import { WorkspaceNotifications } from "./WorkspaceNotifications" ;
11
13
12
14
const defaultPermissions = {
13
15
readWorkspace : true ,
@@ -17,7 +19,7 @@ const defaultPermissions = {
17
19
} ;
18
20
19
21
const meta : Meta < typeof WorkspaceNotifications > = {
20
- title : "components /WorkspaceNotifications" ,
22
+ title : "pages/WorkspacePage /WorkspaceNotifications" ,
21
23
component : WorkspaceNotifications ,
22
24
args : {
23
25
latestVersion : MockTemplateVersion ,
@@ -45,7 +47,37 @@ type Story = StoryObj<typeof WorkspaceNotifications>;
45
47
export const Outdated : Story = {
46
48
args : {
47
49
workspace : MockOutdatedWorkspace ,
48
- defaultOpen : "info" ,
50
+ } ,
51
+
52
+ play : async ( { canvasElement, step } ) => {
53
+ const screen = within ( canvasElement ) ;
54
+
55
+ await step ( "activate hover trigger" , async ( ) => {
56
+ await userEvent . hover ( screen . getByTestId ( "info-notifications" ) ) ;
57
+ await waitFor ( ( ) =>
58
+ expect (
59
+ screen . getByText ( MockTemplateVersion . message ) ,
60
+ ) . toBeInTheDocument ( ) ,
61
+ ) ;
62
+ } ) ;
63
+ } ,
64
+ } ;
65
+
66
+ export const OutdatedWithMarkdownMessage : Story = {
67
+ args : {
68
+ workspace : MockOutdatedWorkspace ,
69
+ latestVersion : MockTemplateVersionWithMarkdownMessage ,
70
+ } ,
71
+
72
+ play : async ( { canvasElement, step } ) => {
73
+ const screen = within ( canvasElement ) ;
74
+
75
+ await step ( "activate hover trigger" , async ( ) => {
76
+ await userEvent . hover ( screen . getByTestId ( "info-notifications" ) ) ;
77
+ await waitFor ( ( ) =>
78
+ expect ( screen . getByText ( / a n u p d a t e i s a v a i l a b l e / i) ) . toBeInTheDocument ( ) ,
79
+ ) ;
80
+ } ) ;
49
81
} ,
50
82
} ;
51
83
@@ -56,7 +88,6 @@ export const RequiresManualUpdate: Story = {
56
88
automatic_updates : "always" ,
57
89
autostart_schedule : "daily" ,
58
90
} ,
59
- defaultOpen : "warning" ,
60
91
} ,
61
92
parameters : {
62
93
queries : [
@@ -68,6 +99,19 @@ export const RequiresManualUpdate: Story = {
68
99
} ,
69
100
] ,
70
101
} ,
102
+
103
+ play : async ( { canvasElement, step } ) => {
104
+ const screen = within ( canvasElement ) ;
105
+
106
+ await step ( "activate hover trigger" , async ( ) => {
107
+ await userEvent . hover ( screen . getByTestId ( "warning-notifications" ) ) ;
108
+ await waitFor ( ( ) =>
109
+ expect (
110
+ screen . getByText ( / u n a b l e t o a u t o m a t i c a l l y u p d a t e / i) ,
111
+ ) . toBeInTheDocument ( ) ,
112
+ ) ;
113
+ } ) ;
114
+ } ,
71
115
} ;
72
116
73
117
export const Unhealthy : Story = {
@@ -83,7 +127,17 @@ export const Unhealthy: Story = {
83
127
status : "running" ,
84
128
} ,
85
129
} ,
86
- defaultOpen : "warning" ,
130
+ } ,
131
+
132
+ play : async ( { canvasElement, step } ) => {
133
+ const screen = within ( canvasElement ) ;
134
+
135
+ await step ( "activate hover trigger" , async ( ) => {
136
+ await userEvent . hover ( screen . getByTestId ( "warning-notifications" ) ) ;
137
+ await waitFor ( ( ) =>
138
+ expect ( screen . getByText ( / w o r k s p a c e i s u n h e a l t h y / i) ) . toBeInTheDocument ( ) ,
139
+ ) ;
140
+ } ) ;
87
141
} ,
88
142
} ;
89
143
@@ -95,6 +149,8 @@ export const UnhealthyWithoutUpdatePermission: Story = {
95
149
updateWorkspace : false ,
96
150
} ,
97
151
} ,
152
+
153
+ play : Unhealthy . play ,
98
154
} ;
99
155
100
156
const DormantWorkspace = {
@@ -104,9 +160,19 @@ const DormantWorkspace = {
104
160
105
161
export const Dormant : Story = {
106
162
args : {
107
- defaultOpen : "warning" ,
108
163
workspace : DormantWorkspace ,
109
164
} ,
165
+
166
+ play : async ( { canvasElement, step } ) => {
167
+ const screen = within ( canvasElement ) ;
168
+
169
+ await step ( "activate hover trigger" , async ( ) => {
170
+ await userEvent . hover ( screen . getByTestId ( "warning-notifications" ) ) ;
171
+ await waitFor ( ( ) =>
172
+ expect ( screen . getByText ( / w o r k s p a c e i s d o r m a n t / i) ) . toBeInTheDocument ( ) ,
173
+ ) ;
174
+ } ) ;
175
+ } ,
110
176
} ;
111
177
112
178
export const DormantWithDeletingDate : Story = {
@@ -117,6 +183,8 @@ export const DormantWithDeletingDate: Story = {
117
183
deleting_at : new Date ( "2020-10-01T00:00:00Z" ) . toISOString ( ) ,
118
184
} ,
119
185
} ,
186
+
187
+ play : Dormant . play ,
120
188
} ;
121
189
122
190
export const PendingInQueue : Story = {
@@ -133,7 +201,17 @@ export const PendingInQueue: Story = {
133
201
} ,
134
202
} ,
135
203
} ,
136
- defaultOpen : "info" ,
204
+ } ,
205
+
206
+ play : async ( { canvasElement, step } ) => {
207
+ const screen = within ( canvasElement ) ;
208
+
209
+ await step ( "activate hover trigger" , async ( ) => {
210
+ await userEvent . hover ( await screen . findByTestId ( "info-notifications" ) ) ;
211
+ await waitFor ( ( ) =>
212
+ expect ( screen . getByText ( / b u i l d i s p e n d i n g / i) ) . toBeInTheDocument ( ) ,
213
+ ) ;
214
+ } ) ;
137
215
} ,
138
216
} ;
139
217
@@ -145,6 +223,16 @@ export const TemplateDeprecated: Story = {
145
223
deprecation_message :
146
224
"Template deprecated due to reasons. [Learn more](#)" ,
147
225
} ,
148
- defaultOpen : "warning" ,
226
+ } ,
227
+
228
+ play : async ( { canvasElement, step } ) => {
229
+ const screen = within ( canvasElement ) ;
230
+
231
+ await step ( "activate hover trigger" , async ( ) => {
232
+ await userEvent . hover ( screen . getByTestId ( "warning-notifications" ) ) ;
233
+ await waitFor ( ( ) =>
234
+ expect ( screen . getByText ( / d e p r e c a t e d t e m p l a t e / i) ) . toBeInTheDocument ( ) ,
235
+ ) ;
236
+ } ) ;
149
237
} ,
150
238
} ;
0 commit comments