- Notifications
You must be signed in to change notification settings - Fork906
feat: add AI Tasks page#18047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
feat: add AI Tasks page#18047
Changes fromall commits
3a5fc9a
01c8268
202cc38
4242c92
455a618
63fe240
2c2d624
0d543d8
5ce5b3e
e706e61
e09dae6
1f109fe
0a1b4d6
156c9d1
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { expect, spyOn, userEvent, within } from "@storybook/test"; | ||
import { | ||
MockTemplate, | ||
MockUserOwner, | ||
MockWorkspace, | ||
MockWorkspaceAppStatus, | ||
mockApiError, | ||
} from "testHelpers/entities"; | ||
import { | ||
withAuthProvider, | ||
withGlobalSnackbar, | ||
withProxyProvider, | ||
} from "testHelpers/storybook"; | ||
import TasksPage, { data } from "./TasksPage"; | ||
const meta: Meta<typeof TasksPage> = { | ||
title: "pages/TasksPage", | ||
component: TasksPage, | ||
decorators: [withAuthProvider], | ||
parameters: { | ||
user: MockUserOwner, | ||
}, | ||
}; | ||
export default meta; | ||
type Story = StoryObj<typeof TasksPage>; | ||
export const LoadingAITemplates: Story = { | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockImplementation( | ||
() => new Promise((res) => 1000 * 60 * 60), | ||
); | ||
}, | ||
}; | ||
export const LoadingAITemplatesError: Story = { | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockRejectedValue( | ||
mockApiError({ | ||
message: "Failed to load AI templates", | ||
detail: "You don't have permission to access this resource.", | ||
}), | ||
); | ||
}, | ||
}; | ||
export const EmptyAITemplates: Story = { | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([]); | ||
}, | ||
}; | ||
export const LoadingTasks: Story = { | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([MockTemplate]); | ||
spyOn(data, "fetchTasks").mockImplementation( | ||
() => new Promise((res) => 1000 * 60 * 60), | ||
); | ||
}, | ||
play: async ({ canvasElement, step }) => { | ||
const canvas = within(canvasElement); | ||
await step("Select the first AI template", async () => { | ||
const combobox = await canvas.findByRole("combobox"); | ||
expect(combobox).toHaveTextContent(MockTemplate.display_name); | ||
}); | ||
}, | ||
}; | ||
export const LoadingTasksError: Story = { | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([MockTemplate]); | ||
spyOn(data, "fetchTasks").mockRejectedValue( | ||
mockApiError({ | ||
message: "Failed to load tasks", | ||
}), | ||
); | ||
}, | ||
}; | ||
export const EmptyTasks: Story = { | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([MockTemplate]); | ||
spyOn(data, "fetchTasks").mockResolvedValue([]); | ||
}, | ||
}; | ||
export const LoadedTasks: Story = { | ||
decorators: [withProxyProvider()], | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([MockTemplate]); | ||
spyOn(data, "fetchTasks").mockResolvedValue(MockTasks); | ||
}, | ||
}; | ||
export const CreateTaskSuccessfully: Story = { | ||
decorators: [withProxyProvider()], | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([MockTemplate]); | ||
spyOn(data, "fetchTasks").mockResolvedValue(MockTasks); | ||
spyOn(data, "createTask").mockImplementation((prompt: string) => { | ||
return Promise.resolve({ | ||
prompt, | ||
workspace: { | ||
...MockWorkspace, | ||
latest_app_status: { | ||
...MockWorkspaceAppStatus, | ||
message: "Task created successfully!", | ||
}, | ||
}, | ||
}); | ||
}); | ||
}, | ||
play: async ({ canvasElement, step }) => { | ||
const canvas = within(canvasElement); | ||
await step("Run task", async () => { | ||
const prompt = await canvas.findByLabelText(/prompt/i); | ||
await userEvent.type(prompt, "Create a new task"); | ||
const submitButton = canvas.getByRole("button", { name: /run task/i }); | ||
await userEvent.click(submitButton); | ||
}); | ||
await step("Verify task in the table", async () => { | ||
await canvas.findByRole("row", { | ||
name: /create a new task/i, | ||
}); | ||
}); | ||
}, | ||
}; | ||
export const CreateTaskError: Story = { | ||
decorators: [withProxyProvider(), withGlobalSnackbar], | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([MockTemplate]); | ||
spyOn(data, "fetchTasks").mockResolvedValue(MockTasks); | ||
spyOn(data, "createTask").mockRejectedValue( | ||
mockApiError({ | ||
message: "Failed to create task", | ||
detail: "You don't have permission to create tasks.", | ||
}), | ||
); | ||
}, | ||
play: async ({ canvasElement, step }) => { | ||
const canvas = within(canvasElement); | ||
await step("Run task", async () => { | ||
const prompt = await canvas.findByLabelText(/prompt/i); | ||
await userEvent.type(prompt, "Create a new task"); | ||
const submitButton = canvas.getByRole("button", { name: /run task/i }); | ||
await userEvent.click(submitButton); | ||
}); | ||
await step("Verify error", async () => { | ||
await canvas.findByText(/failed to create task/i); | ||
}); | ||
}, | ||
}; | ||
const MockTasks = [ | ||
{ | ||
workspace: { | ||
...MockWorkspace, | ||
latest_app_status: MockWorkspaceAppStatus, | ||
}, | ||
prompt: "Create competitors page", | ||
}, | ||
{ | ||
workspace: { | ||
...MockWorkspace, | ||
id: "workspace-2", | ||
latest_app_status: { | ||
...MockWorkspaceAppStatus, | ||
message: "Avatar size fixed!", | ||
}, | ||
}, | ||
prompt: "Fix user avatar size", | ||
}, | ||
{ | ||
workspace: { | ||
...MockWorkspace, | ||
id: "workspace-3", | ||
latest_app_status: { | ||
...MockWorkspaceAppStatus, | ||
message: "Accessibility issues fixed!", | ||
}, | ||
}, | ||
prompt: "Fix accessibility issues", | ||
}, | ||
]; |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.