mirror of
https://github.com/coder/coder.git
synced 2026-09-22 21:22:17 +08:00
test(site): convert TemplateVersionEditorPage tests from Jest to Vitest
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
52a848c65e
commit
99a4ecd62f
+16
-18
@@ -34,7 +34,7 @@ const { API } = apiModule;
|
|||||||
|
|
||||||
// For some reason this component in Jest is throwing a MUI style warning so,
|
// For some reason this component in Jest is throwing a MUI style warning so,
|
||||||
// since we don't need it for this test, we can mock it out
|
// since we don't need it for this test, we can mock it out
|
||||||
jest.mock(
|
vi.mock(
|
||||||
"modules/templates/TemplateResourcesTable/TemplateResourcesTable",
|
"modules/templates/TemplateResourcesTable/TemplateResourcesTable",
|
||||||
() => ({
|
() => ({
|
||||||
TemplateResourcesTable: () => <div></div>,
|
TemplateResourcesTable: () => <div></div>,
|
||||||
@@ -43,7 +43,7 @@ jest.mock(
|
|||||||
|
|
||||||
// Occasionally, Jest encounters HTML5 canvas errors. As the MonacoEditor is not
|
// Occasionally, Jest encounters HTML5 canvas errors. As the MonacoEditor is not
|
||||||
// required for these tests, we can safely mock it.
|
// required for these tests, we can safely mock it.
|
||||||
jest.mock("pages/TemplateVersionEditorPage/MonacoEditor", () => ({
|
vi.mock("pages/TemplateVersionEditorPage/MonacoEditor", () => ({
|
||||||
MonacoEditor: (props: MonacoEditorProps) => (
|
MonacoEditor: (props: MonacoEditorProps) => (
|
||||||
<textarea
|
<textarea
|
||||||
data-testid="monaco-editor"
|
data-testid="monaco-editor"
|
||||||
@@ -78,27 +78,25 @@ const buildTemplateVersion = async (
|
|||||||
user: UserEvent,
|
user: UserEvent,
|
||||||
topbar: HTMLElement,
|
topbar: HTMLElement,
|
||||||
) => {
|
) => {
|
||||||
jest.spyOn(API, "uploadFile").mockResolvedValueOnce({ hash: "hash" });
|
vi.spyOn(API, "uploadFile").mockResolvedValueOnce({ hash: "hash" });
|
||||||
jest.spyOn(API, "createTemplateVersion").mockResolvedValue({
|
vi.spyOn(API, "createTemplateVersion").mockResolvedValue({
|
||||||
...templateVersion,
|
...templateVersion,
|
||||||
job: {
|
job: {
|
||||||
...templateVersion.job,
|
...templateVersion.job,
|
||||||
status: "running",
|
status: "running",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
jest
|
vi.spyOn(API, "getTemplateVersionByName").mockResolvedValue(templateVersion);
|
||||||
.spyOn(API, "getTemplateVersionByName")
|
vi.spyOn(apiModule, "watchBuildLogsByTemplateVersionId").mockImplementation(
|
||||||
.mockResolvedValue(templateVersion);
|
(_, options) => {
|
||||||
jest
|
|
||||||
.spyOn(apiModule, "watchBuildLogsByTemplateVersionId")
|
|
||||||
.mockImplementation((_, options) => {
|
|
||||||
options.onMessage(MockWorkspaceBuildLogs[0]);
|
options.onMessage(MockWorkspaceBuildLogs[0]);
|
||||||
options.onDone?.();
|
options.onDone?.();
|
||||||
const wsMock = {
|
const wsMock = {
|
||||||
close: jest.fn(),
|
close: vi.fn(),
|
||||||
} as unknown;
|
} as unknown;
|
||||||
return wsMock as WebSocket;
|
return wsMock as WebSocket;
|
||||||
});
|
},
|
||||||
|
);
|
||||||
const buildButton = within(topbar).getByRole("button", {
|
const buildButton = within(topbar).getByRole("button", {
|
||||||
name: "Build",
|
name: "Build",
|
||||||
});
|
});
|
||||||
@@ -124,10 +122,10 @@ test("Use custom name, message and set it as active when publishing", async () =
|
|||||||
await buildTemplateVersion(newTemplateVersion, user, topbar);
|
await buildTemplateVersion(newTemplateVersion, user, topbar);
|
||||||
|
|
||||||
// Publish
|
// Publish
|
||||||
const patchTemplateVersion = jest
|
const patchTemplateVersion = vi
|
||||||
.spyOn(API, "patchTemplateVersion")
|
.spyOn(API, "patchTemplateVersion")
|
||||||
.mockResolvedValue(newTemplateVersion);
|
.mockResolvedValue(newTemplateVersion);
|
||||||
const updateActiveTemplateVersion = jest
|
const updateActiveTemplateVersion = vi
|
||||||
.spyOn(API, "updateActiveTemplateVersion")
|
.spyOn(API, "updateActiveTemplateVersion")
|
||||||
.mockResolvedValue({ message: "" });
|
.mockResolvedValue({ message: "" });
|
||||||
const publishButton = within(topbar).getByRole("button", {
|
const publishButton = within(topbar).getByRole("button", {
|
||||||
@@ -170,10 +168,10 @@ test("Do not mark as active if promote is not checked", async () => {
|
|||||||
await buildTemplateVersion(newTemplateVersion, user, topbar);
|
await buildTemplateVersion(newTemplateVersion, user, topbar);
|
||||||
|
|
||||||
// Publish
|
// Publish
|
||||||
const patchTemplateVersion = jest
|
const patchTemplateVersion = vi
|
||||||
.spyOn(API, "patchTemplateVersion")
|
.spyOn(API, "patchTemplateVersion")
|
||||||
.mockResolvedValue(newTemplateVersion);
|
.mockResolvedValue(newTemplateVersion);
|
||||||
const updateActiveTemplateVersion = jest
|
const updateActiveTemplateVersion = vi
|
||||||
.spyOn(API, "updateActiveTemplateVersion")
|
.spyOn(API, "updateActiveTemplateVersion")
|
||||||
.mockResolvedValue({ message: "" });
|
.mockResolvedValue({ message: "" });
|
||||||
const publishButton = within(topbar).getByRole("button", {
|
const publishButton = within(topbar).getByRole("button", {
|
||||||
@@ -215,7 +213,7 @@ test("Patch request is not send when there are no changes", async () => {
|
|||||||
await buildTemplateVersion(newTemplateVersion, user, topbar);
|
await buildTemplateVersion(newTemplateVersion, user, topbar);
|
||||||
|
|
||||||
// Publish
|
// Publish
|
||||||
const patchTemplateVersion = jest
|
const patchTemplateVersion = vi
|
||||||
.spyOn(API, "patchTemplateVersion")
|
.spyOn(API, "patchTemplateVersion")
|
||||||
.mockResolvedValue(newTemplateVersion);
|
.mockResolvedValue(newTemplateVersion);
|
||||||
const publishButton = within(topbar).getByRole("button", {
|
const publishButton = within(topbar).getByRole("button", {
|
||||||
@@ -333,7 +331,7 @@ describe.each([
|
|||||||
askForVariables,
|
askForVariables,
|
||||||
}) => {
|
}) => {
|
||||||
it(testName, async () => {
|
it(testName, async () => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
queryClient.setQueryData(
|
queryClient.setQueryData(
|
||||||
templateVersionVariablesKey(MockTemplateVersion.id),
|
templateVersionVariablesKey(MockTemplateVersion.id),
|
||||||
Reference in New Issue
Block a user