Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit59c7e72

Browse files
committed
fix: replace spyOn with queries parameter in TasksPage stories
Replace all spyOn usage with the preferred queries parameter approachfor GET endpoint mocks in TasksPage.stories.tsx.---🤖 This change was written by Claude Sonnet 4.5 Thinking using mux and reviewed by a human 🏂
1 parentb7d8918 commit59c7e72

File tree

1 file changed

+129
-62
lines changed

1 file changed

+129
-62
lines changed

‎site/src/pages/TasksPage/TasksPage.stories.tsx‎

Lines changed: 129 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { API } from "api/api";
1212
import{MockUsers}from"pages/UsersPage/storybookData/users";
1313
import{expect,spyOn,userEvent,waitFor,within}from"storybook/test";
1414
import{getTemplatesQueryKey}from"../../api/queries/templates";
15+
import{usersKey}from"../../api/queries/users";
1516
importTasksPagefrom"./TasksPage";
1617

1718
constmeta:Meta<typeofTasksPage>={
@@ -23,23 +24,35 @@ const meta: Meta<typeof TasksPage> = {
2324
permissions:{
2425
viewDeploymentConfig: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

8396
exportconstLoadingTasks:Story={
97+
parameters:{
98+
queries:[
99+
{
100+
key:getTemplatesQueryKey({q:"has-ai-task:true"}),
101+
data:[MockTemplate],
102+
},
103+
],
104+
},
84105
beforeEach:()=>{
85-
spyOn(API,"getTemplates").mockResolvedValue([MockTemplate]);
86106
spyOn(API,"getTasks").mockImplementation(
87107
()=>newPromise(()=>1000*60*60),
88108
);
@@ -99,8 +119,15 @@ export const LoadingTasks: Story = {
99119
};
100120

101121
exportconstLoadingTasksError:Story={
122+
parameters:{
123+
queries:[
124+
{
125+
key:getTemplatesQueryKey({q:"has-ai-task:true"}),
126+
data:[MockTemplate],
127+
},
128+
],
129+
},
102130
beforeEach:()=>{
103-
spyOn(API,"getTemplates").mockResolvedValue([MockTemplate]);
104131
spyOn(API,"getTasks").mockRejectedValue(
105132
mockApiError({
106133
message:"Failed to load tasks",
@@ -110,16 +137,32 @@ export const LoadingTasksError: Story = {
110137
};
111138

112139
exportconstEmptyTasks: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

119154
exportconstLoadedTasks: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

141184
exportconstLoadedTasksWaitingForInputTab: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
},
179232
play:async({ canvasElement, step})=>{
180233
constcanvas=within(canvasElement);
@@ -210,10 +263,16 @@ export const NonAdmin: Story = {
210263
permissions:{
211264
viewDeploymentConfig: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
},
218277
play:async({ canvasElement, step})=>{
219278
constcanvas=within(canvasElement);
@@ -228,9 +287,17 @@ export const NonAdmin: Story = {
228287
};
229288

230289
exportconstOpenDeleteDialog: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
},
235302
play:async({ canvasElement})=>{
236303
constcanvas=within(canvasElement);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp