- Notifications
You must be signed in to change notification settings - Fork1k
feat: add preset selector in TasksPage#19012
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
a4ccb41
8cafbc9
071c896
9938038
ec3d72d
31901f9
c4dbd2f
72db7b6
4f2d820
7602ef6
80b96de
e248c14
bf6f113
b3916e2
0fd55e2
9da9f5d
2680111
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4,12 +4,14 @@ import { API } from "api/api"; | ||
import { MockUsers } from "pages/UsersPage/storybookData/users"; | ||
import { reactRouterParameters } from "storybook-addon-remix-react-router"; | ||
import { | ||
MockAIPromptPresets, | ||
MockNewTaskData, | ||
MockPresets, | ||
MockTasks, | ||
MockTemplate, | ||
MockTemplateVersionExternalAuthGithub, | ||
MockTemplateVersionExternalAuthGithubAuthenticated, | ||
MockUserOwner, | ||
mockApiError, | ||
} from "testHelpers/entities"; | ||
import { | ||
@@ -31,6 +33,7 @@ const meta: Meta<typeof TasksPage> = { | ||
}, | ||
beforeEach: () => { | ||
spyOn(API, "getTemplateVersionExternalAuth").mockResolvedValue([]); | ||
spyOn(API, "getTemplateVersionPresets").mockResolvedValue(null); | ||
spyOn(API, "getUsers").mockResolvedValue({ | ||
users: MockUsers, | ||
count: MockUsers.length, | ||
@@ -53,7 +56,7 @@ type Story = StoryObj<typeof TasksPage>; | ||
export const LoadingAITemplates: Story = { | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockImplementation( | ||
() => new Promise(() => 1000 * 60 * 60), | ||
); | ||
}, | ||
}; | ||
@@ -79,7 +82,7 @@ export const LoadingTasks: Story = { | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([MockTemplate]); | ||
spyOn(data, "fetchTasks").mockImplementation( | ||
() => new Promise(() => 1000 * 60 * 60), | ||
); | ||
}, | ||
play: async ({ canvasElement, step }) => { | ||
@@ -119,15 +122,77 @@ export const LoadedTasks: Story = { | ||
}, | ||
}; | ||
export const LoadedTasksWithPresets: Story = { | ||
decorators: [withProxyProvider()], | ||
beforeEach: () => { | ||
const mockTemplateWithPresets = { | ||
...MockTemplate, | ||
id: "test-template-2", | ||
name: "template-with-presets", | ||
display_name: "Template with Presets", | ||
}; | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([ | ||
MockTemplate, | ||
mockTemplateWithPresets, | ||
]); | ||
spyOn(data, "fetchTasks").mockResolvedValue(MockTasks); | ||
spyOn(API, "getTemplateVersionPresets").mockImplementation( | ||
async (versionId) => { | ||
// Return presets only for the second template | ||
if (versionId === mockTemplateWithPresets.active_version_id) { | ||
return MockPresets; | ||
} | ||
return null; | ||
}, | ||
); | ||
}, | ||
}; | ||
export const LoadedTasksWithAIPromptPresets: Story = { | ||
decorators: [withProxyProvider()], | ||
beforeEach: () => { | ||
const mockTemplateWithPresets = { | ||
...MockTemplate, | ||
id: "test-template-2", | ||
name: "template-with-presets", | ||
display_name: "Template with AI Prompt Presets", | ||
}; | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([ | ||
MockTemplate, | ||
mockTemplateWithPresets, | ||
]); | ||
spyOn(data, "fetchTasks").mockResolvedValue(MockTasks); | ||
spyOn(API, "getTemplateVersionPresets").mockImplementation( | ||
async (versionId) => { | ||
// Return presets only for the second template | ||
if (versionId === mockTemplateWithPresets.active_version_id) { | ||
return MockAIPromptPresets; | ||
} | ||
return null; | ||
}, | ||
); | ||
}, | ||
}; | ||
export const LoadedTasksEdgeCases: Story = { | ||
decorators: [withProxyProvider()], | ||
beforeEach: () => { | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([MockTemplate]); | ||
spyOn(data, "fetchTasks").mockResolvedValue(MockTasks); | ||
// Test various edge cases for presets | ||
spyOn(API, "getTemplateVersionPresets").mockImplementation(async () => { | ||
return [ | ||
{ | ||
ID: "malformed", | ||
Name: "Malformed Preset", | ||
Default: true, | ||
}, | ||
// biome-ignore lint/suspicious/noExplicitAny: Testing malformed data edge cases | ||
] as any; | ||
}); | ||
}, | ||
}; | ||
@@ -154,15 +219,15 @@ export const CreateTaskSuccessfully: Story = { | ||
spyOn(data, "fetchAITemplates").mockResolvedValue([MockTemplate]); | ||
spyOn(data, "fetchTasks") | ||
.mockResolvedValueOnce(MockTasks) | ||
.mockResolvedValue([MockNewTaskData, ...MockTasks]); | ||
spyOn(data, "createTask").mockResolvedValue(MockNewTaskData); | ||
}, | ||
play: async ({ canvasElement, step }) => { | ||
const canvas = within(canvasElement); | ||
await step("Run task", async () => { | ||
const prompt = await canvas.findByLabelText(/prompt/i); | ||
await userEvent.type(prompt,MockNewTaskData.prompt); | ||
const submitButton = canvas.getByRole("button", { name: /run task/i }); | ||
await waitFor(() => expect(submitButton).toBeEnabled()); | ||
await userEvent.click(submitButton); | ||
@@ -208,8 +273,8 @@ export const WithAuthenticatedExternalAuth: Story = { | ||
beforeEach: () => { | ||
spyOn(data, "fetchTasks") | ||
.mockResolvedValueOnce(MockTasks) | ||
.mockResolvedValue([MockNewTaskData, ...MockTasks]); | ||
spyOn(data, "createTask").mockResolvedValue(MockNewTaskData); | ||
spyOn(API, "getTemplateVersionExternalAuth").mockResolvedValue([ | ||
MockTemplateVersionExternalAuthGithubAuthenticated, | ||
]); | ||
@@ -235,8 +300,8 @@ export const MissingExternalAuth: Story = { | ||
beforeEach: () => { | ||
spyOn(data, "fetchTasks") | ||
.mockResolvedValueOnce(MockTasks) | ||
.mockResolvedValue([MockNewTaskData, ...MockTasks]); | ||
spyOn(data, "createTask").mockResolvedValue(MockNewTaskData); | ||
spyOn(API, "getTemplateVersionExternalAuth").mockResolvedValue([ | ||
MockTemplateVersionExternalAuthGithub, | ||
]); | ||
@@ -246,7 +311,7 @@ export const MissingExternalAuth: Story = { | ||
await step("Submit is disabled", async () => { | ||
const prompt = await canvas.findByLabelText(/prompt/i); | ||
await userEvent.type(prompt,MockNewTaskData.prompt); | ||
const submitButton = canvas.getByRole("button", { name: /run task/i }); | ||
expect(submitButton).toBeDisabled(); | ||
}); | ||
@@ -262,8 +327,8 @@ export const ExternalAuthError: Story = { | ||
beforeEach: () => { | ||
spyOn(data, "fetchTasks") | ||
.mockResolvedValueOnce(MockTasks) | ||
.mockResolvedValue([MockNewTaskData, ...MockTasks]); | ||
spyOn(data, "createTask").mockResolvedValue(MockNewTaskData); | ||
spyOn(API, "getTemplateVersionExternalAuth").mockRejectedValue( | ||
mockApiError({ | ||
message: "Failed to load external auth", | ||
@@ -275,7 +340,7 @@ export const ExternalAuthError: Story = { | ||
await step("Submit is disabled", async () => { | ||
const prompt = await canvas.findByLabelText(/prompt/i); | ||
await userEvent.type(prompt,MockNewTaskData.prompt); | ||
const submitButton = canvas.getByRole("button", { name: /run task/i }); | ||
expect(submitButton).toBeDisabled(); | ||
}); | ||
@@ -308,35 +373,3 @@ export const NonAdmin: Story = { | ||
}); | ||
}, | ||
}; | ||
Comment on lines -312 to -342 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. review: moved to |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.