← Back to team overview

sts-sponsors team mailing list archive

Re: [Merge] ~petermakowski/maas-site-manager:feat-token-generation-form-MAASENG-1476 into maas-site-manager:main

 

Review: Approve code, qa

LGTM, just one small (optional) suggestion

Diff comments:

> diff --git a/frontend/package.json b/frontend/package.json
> index add2a15..b0aa455 100644
> --- a/frontend/package.json
> +++ b/frontend/package.json
> @@ -19,13 +19,16 @@
>      "classnames": "2.3.2",
>      "date-fns": "2.29.3",
>      "date-fns-tz": "2.0.0",
> +    "formik": "2.2.9",

Thank you for this!

> +    "human-interval": "2.0.1",
>      "lodash": "4.17.21",
>      "pluralize": "8.0.0",
>      "react": "18.2.0",
>      "react-dom": "18.2.0",
>      "react-router-dom": "6.8.1",
>      "use-local-storage-state": "18.1.2",
> -    "vanilla-framework": "3.11.0"
> +    "vanilla-framework": "3.11.0",
> +    "yup": "1.0.2"
>    },
>    "devDependencies": {
>      "@playwright/test": "1.31.1",
> diff --git a/frontend/src/components/TokensCreate/TokensCreate.test.tsx b/frontend/src/components/TokensCreate/TokensCreate.test.tsx
> index a3b8abd..b2a82f7 100644
> --- a/frontend/src/components/TokensCreate/TokensCreate.test.tsx
> +++ b/frontend/src/components/TokensCreate/TokensCreate.test.tsx
> @@ -1,10 +1,71 @@
> +import { rest } from "msw";
> +import { setupServer } from "msw/node";
> +import { vi } from "vitest";
> +
>  import TokensCreate from "./TokensCreate";
>  
> -import { render, screen } from "@/test-utils";
> +import urls from "@/api/urls";
> +import { render, screen, userEvent } from "@/test-utils";
> +
> +const postTokensEndpointMock = vi.fn();
> +const mockServer = setupServer(
> +  rest.post(urls.tokens, async (req) => {
> +    postTokensEndpointMock(await req.json());
> +  }),
> +);
> +
> +beforeAll(() => {
> +  mockServer.listen();
> +});
> +
> +afterEach(() => {
> +  mockServer.resetHandlers();
> +});
> +
> +afterAll(() => {
> +  mockServer.close();
> +});
>  
>  describe("TokensCreate", () => {
>    it("renders the form", async () => {
>      render(<TokensCreate />);
>      expect(screen.getByRole("form", { name: /Generate new enrollment tokens/i })).toBeInTheDocument();
>    });
> +
> +  it("if not all required fields have been entered the submit button is disabled", async () => {

Suggested change:

it("disables the submit button if some required fields have not been entered", ...

> +    render(<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 () => {
> +    render(<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 () => {
> +    render(<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(postTokensEndpointMock).toHaveBeenCalledTimes(1);
> +    expect(postTokensEndpointMock).toHaveBeenCalledWith({
> +      amount: 1,
> +      expires: "P0Y0M7DT0H0M0S",
> +    });
> +  });
>  });


-- 
https://code.launchpad.net/~petermakowski/maas-site-manager/+git/site-manager/+merge/439061
Your team MAAS Committers is subscribed to branch ~petermakowski/maas-site-manager:feat-token-generation-form-MAASENG-1476.



References