Skip to content

fix(site): retry and debug passing build parameters options #12384

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for retry with build parameters
  • Loading branch information
BrunoQuaresma committed Mar 1, 2024
commit a9e122f34c506fff276ac451b58e6f65def68f3e
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ import {
usePopover,
} from "components/Popover/Popover";
import { TopbarButton } from "components/FullPageLayout/Topbar";
import visuallyHidden from "@mui/utils/visuallyHidden";

interface BuildParametersPopoverProps {
workspace: Workspace;
disabled?: boolean;
onSubmit: (buildParameters: WorkspaceBuildParameter[]) => void;
label: string;
}

export const BuildParametersPopover: FC<BuildParametersPopoverProps> = ({
workspace,
disabled,
label,
onSubmit,
}) => {
const { data: parameters } = useQuery({
Expand All @@ -62,6 +65,7 @@ export const BuildParametersPopover: FC<BuildParametersPopoverProps> = ({
css={{ paddingLeft: 0, paddingRight: 0, minWidth: "28px !important" }}
>
<ExpandMoreOutlined css={{ fontSize: 14 }} />
<span css={{ ...visuallyHidden }}>{label}</span>
</TopbarButton>
</PopoverTrigger>
<PopoverContent
Expand Down
2 changes: 2 additions & 0 deletions site/src/pages/WorkspacePage/WorkspaceActions/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const StartButton: FC<ActionButtonPropsWithWorkspace> = ({
{loading ? <>Starting&hellip;</> : "Start"}
</TopbarButton>
<BuildParametersPopover
label="Start with build parameters"
workspace={workspace}
disabled={loading}
onSubmit={handleAction}
Expand Down Expand Up @@ -139,6 +140,7 @@ export const RestartButton: FC<ActionButtonPropsWithWorkspace> = ({
{loading ? <>Restarting&hellip;</> : <>Restart&hellip;</>}
</TopbarButton>
<BuildParametersPopover
label="Restart with build parameters"
workspace={workspace}
disabled={loading}
onSubmit={handleAction}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export const DebugButton: FC<DebugButtonProps> = ({
}}
>
{mainAction}
<BuildParametersPopover workspace={workspace} onSubmit={handleAction} />
<BuildParametersPopover
label="Debug with build parameters"
workspace={workspace}
onSubmit={handleAction}
/>
</ButtonGroup>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export const RetryButton: FC<RetryButtonProps> = ({
}}
>
{mainAction}
<BuildParametersPopover workspace={workspace} onSubmit={handleAction} />
<BuildParametersPopover
label="Retry with build parameters"
workspace={workspace}
onSubmit={handleAction}
/>
</ButtonGroup>
);
};
52 changes: 51 additions & 1 deletion site/src/pages/WorkspacePage/WorkspacePage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Workspace } from "api/typesGenerated";
import { TemplateVersionParameter, type Workspace } from "api/typesGenerated";
import { screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import EventSourceMock from "eventsourcemock";
Expand All @@ -21,6 +21,7 @@ import * as api from "api/api";
import { renderWithAuth } from "testHelpers/renderHelpers";
import { server } from "testHelpers/server";
import { WorkspacePage } from "./WorkspacePage";
import { satisfies } from "semver";

// Renders the workspace page and waits for it be loaded
const renderWorkspacePage = async (workspace: Workspace) => {
Expand Down Expand Up @@ -438,4 +439,53 @@ describe("WorkspacePage", () => {
});
});
});

it.only("retry with build parameters", async () => {
const user = userEvent.setup();
const workspace = {
...MockFailedWorkspace,
latest_build: {
...MockFailedWorkspace.latest_build,
transition: "start",
},
} satisfies Workspace;
const parameter = {
...MockTemplateVersionParameter1,
display_name: "Parameter 1",
ephemeral: true,
} satisfies TemplateVersionParameter;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to use satisifes here and above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When typing the variable directly it was missing a few attribute types after destructuring so using satisfies fixed that.


server.use(
rest.get(
"/api/v2/templateversions/:versionId/rich-parameters",
(req, res, ctx) => {
return res(ctx.status(200), ctx.json([parameter]));
},
),
);
const startWorkspaceSpy = jest.spyOn(api, "startWorkspace");

await renderWorkspacePage(workspace);
const retryWithBuildParametersButton = await screen.findByRole("button", {
name: "Retry with build parameters",
});
await user.click(retryWithBuildParametersButton);
await screen.findByText("Build Options");
const parameterField = screen.getByLabelText(parameter.display_name, {
exact: false,
});
await user.clear(parameterField);
await user.type(parameterField, "some-value");
const submitButton = screen.getByText("Build workspace");
await user.click(submitButton);

await waitFor(() => {
expect(startWorkspaceSpy).toBeCalledWith(
workspace.id,
workspace.latest_build.template_version_id,
undefined,
[{ name: parameter.name, value: "some-value" }],
);
});
});
});