Diff comments:
> diff --git a/frontend/src/components/TokensCreate/TokensCreate.test.tsx
> b/frontend/src/components/TokensCreate/TokensCreate.test.tsx
> index 2519f7f..4665b36 100644
> --- a/frontend/src/components/TokensCreate/TokensCreate.test.tsx
> +++ b/frontend/src/components/TokensCreate/TokensCreate.test.tsx
> @@ -29,46 +29,54 @@ afterAll(() => {
> mockServer.close();
> });
>
> -describe("TokensCreate", () => {
> - it("renders the form", async () => {
> - renderWithMemoryRouter(<TokensCreate />);
> - expect(screen.getByRole("form", { name: /Generate new enrolment tokens/i
> })).toBeInTheDocument();
> - });
> +it("renders the form", async () => {
> + renderWithMemoryRouter(<TokensCreate />);
> + expect(screen.getByRole("form", { name: /Generate new enrolment tokens/i
> })).toBeInTheDocument();
> +});
>
> - it("if not all required fields have been entered the submit button is
> disabled", async () => {
> - renderWithMemoryRouter(<TokensCreate />);
> - const amount = screen.getByLabelText(/Amount of tokens to generate/i);
> - const expires = screen.getByLabelText(/Expiration time/i);
> - expect(screen.getByRole("button", { name: /Generate tokens/i
> })).toBeDisabled();
> - await userEvent.type(amount, "1");
> - await userEvent.type(expires, "1 month");
> - expect(screen.getByRole("button", { name: /Generate tokens/i
> })).toBeEnabled();
> - });
> +it("if not all required fields have been entered the submit button is
> disabled", async () => {
> + renderWithMemoryRouter(<TokensCreate />);
> + const amount = screen.getByLabelText(/Amount of tokens to generate/i);
> + const expires = screen.getByLabelText(/Expiration time/i);
> + expect(screen.getByRole("button", { name: /Generate tokens/i
> })).toBeDisabled();
> + await userEvent.type(amount, "1");
> + await userEvent.type(expires, "1 month");
> + expect(screen.getByRole("button", { name: /Generate tokens/i
> })).toBeEnabled();
> +});
>
> - it("displays an error for invalid expiration value", async () => {
> - renderWithMemoryRouter(<TokensCreate />);
> - const expires = screen.getByLabelText(/Expiration time/i);
> - await userEvent.type(expires, "2");
> - await userEvent.tab();
> - expect(expires).toHaveErrorMessage(
> - /Time unit must be a `string` type with a value of weeks, days, hours,
> and\/or minutes./i,
> - );
> - });
> +it("displays an error for invalid expiration value", async () => {
> + renderWithMemoryRouter(<TokensCreate />);
> + const expires = screen.getByLabelText(/Expiration time/i);
> + await userEvent.type(expires, "2");
> + await userEvent.tab();
> + expect(expires).toHaveErrorMessage(
> + /Time unit must be a `string` type with a value of weeks, days, hours,
> and\/or minutes./i,
> + );
> +});
>
> - it("can generate enrolment tokens", async () => {
> - renderWithMemoryRouter(<TokensCreate />);
> - const amount = screen.getByLabelText(/Amount of tokens to generate/i);
> - const expires = screen.getByLabelText(/Expiration time/i);
> - expect(screen.getByRole("button", { name: /Generate tokens/i
> })).toBeDisabled();
> - // can specify the number of tokens to generate
> - await userEvent.type(amount, "1");
> - // can specify the token expiration time (e.g. 1 week)
> - await userEvent.type(expires, "1 week");
> - await userEvent.click(screen.getByRole("button", { name: /Generate
> tokens/i }));
> - expect(tokensMutationMock).toHaveBeenCalledTimes(1);
> - expect(tokensMutationMock).toHaveBeenCalledWith({
> - amount: 1,
> - expires: "P0Y0M7DT0H0M0S",
> - });
> +it("can generate enrolment tokens", async () => {
> + renderWithMemoryRouter(<TokensCreate />);
> + const amount = screen.getByLabelText(/Amount of tokens to generate/i);
> + const expires = screen.getByLabelText(/Expiration time/i);
> + expect(screen.getByRole("button", { name: /Generate tokens/i
> })).toBeDisabled();
> + // can specify the number of tokens to generate
> + await userEvent.type(amount, "1");
> + // can specify the token expiration time (e.g. 1 week)
> + await userEvent.type(expires, "1 week");
> + await userEvent.click(screen.getByRole("button", { name: /Generate
> tokens/i }));
> + expect(tokensMutationMock).toHaveBeenCalledTimes(1);
> + expect(tokensMutationMock).toHaveBeenCalledWith({
> + amount: 1,
> + expires: "P0Y0M7DT0H0M0S",
> });
> });
> +
> +it("does not display error message on blur if the value has not chagned",
> async () => {
This is the only change in the tests file, the others are just due to removal
of the describe block.
> + renderWithMemoryRouter(<TokensCreate />);
> + const amount = screen.getByLabelText(/Amount of tokens to generate/i);
> + await userEvent.type(amount, "{tab}");
> + expect(amount).not.toHaveErrorMessage(/Error/i);
> + // enter a value and then delete it
> + await userEvent.type(amount, "1{backspace}");
> + expect(amount).toHaveErrorMessage(/Error/i);
> +});
--
https://code.launchpad.net/~petermakowski/maas-site-manager/+git/site-manager/+merge/441949
Your team MAAS Committers is requested to review the proposed merge of
~petermakowski/maas-site-manager:fix-validation-onSubmit-MAASENG-1571 into
maas-site-manager:main.
--
Mailing list: https://launchpad.net/~sts-sponsors
Post to : sts-sponsors@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sts-sponsors
More help : https://help.launchpad.net/ListHelp