@@ -12,6 +12,7 @@ import { API } from "api/api";
1212import { MockUsers } from "pages/UsersPage/storybookData/users" ;
1313import { expect , spyOn , userEvent , waitFor , within } from "storybook/test" ;
1414import { getTemplatesQueryKey } from "../../api/queries/templates" ;
15+ import { usersKey } from "../../api/queries/users" ;
1516import TasksPage from "./TasksPage" ;
1617
1718const meta :Meta < typeof TasksPage > = {
@@ -23,23 +24,35 @@ const meta: Meta<typeof TasksPage> = {
2324permissions :{
2425viewDeploymentConfig :true ,
2526} ,
26- } ,
27- beforeEach :( ) => {
28- spyOn ( API , "getTemplateVersionExternalAuth" ) . mockResolvedValue ( [ ] ) ;
29- spyOn ( API , "getTemplateVersionPresets" ) . mockResolvedValue ( null ) ;
30- spyOn ( API , "getUsers" ) . mockResolvedValue ( {
31- users :MockUsers ,
32- count :MockUsers . length ,
33- } ) ;
34- spyOn ( API , "getTemplates" ) . mockResolvedValue ( [
35- MockTemplate ,
27+ queries :[
28+ {
29+ key :[ "template_version_external_auth" ] ,
30+ data :[ ] ,
31+ } ,
32+ {
33+ key :[ "template_version_presets" ] ,
34+ data :null ,
35+ } ,
36+ {
37+ key :usersKey ( { q :"" } ) ,
38+ data :{
39+ users :MockUsers ,
40+ count :MockUsers . length ,
41+ } ,
42+ } ,
3643{
37- ...MockTemplate ,
38- id :"test-template-2" ,
39- name :"template 2" ,
40- display_name :"Template 2" ,
44+ key :getTemplatesQueryKey ( { q :"has-ai-task:true" } ) ,
45+ data :[
46+ MockTemplate ,
47+ {
48+ ...MockTemplate ,
49+ id :"test-template-2" ,
50+ name :"template 2" ,
51+ display_name :"Template 2" ,
52+ } ,
53+ ] ,
4154} ,
42- ] ) ;
55+ ] ,
4356} ,
4457} ;
4558
@@ -81,8 +94,15 @@ export const LoadingTemplatesError: Story = {
8194} ;
8295
8396export const LoadingTasks :Story = {
97+ parameters :{
98+ queries :[
99+ {
100+ key :getTemplatesQueryKey ( { q :"has-ai-task:true" } ) ,
101+ data :[ MockTemplate ] ,
102+ } ,
103+ ] ,
104+ } ,
84105beforeEach :( ) => {
85- spyOn ( API , "getTemplates" ) . mockResolvedValue ( [ MockTemplate ] ) ;
86106spyOn ( API , "getTasks" ) . mockImplementation (
87107( ) => new Promise ( ( ) => 1000 * 60 * 60 ) ,
88108) ;
@@ -99,8 +119,15 @@ export const LoadingTasks: Story = {
99119} ;
100120
101121export const LoadingTasksError :Story = {
122+ parameters :{
123+ queries :[
124+ {
125+ key :getTemplatesQueryKey ( { q :"has-ai-task:true" } ) ,
126+ data :[ MockTemplate ] ,
127+ } ,
128+ ] ,
129+ } ,
102130beforeEach :( ) => {
103- spyOn ( API , "getTemplates" ) . mockResolvedValue ( [ MockTemplate ] ) ;
104131spyOn ( API , "getTasks" ) . mockRejectedValue (
105132mockApiError ( {
106133message :"Failed to load tasks" ,
@@ -110,16 +137,32 @@ export const LoadingTasksError: Story = {
110137} ;
111138
112139export const EmptyTasks :Story = {
113- beforeEach :( ) => {
114- spyOn ( API , "getTemplates" ) . mockResolvedValue ( [ MockTemplate ] ) ;
115- spyOn ( API , "getTasks" ) . mockResolvedValue ( [ ] ) ;
140+ parameters :{
141+ queries :[
142+ {
143+ key :getTemplatesQueryKey ( { q :"has-ai-task:true" } ) ,
144+ data :[ MockTemplate ] ,
145+ } ,
146+ {
147+ key :[ "tasks" , { owner :MockUserOwner . username } ] ,
148+ data :[ ] ,
149+ } ,
150+ ] ,
116151} ,
117152} ;
118153
119154export const LoadedTasks :Story = {
120- beforeEach :( ) => {
121- spyOn ( API , "getTemplates" ) . mockResolvedValue ( [ MockTemplate ] ) ;
122- spyOn ( API , "getTasks" ) . mockResolvedValue ( MockTasks ) ;
155+ parameters :{
156+ queries :[
157+ {
158+ key :getTemplatesQueryKey ( { q :"has-ai-task:true" } ) ,
159+ data :[ MockTemplate ] ,
160+ } ,
161+ {
162+ key :[ "tasks" , { owner :MockUserOwner . username } ] ,
163+ data :MockTasks ,
164+ } ,
165+ ] ,
123166} ,
124167} ;
125168
@@ -139,42 +182,52 @@ export const DisplayName: Story = {
139182} ;
140183
141184export const LoadedTasksWaitingForInputTab :Story = {
142- beforeEach :( ) => {
143- const [ firstTask , ...otherTasks ] = MockTasks ;
144- spyOn ( API , "getTemplates" ) . mockResolvedValue ( [ MockTemplate ] ) ;
145- spyOn ( API , "getTasks" ) . mockResolvedValue ( [
146- {
147- ...firstTask ,
148- id :"active-idle-task" ,
149- display_name :"Active Idle Task" ,
150- status :"active" ,
151- current_state :{
152- ...firstTask . current_state ,
153- state :"idle" ,
154- } ,
155- } ,
185+ parameters :{
186+ queries :[
156187{
157- ...firstTask ,
158- id :"paused-idle-task" ,
159- display_name :"Paused Idle Task" ,
160- status :"paused" ,
161- current_state :{
162- ...firstTask . current_state ,
163- state :"idle" ,
164- } ,
188+ key :getTemplatesQueryKey ( { q :"has-ai-task:true" } ) ,
189+ data :[ MockTemplate ] ,
165190} ,
166191{
167- ...firstTask ,
168- id :"error-idle-task" ,
169- display_name :"Error Idle Task" ,
170- status :"error" ,
171- current_state :{
172- ...firstTask . current_state ,
173- state :"idle" ,
174- } ,
192+ key :[ "tasks" , { owner :MockUserOwner . username } ] ,
193+ data :( ( ) => {
194+ const [ firstTask , ...otherTasks ] = MockTasks ;
195+ return [
196+ {
197+ ...firstTask ,
198+ id :"active-idle-task" ,
199+ display_name :"Active Idle Task" ,
200+ status :"active" ,
201+ current_state :{
202+ ...firstTask . current_state ,
203+ state :"idle" ,
204+ } ,
205+ } ,
206+ {
207+ ...firstTask ,
208+ id :"paused-idle-task" ,
209+ display_name :"Paused Idle Task" ,
210+ status :"paused" ,
211+ current_state :{
212+ ...firstTask . current_state ,
213+ state :"idle" ,
214+ } ,
215+ } ,
216+ {
217+ ...firstTask ,
218+ id :"error-idle-task" ,
219+ display_name :"Error Idle Task" ,
220+ status :"error" ,
221+ current_state :{
222+ ...firstTask . current_state ,
223+ state :"idle" ,
224+ } ,
225+ } ,
226+ ...otherTasks ,
227+ ] ;
228+ } ) ( ) ,
175229} ,
176- ...otherTasks ,
177- ] ) ;
230+ ] ,
178231} ,
179232play :async ( { canvasElement, step} ) => {
180233const canvas = within ( canvasElement ) ;
@@ -210,10 +263,16 @@ export const NonAdmin: Story = {
210263permissions :{
211264viewDeploymentConfig :false ,
212265} ,
213- } ,
214- beforeEach :( ) => {
215- spyOn ( API , "getTemplates" ) . mockResolvedValue ( [ MockTemplate ] ) ;
216- spyOn ( API , "getTasks" ) . mockResolvedValue ( MockTasks ) ;
266+ queries :[
267+ {
268+ key :getTemplatesQueryKey ( { q :"has-ai-task:true" } ) ,
269+ data :[ MockTemplate ] ,
270+ } ,
271+ {
272+ key :[ "tasks" , { owner :MockUserOwner . username } ] ,
273+ data :MockTasks ,
274+ } ,
275+ ] ,
217276} ,
218277play :async ( { canvasElement, step} ) => {
219278const canvas = within ( canvasElement ) ;
@@ -228,9 +287,17 @@ export const NonAdmin: Story = {
228287} ;
229288
230289export const OpenDeleteDialog :Story = {
231- beforeEach :( ) => {
232- spyOn ( API , "getTemplates" ) . mockResolvedValue ( [ MockTemplate ] ) ;
233- spyOn ( API , "getTasks" ) . mockResolvedValue ( MockTasks ) ;
290+ parameters :{
291+ queries :[
292+ {
293+ key :getTemplatesQueryKey ( { q :"has-ai-task:true" } ) ,
294+ data :[ MockTemplate ] ,
295+ } ,
296+ {
297+ key :[ "tasks" , { owner :MockUserOwner . username } ] ,
298+ data :MockTasks ,
299+ } ,
300+ ] ,
234301} ,
235302play :async ( { canvasElement} ) => {
236303const canvas = within ( canvasElement ) ;