- Notifications
You must be signed in to change notification settings - Fork1k
feat: select template version for tasks#20146
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
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,296 @@ | ||
import { | ||
MockAIPromptPresets, | ||
MockNewTaskData, | ||
MockPresets, | ||
MockTask, | ||
MockTasks, | ||
MockTemplate, | ||
MockTemplateVersion, | ||
MockTemplateVersionExternalAuthGithub, | ||
MockTemplateVersionExternalAuthGithubAuthenticated, | ||
MockUserOwner, | ||
mockApiError, | ||
} from "testHelpers/entities"; | ||
import { withAuthProvider, withGlobalSnackbar } from "testHelpers/storybook"; | ||
import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
import { API } from "api/api"; | ||
import { expect, spyOn, userEvent, waitFor, within } from "storybook/test"; | ||
import type TasksPage from "../../../pages/TasksPage/TasksPage"; | ||
import { TaskPrompt } from "./TaskPrompt"; | ||
const meta: Meta<typeof TasksPage> = { | ||
title: "modules/tasks/TaskPrompt", | ||
component: TaskPrompt, | ||
decorators: [withAuthProvider], | ||
parameters: { | ||
user: MockUserOwner, | ||
permissions: { | ||
updateTemplates: true, | ||
}, | ||
}, | ||
beforeEach: () => { | ||
spyOn(API, "getTemplateVersionExternalAuth").mockResolvedValue([]); | ||
spyOn(API, "getTemplates").mockResolvedValue([ | ||
MockTemplate, | ||
{ | ||
...MockTemplate, | ||
id: "test-template-2", | ||
name: "template 2", | ||
display_name: "Template 2", | ||
}, | ||
]); | ||
spyOn(API, "getTemplateVersions").mockResolvedValue([ | ||
{ | ||
...MockTemplateVersion, | ||
name: "v1.0.0", | ||
}, | ||
]); | ||
spyOn(API, "getTemplateVersionPresets").mockResolvedValue(null); | ||
}, | ||
args: { | ||
templates: [MockTemplate], | ||
}, | ||
}; | ||
export default meta; | ||
type Story = StoryObj<typeof TasksPage>; | ||
export const LoadingTemplates: Story = { | ||
args: { | ||
templates: undefined, | ||
}, | ||
}; | ||
export const EmptyTemplates: Story = { | ||
args: { | ||
templates: [], | ||
}, | ||
}; | ||
export const WithPresets: Story = { | ||
beforeEach: () => { | ||
spyOn(API, "getTemplateVersionPresets").mockResolvedValue(MockPresets); | ||
}, | ||
}; | ||
export const ReadOnlyPresetPrompt: Story = { | ||
beforeEach: () => { | ||
spyOn(API, "getTemplateVersionPresets").mockResolvedValue( | ||
MockAIPromptPresets, | ||
); | ||
}, | ||
}; | ||
export const OnSuccess: Story = { | ||
decorators: [withGlobalSnackbar], | ||
parameters: { | ||
permissions: { | ||
updateTemplates: false, | ||
}, | ||
}, | ||
beforeEach: () => { | ||
const activeVersionId = `${MockTemplate.active_version_id}-latest`; | ||
spyOn(API, "getTemplate").mockResolvedValue({ | ||
...MockTemplate, | ||
active_version_id: activeVersionId, | ||
}); | ||
spyOn(API.experimental, "createTask").mockResolvedValue(MockTask); | ||
}, | ||
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); | ||
}); | ||
await step("Uses latest template version", () => { | ||
expect(API.experimental.createTask).toHaveBeenCalledWith( | ||
MockUserOwner.id, | ||
{ | ||
input: MockNewTaskData.prompt, | ||
template_version_id: `${MockTemplate.active_version_id}-latest`, | ||
template_version_preset_id: undefined, | ||
}, | ||
); | ||
}); | ||
await step("Displays success message", async () => { | ||
const body = within(canvasElement.ownerDocument.body); | ||
const successMessage = await body.findByText(/task created/i); | ||
expect(successMessage).toBeInTheDocument(); | ||
}); | ||
}, | ||
}; | ||
export const SelectTemplateVersion: Story = { | ||
decorators: [withGlobalSnackbar], | ||
beforeEach: () => { | ||
spyOn(API, "getTemplateVersions").mockResolvedValue([ | ||
{ | ||
...MockTemplateVersion, | ||
id: "test-template-version-2", | ||
name: "v2.0.0", | ||
}, | ||
{ | ||
...MockTemplateVersion, | ||
name: "v1.0.0", | ||
}, | ||
]); | ||
spyOn(API.experimental, "createTask").mockResolvedValue(MockTask); | ||
}, | ||
play: async ({ canvasElement, step }) => { | ||
const canvas = within(canvasElement); | ||
await step("Fill prompt", async () => { | ||
const prompt = await canvas.findByLabelText(/prompt/i); | ||
await userEvent.type(prompt, MockNewTaskData.prompt); | ||
}); | ||
await step("Select version", async () => { | ||
const body = within(canvasElement.ownerDocument.body); | ||
const versionSelect = await canvas.findByLabelText(/template version/i); | ||
await userEvent.click(versionSelect); | ||
const versionOption = await body.findByRole("option", { | ||
name: /v2.0.0/i, | ||
}); | ||
await userEvent.click(versionOption); | ||
}); | ||
await step("Submit form", async () => { | ||
const submitButton = canvas.getByRole("button", { name: /run task/i }); | ||
await waitFor(() => expect(submitButton).toBeEnabled()); | ||
await userEvent.click(submitButton); | ||
}); | ||
await step("Uses selected version", () => { | ||
expect(API.experimental.createTask).toHaveBeenCalledWith( | ||
MockUserOwner.id, | ||
{ | ||
input: MockNewTaskData.prompt, | ||
template_version_id: "test-template-version-2", | ||
template_version_preset_id: undefined, | ||
}, | ||
); | ||
}); | ||
await step("Displays success message", async () => { | ||
const body = within(canvasElement.ownerDocument.body); | ||
const successMessage = await body.findByText(/task created/i); | ||
expect(successMessage).toBeInTheDocument(); | ||
}); | ||
}, | ||
}; | ||
export const OnError: Story = { | ||
decorators: [withGlobalSnackbar], | ||
beforeEach: () => { | ||
spyOn(API, "getTemplates").mockResolvedValue([MockTemplate]); | ||
spyOn(API, "getTemplate").mockResolvedValue(MockTemplate); | ||
spyOn(API.experimental, "getTasks").mockResolvedValue(MockTasks); | ||
spyOn(API.experimental, "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 waitFor(() => expect(submitButton).toBeEnabled()); | ||
await userEvent.click(submitButton); | ||
}); | ||
await step("Verify error", async () => { | ||
await canvas.findByText(/failed to create task/i); | ||
}); | ||
}, | ||
}; | ||
export const AuthenticatedExternalAuth: Story = { | ||
beforeEach: () => { | ||
spyOn(API.experimental, "getTasks") | ||
.mockResolvedValueOnce(MockTasks) | ||
.mockResolvedValue([MockNewTaskData, ...MockTasks]); | ||
spyOn(API.experimental, "createTask").mockResolvedValue(MockTask); | ||
spyOn(API, "getTemplateVersionExternalAuth").mockResolvedValue([ | ||
MockTemplateVersionExternalAuthGithubAuthenticated, | ||
]); | ||
}, | ||
play: async ({ canvasElement, step }) => { | ||
const canvas = within(canvasElement); | ||
await step("Does not render external auth", async () => { | ||
expect( | ||
canvas.queryByText(/external authentication/), | ||
).not.toBeInTheDocument(); | ||
}); | ||
}, | ||
parameters: { | ||
chromatic: { | ||
disableSnapshot: true, | ||
}, | ||
}, | ||
}; | ||
export const MissingExternalAuth: Story = { | ||
beforeEach: () => { | ||
spyOn(API.experimental, "getTasks") | ||
.mockResolvedValueOnce(MockTasks) | ||
.mockResolvedValue([MockNewTaskData, ...MockTasks]); | ||
spyOn(API.experimental, "createTask").mockResolvedValue(MockTask); | ||
spyOn(API, "getTemplateVersionExternalAuth").mockResolvedValue([ | ||
MockTemplateVersionExternalAuthGithub, | ||
]); | ||
}, | ||
play: async ({ canvasElement, step }) => { | ||
const canvas = within(canvasElement); | ||
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(); | ||
}); | ||
await step("Renders external authentication", async () => { | ||
await canvas.findByRole("button", { name: /connect to github/i }); | ||
}); | ||
}, | ||
}; | ||
export const ExternalAuthError: Story = { | ||
beforeEach: () => { | ||
spyOn(API.experimental, "getTasks") | ||
.mockResolvedValueOnce(MockTasks) | ||
.mockResolvedValue([MockNewTaskData, ...MockTasks]); | ||
spyOn(API.experimental, "createTask").mockResolvedValue(MockTask); | ||
spyOn(API, "getTemplateVersionExternalAuth").mockRejectedValue( | ||
mockApiError({ | ||
message: "Failed to load external auth", | ||
}), | ||
); | ||
}, | ||
play: async ({ canvasElement, step }) => { | ||
const canvas = within(canvasElement); | ||
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(); | ||
}); | ||
await step("Renders error", async () => { | ||
await canvas.findByText(/failed to load external auth/i); | ||
}); | ||
}, | ||
}; |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.