Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion site/src/pages/TasksPage/TasksPage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { withAuthProvider, withProxyProvider } from "testHelpers/storybook";
import type { Meta, StoryObj } from "@storybook/react-vite";
import { API } from "api/api";
import { MockUsers } from "pages/UsersPage/storybookData/users";
import { expect, spyOn, userEvent, within } from "storybook/test";
import { expect, spyOn, userEvent, waitFor, within } from "storybook/test";
import { getTemplatesQueryKey } from "../../api/queries/templates";
import TasksPage from "./TasksPage";

Expand Down Expand Up @@ -145,6 +145,29 @@ export const LoadedTasksWaitingForInputTab: Story = {
spyOn(API, "getTasks").mockResolvedValue([
{
...firstTask,
id: "active-idle-task",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, the preferred method for these GET endpoints mocks is something like:

parameters: {
		queries: [
			{
				key: ["tasks", { owner: MockUserOwner.username }],
				data: [
					{
						...firstTask,
						id: "active-idle-task",
						display_name: "Active Idle Task",
						status: "active",
						current_state: {
							...firstTask.current_state,
							state: "idle",
						},
					},
					...
				],
			},
			{
				key: getTemplatesQueryKey({ q: "has-ai-task:true" }),
				data: [MockTemplate],
			},
		],
	},

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe most of this file should be converted, doesn't feel appropriate to do it in this PR, or to introduce mixed usage. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I think we already have mixed usages in a lot of files, as this is something that I was already called out on in other PRs as well, and I only updated the stories I was changing 😞 I'm ok with addressing this in a separate PR 👍

display_name: "Active Idle Task",
status: "active",
current_state: {
...firstTask.current_state,
state: "idle",
},
},
{
...firstTask,
id: "paused-idle-task",
display_name: "Paused Idle Task",
status: "paused",
current_state: {
...firstTask.current_state,
state: "idle",
},
},
{
...firstTask,
id: "error-idle-task",
display_name: "Error Idle Task",
status: "error",
current_state: {
...firstTask.current_state,
state: "idle",
Expand All @@ -161,6 +184,23 @@ export const LoadedTasksWaitingForInputTab: Story = {
name: /waiting for input/i,
});
await userEvent.click(waitingForInputTab);

// Wait for the table to update after tab switch
await waitFor(async () => {
const table = canvas.getByRole("table");
const tableContent = within(table);

// Active idle task should be visible
expect(tableContent.getByText("Active Idle Task")).toBeInTheDocument();

// Only active idle tasks should be visible in the table
expect(
tableContent.queryByText("Paused Idle Task"),
).not.toBeInTheDocument();
expect(
tableContent.queryByText("Error Idle Task"),
).not.toBeInTheDocument();
});
});
},
};
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/TasksPage/TasksPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const TasksPage: FC = () => {
refetchInterval: 10_000,
});
const idleTasks = tasksQuery.data?.filter(
(task) => task.current_state?.state === "idle",
(task) => task.status === "active" && task.current_state?.state === "idle",
);
const displayedTasks =
tab.value === "waiting-for-input" ? idleTasks : tasksQuery.data;
Expand Down
Loading