1
1
import type { Meta , StoryObj } from "@storybook/react" ;
2
- import { expect , spyOn , userEvent , within } from "@storybook/test" ;
2
+ import { expect , spyOn , userEvent , waitFor , within } from "@storybook/test" ;
3
3
import { API } from "api/api" ;
4
4
import { MockUsers } from "pages/UsersPage/storybookData/users" ;
5
5
import {
6
6
MockTemplate ,
7
+ MockTemplateVersionExternalAuthGithub ,
8
+ MockTemplateVersionExternalAuthGithubAuthenticated ,
7
9
MockUserOwner ,
8
10
MockWorkspace ,
9
11
MockWorkspaceAppStatus ,
@@ -27,10 +29,20 @@ const meta: Meta<typeof TasksPage> = {
27
29
} ,
28
30
} ,
29
31
beforeEach : ( ) => {
32
+ spyOn ( API , "getTemplateVersionExternalAuth" ) . mockResolvedValue ( [ ] ) ;
30
33
spyOn ( API , "getUsers" ) . mockResolvedValue ( {
31
34
users : MockUsers ,
32
35
count : MockUsers . length ,
33
36
} ) ;
37
+ spyOn ( data , "fetchAITemplates" ) . mockResolvedValue ( [
38
+ MockTemplate ,
39
+ {
40
+ ...MockTemplate ,
41
+ id : "test-template-2" ,
42
+ name : "template 2" ,
43
+ display_name : "Template 2" ,
44
+ } ,
45
+ ] ) ;
34
46
} ,
35
47
} ;
36
48
@@ -134,6 +146,7 @@ export const CreateTaskSuccessfully: Story = {
134
146
const prompt = await canvas . findByLabelText ( / p r o m p t / i) ;
135
147
await userEvent . type ( prompt , newTaskData . prompt ) ;
136
148
const submitButton = canvas . getByRole ( "button" , { name : / r u n t a s k / i } ) ;
149
+ await waitFor ( ( ) => expect ( submitButton ) . toBeEnabled ( ) ) ;
137
150
await userEvent . click ( submitButton ) ;
138
151
} ) ;
139
152
@@ -164,6 +177,7 @@ export const CreateTaskError: Story = {
164
177
const prompt = await canvas . findByLabelText ( / p r o m p t / i) ;
165
178
await userEvent . type ( prompt , "Create a new task" ) ;
166
179
const submitButton = canvas . getByRole ( "button" , { name : / r u n t a s k / i } ) ;
180
+ await waitFor ( ( ) => expect ( submitButton ) . toBeEnabled ( ) ) ;
167
181
await userEvent . click ( submitButton ) ;
168
182
} ) ;
169
183
@@ -173,6 +187,98 @@ export const CreateTaskError: Story = {
173
187
} ,
174
188
} ;
175
189
190
+ export const WithExternalAuth : Story = {
191
+ decorators : [ withProxyProvider ( ) ] ,
192
+ beforeEach : ( ) => {
193
+ spyOn ( data , "fetchTasks" )
194
+ . mockResolvedValueOnce ( MockTasks )
195
+ . mockResolvedValue ( [ newTaskData , ...MockTasks ] ) ;
196
+ spyOn ( data , "createTask" ) . mockResolvedValue ( newTaskData ) ;
197
+ spyOn ( API , "getTemplateVersionExternalAuth" ) . mockResolvedValue ( [
198
+ MockTemplateVersionExternalAuthGithubAuthenticated ,
199
+ ] ) ;
200
+ } ,
201
+ play : async ( { canvasElement, step } ) => {
202
+ const canvas = within ( canvasElement ) ;
203
+
204
+ await step ( "Run task" , async ( ) => {
205
+ const prompt = await canvas . findByLabelText ( / p r o m p t / i) ;
206
+ await userEvent . type ( prompt , newTaskData . prompt ) ;
207
+ const submitButton = canvas . getByRole ( "button" , { name : / r u n t a s k / i } ) ;
208
+ await waitFor ( ( ) => expect ( submitButton ) . toBeEnabled ( ) ) ;
209
+ await userEvent . click ( submitButton ) ;
210
+ } ) ;
211
+
212
+ await step ( "Verify task in the table" , async ( ) => {
213
+ await canvas . findByRole ( "row" , {
214
+ name : new RegExp ( newTaskData . prompt , "i" ) ,
215
+ } ) ;
216
+ } ) ;
217
+
218
+ await step ( "Does not render external auth" , async ( ) => {
219
+ expect (
220
+ canvas . queryByText ( / e x t e r n a l a u t h e n t i c a t i o n / ) ,
221
+ ) . not . toBeInTheDocument ( ) ;
222
+ } ) ;
223
+ } ,
224
+ } ;
225
+
226
+ export const MissingExternalAuth : Story = {
227
+ decorators : [ withProxyProvider ( ) ] ,
228
+ beforeEach : ( ) => {
229
+ spyOn ( data , "fetchTasks" )
230
+ . mockResolvedValueOnce ( MockTasks )
231
+ . mockResolvedValue ( [ newTaskData , ...MockTasks ] ) ;
232
+ spyOn ( data , "createTask" ) . mockResolvedValue ( newTaskData ) ;
233
+ spyOn ( API , "getTemplateVersionExternalAuth" ) . mockResolvedValue ( [
234
+ MockTemplateVersionExternalAuthGithub ,
235
+ ] ) ;
236
+ } ,
237
+ play : async ( { canvasElement, step } ) => {
238
+ const canvas = within ( canvasElement ) ;
239
+
240
+ await step ( "Submit is disabled" , async ( ) => {
241
+ const prompt = await canvas . findByLabelText ( / p r o m p t / i) ;
242
+ await userEvent . type ( prompt , newTaskData . prompt ) ;
243
+ const submitButton = canvas . getByRole ( "button" , { name : / r u n t a s k / i } ) ;
244
+ expect ( submitButton ) . toBeDisabled ( ) ;
245
+ } ) ;
246
+
247
+ await step ( "Renders external authentication" , async ( ) => {
248
+ await canvas . findByRole ( "button" , { name : / l o g i n w i t h g i t h u b / i } ) ;
249
+ } ) ;
250
+ } ,
251
+ } ;
252
+
253
+ export const ExternalAuthError : Story = {
254
+ decorators : [ withProxyProvider ( ) ] ,
255
+ beforeEach : ( ) => {
256
+ spyOn ( data , "fetchTasks" )
257
+ . mockResolvedValueOnce ( MockTasks )
258
+ . mockResolvedValue ( [ newTaskData , ...MockTasks ] ) ;
259
+ spyOn ( data , "createTask" ) . mockResolvedValue ( newTaskData ) ;
260
+ spyOn ( API , "getTemplateVersionExternalAuth" ) . mockRejectedValue (
261
+ mockApiError ( {
262
+ message : "Failed to load external auth" ,
263
+ } ) ,
264
+ ) ;
265
+ } ,
266
+ play : async ( { canvasElement, step } ) => {
267
+ const canvas = within ( canvasElement ) ;
268
+
269
+ await step ( "Submit is disabled" , async ( ) => {
270
+ const prompt = await canvas . findByLabelText ( / p r o m p t / i) ;
271
+ await userEvent . type ( prompt , newTaskData . prompt ) ;
272
+ const submitButton = canvas . getByRole ( "button" , { name : / r u n t a s k / i } ) ;
273
+ expect ( submitButton ) . toBeDisabled ( ) ;
274
+ } ) ;
275
+
276
+ await step ( "Renders error" , async ( ) => {
277
+ await canvas . findByText ( / f a i l e d t o l o a d e x t e r n a l a u t h / i) ;
278
+ } ) ;
279
+ } ,
280
+ } ;
281
+
176
282
export const NonAdmin : Story = {
177
283
decorators : [ withProxyProvider ( ) ] ,
178
284
parameters : {
0 commit comments