Skip to content

Commit c3edba7

Browse files
committed
refactor: update how parameters for tests are defined
1 parent b1f6660 commit c3edba7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

site/src/pages/WorkspacePage/WorkspacePage.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { rest } from "msw";
66
import {
77
MockTemplate,
88
MockWorkspace,
9-
MockFailedWorkspace,
109
MockWorkspaceBuild,
1110
MockStoppedWorkspace,
1211
MockStartingWorkspace,
@@ -25,6 +24,7 @@ import { WorkspacePage } from "./WorkspacePage";
2524

2625
// It renders the workspace page and waits for it be loaded
2726
const renderWorkspacePage = async (workspace: Workspace) => {
27+
jest.spyOn(api, "getWorkspaceByOwnerAndName").mockResolvedValue(workspace);
2828
jest.spyOn(api, "getTemplate").mockResolvedValueOnce(MockTemplate);
2929
jest.spyOn(api, "getTemplateVersionRichParameters").mockResolvedValueOnce([]);
3030
jest
@@ -55,15 +55,14 @@ const renderWorkspacePage = async (workspace: Workspace) => {
5555
*/
5656
const testButton = async (
5757
workspace: Workspace,
58-
label: string,
58+
name: string | RegExp,
5959
actionMock: jest.SpyInstance,
6060
) => {
61-
const user = userEvent.setup();
6261
await renderWorkspacePage(workspace);
63-
6462
const workspaceActions = screen.getByTestId("workspace-actions");
65-
const button = within(workspaceActions).getByRole("button", { name: label });
63+
const button = within(workspaceActions).getByRole("button", { name });
6664

65+
const user = userEvent.setup();
6766
await user.click(button);
6867
expect(actionMock).toBeCalled();
6968
};

0 commit comments

Comments
 (0)