-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI v2] feat: Adds deployment schedule cron tab (#17132)
- Loading branch information
1 parent
016fb00
commit cd03e6f
Showing
12 changed files
with
376 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
83 changes: 83 additions & 0 deletions
83
...s/deployments/deployment-schedules/deployment-schedule-dialog/cron-schedule-form.test.tsx
This file contains 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,83 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { beforeAll, describe, expect, it, vi } from "vitest"; | ||
|
||
import { Dialog } from "@/components/ui/dialog"; | ||
import { Toaster } from "@/components/ui/toaster"; | ||
import { createWrapper } from "@tests/utils"; | ||
import { mockPointerEvents } from "@tests/utils/browser"; | ||
import { | ||
CronScheduleForm, | ||
type CronScheduleFormProps, | ||
} from "./cron-schedule-form"; | ||
|
||
const CronScheduleFormTest = (props: CronScheduleFormProps) => ( | ||
<> | ||
<Toaster /> | ||
<Dialog> | ||
<CronScheduleForm {...props} /> | ||
</Dialog> | ||
</> | ||
); | ||
|
||
describe("CronScheduleForm", () => { | ||
beforeAll(mockPointerEvents); | ||
|
||
it("is able to create a new cron schedule", async () => { | ||
// Setup | ||
const user = userEvent.setup(); | ||
render(<CronScheduleFormTest deployment_id="0" onSubmit={vi.fn()} />, { | ||
wrapper: createWrapper(), | ||
}); | ||
|
||
// Test | ||
await user.click(screen.getByLabelText(/active/i)); | ||
await user.clear(screen.getByLabelText(/value/i)); | ||
await user.type(screen.getByLabelText(/value/i), "* * * * 1/2"); | ||
await user.click(screen.getByLabelText(/day or/i)); | ||
await user.click( | ||
screen.getByRole("combobox", { name: /select timezone/i }), | ||
); | ||
await user.click(screen.getByRole("option", { name: /africa \/ asmera/i })); | ||
await user.click(screen.getByRole("button", { name: /save/i })); | ||
|
||
screen.logTestingPlaygroundURL(); | ||
|
||
// ------------ Assert | ||
|
||
expect(screen.getByLabelText(/active/i)).not.toBeChecked(); | ||
expect(screen.getByLabelText(/value/i)).toHaveValue("* * * * 1/2"); | ||
expect(screen.getByLabelText(/day or/i)).not.toBeChecked(); | ||
}); | ||
|
||
it("is able to edit a new cron schedule", () => { | ||
// Setup | ||
const MOCK_SCHEDULE = { | ||
active: true, | ||
created: "0", | ||
deployment_id: "0", | ||
id: "123", | ||
updated: "0", | ||
schedule: { | ||
cron: "* * * * 1/2", | ||
day_or: true, | ||
timezone: '"Etc/UTC"', | ||
}, | ||
}; | ||
|
||
render( | ||
<CronScheduleFormTest | ||
deployment_id="0" | ||
onSubmit={vi.fn()} | ||
scheduleToEdit={MOCK_SCHEDULE} | ||
/>, | ||
{ wrapper: createWrapper() }, | ||
); | ||
|
||
// ------------ Assert | ||
|
||
expect(screen.getByLabelText(/active/i)).toBeChecked(); | ||
expect(screen.getByLabelText(/value/i)).toHaveValue("* * * * 1/2"); | ||
expect(screen.getByLabelText(/day or/i)).toBeChecked(); | ||
}); | ||
}); |
Oops, something went wrong.