8000 chore: patch known bugs in stable by stirby · Pull Request #14925 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore: patch known bugs in stable #14925

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 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 9 additions & 10 deletions codersdk/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/require"

"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/codersdk"
)

Expand Down Expand Up @@ -109,9 +108,9 @@ func TestCreateUserRequestJSON(t *testing.T) {
t.Parallel()

req := codersdk.CreateUserRequestWithOrgs{
Email: coderdtest.RandomName(t),
Username: coderdtest.RandomName(t),
Name: coderdtest.RandomName(t),
Email: "alice@coder.com",
Username: "alice",
Name: "Alice User",
Password: "",
UserLoginType: codersdk.LoginTypePassword,
OrganizationIDs: []uuid.UUID{uuid.New(), uuid.New()},
Expand All @@ -123,9 +122,9 @@ func TestCreateUserRequestJSON(t *testing.T) {
t.Parallel()

req := codersdk.CreateUserRequestWithOrgs{
Email: coderdtest.RandomName(t),
Username: coderdtest.RandomName(t),
Name: coderdtest.RandomName(t),
Email: "alice@coder.com",
Username: "alice",
Name: "Alice User",
Password: "",
UserLoginType: codersdk.LoginTypePassword,
OrganizationIDs: []uuid.UUID{uuid.New()},
Expand All @@ -137,9 +136,9 @@ func TestCreateUserRequestJSON(t *testing.T) {
t.Parallel()

req := codersdk.CreateUserRequestWithOrgs{
Email: coderdtest.RandomName(t),
Username: coderdtest.RandomName(t),
Name: coderdtest.RandomName(t),
Email: "alice@coder.com",
Username: "alice",
Name: "Alice User",
Password: "",
UserLoginType: codersdk.LoginTypePassword,
OrganizationIDs: []uuid.UUID{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ export const WorkspaceParametersForm: FC<WorkspaceParameterFormProps> = ({
<FormFooter
onCancel={onCancel}
isLoading={isSubmitting}
submitDisabled={disabled}
submitLabel="Submit and restart"
submitDisabled={disabled || !form.dirty}
/>
</HorizontalForm>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ test("Submit the workspace settings page successfully", async () => {
);
await user.clear(parameter2);
await user.type(parameter2, "1");
await user.click(within(form).getByRole("button", { name: "Submit" }));
await user.click(
within(form).getByRole("button", { name: "Submit and restart" }),
);
// Assert that the API calls were made with the correct data
await waitFor(() => {
expect(postWorkspaceBuildSpy).toHaveBeenCalledWith(MockWorkspace.id, {
Expand All @@ -73,3 +75,58 @@ test("Submit the workspace settings page successfully", async () => {
});
});
});

test("Submit button is only enabled when changes are made", async () => {
// Mock the API calls that loads data
jest
.spyOn(API, "getWorkspaceByOwnerAndName")
.mockResolvedValueOnce(MockWorkspace);
jest.spyOn(API, "getTemplateVersionRichParameters").mockResolvedValueOnce([
MockTemplateVersionParameter1,
MockTemplateVersionParameter2,
// Immutable parameters
MockTemplateVersionParameter4,
]);
jest.spyOn(API, "getWorkspaceBuildParameters").mockResolvedValueOnce([
MockWorkspaceBuildParameter1,
MockWorkspaceBuildParameter2,
// Immutable value
MockWorkspaceBuildParameter4,
]);
// Setup event and rendering
const user = userEvent.setup();
renderWithWorkspaceSettingsLayout(<WorkspaceParametersPage />, {
route: "/@test-user/test-workspace/settings",
path: "/:username/:workspace/settings",
// Need this because after submit the user is redirected
extraRoutes: [{ path: "/:username/:workspace", element: <div /> }],
});
await waitForLoaderToBeRemoved();

const submitButton: HTMLButtonElement = screen.getByRole("button", {
name: "Submit and restart",
});

const form = screen.getByTestId("form");
const parameter1 = within(form).getByLabelText(
MockWorkspaceBuildParameter1.name,
{ exact: false },
);

// There are no changes, the button should be disabled.
expect(submitButton.disabled).toBeTruthy();

// Make changes to the form
await user.clear(parameter1);
await user.type(parameter1, "new-value");

// There are now changes, the button should be enabled.
expect(submitButton.disabled).toBeFalsy();

// Change form value back to default
await user.clear(parameter1);
await user.type(parameter1, MockWorkspaceBuildParameter1.value);

// There are now no changes, the button should be disabled.
expect(submitButton.disabled).toBeTruthy();
});
2 changes: 1 addition & 1 deletion site/src/utils/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function defaultDocsUrl(): string {
}

// Strip the postfix version info that's not part of the link.
const i = version?.indexOf("-") ?? -1;
const i = version?.match(/[+-]/)?.index ?? -1;
if (i >= 0) {
version = version.slice(0, i);
}
Expand Down
Loading
0