Skip to content

Commit

Permalink
fix e2e, packages
Browse files Browse the repository at this point in the history
  • Loading branch information
esizer committed Sep 27, 2024
1 parent 7d48ed6 commit 63e35b7
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 31 deletions.
8 changes: 4 additions & 4 deletions apps/playwright/tests/login-logout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ test.describe("Login and logout", () => {
}
return false;
})
.then(async (request) => {
.then((request) => {
// make sure it uses the access token
expect(request.headers().authorization).toEqual(
`Bearer ${tokenSet1.accessToken}`,
Expand Down Expand Up @@ -195,7 +195,7 @@ test.describe("Login and logout", () => {
}
return false;
})
.then(async (req) => {
.then((req) => {
// make sure it uses the second access token
expect(req.headers().authorization).toEqual(
`Bearer ${tokenSet2.accessToken}`,
Expand Down Expand Up @@ -229,7 +229,7 @@ test.describe("Login and logout", () => {
}
return false;
})
.then(async (req) => {
.then((req) => {
// make sure it uses the third access token
expect(req.headers().authorization).toEqual(
`Bearer ${tokenSet3.accessToken}`,
Expand Down Expand Up @@ -266,7 +266,7 @@ test.describe("Login and logout", () => {
await page.goto("/en/logged-out");
await page.getByRole("button", { name: "Sign out" }).click();

await requestPromise.then(async (req) => {
await requestPromise.then((req) => {
const url = new URL(req.url());
const searchParamPostLogoutRedirectUri = url.searchParams.get(
"post_logout_redirect_uri",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ const { isTokenKnownToBeExpired } = exportedForTesting;

describe("ClientProvider tests", () => {
// some API requests do not require auth to succeed
test("If there is no auth then willAuthError is false", async () => {
test("If there is no auth then willAuthError is false", () => {
const accessToken = null;
const result = isTokenKnownToBeExpired(accessToken);
expect(result).toEqual(false);
});

test("If there is an accessToken that has not expired then willAuthError is false", async () => {
test("If there is an accessToken that has not expired then willAuthError is false", () => {
const accessToken =
"eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjIxNDc0ODM2NDcsImlhdCI6MH0.v5o7sfcTiqB21JrCZ1ytP0gJp4JeTuiEdO8yVBVro7Y"; // expires Jan 18 2038
const result = isTokenKnownToBeExpired(accessToken);
expect(result).toEqual(false);
});

test("If there is an accessToken that has expired then willAuthError is true", async () => {
test("If there is an accessToken that has expired then willAuthError is true", () => {
const accessToken =
"eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjEsImlhdCI6MH0.d5nyMUDCvbvfTmg3ow_cN4YZX4jmfoXAGq3DbCw5LAc"; // expires Dec 31 1969
const result = isTokenKnownToBeExpired(accessToken);
expect(result).toEqual(true);
});
test("finds validation errors", async () => {
test("finds validation errors", () => {
// an error object for testing on
// sorry, very ugly - would be nice to use stubs but I haven't figured that out
const testError: CombinedError = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ const ClientProvider = ({
if (errorMessageNode) toast.error(errorMessageNode);
},
}),
// NOTE: Needed to colour the function
// eslint-disable-next-line @typescript-eslint/require-await
authExchange(async (utils) => {
return {
addAuthToOperation: (operation) => {
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-config-custom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ module.exports = {

// Temporarily disabled to ease transition to typed linting
"@typescript-eslint/prefer-nullish-coalescing": "off", // Remove in #11376
"@typescript-eslint/require-await": "off", // Remove in #11377
"@typescript-eslint/only-throw-error": "off", // Remove in #11378
"@typescript-eslint/no-misused-promises": "off", // Remove in #11379
"@typescript-eslint/no-base-to-string": "off", // Remove in #11380
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/src/components/BasicForm.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const labels = {
export default {
component: BasicForm,
args: {
onSubmit: async (values) => action("onSubmit")(values),
onSubmit: (values) => action("onSubmit")(values),
labels,
},
} as Meta<typeof BasicForm>;
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/src/components/BasicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function BasicForm<TFieldValues extends FieldValues>({
formState: { isDirty },
} = methods;

const handleSubmit = async (data: TFieldValues) => {
const handleSubmit = (data: TFieldValues) => {
// Reset form to clear dirty values
reset(data, {
keepDirty: false,
Expand Down
22 changes: 11 additions & 11 deletions packages/forms/src/components/DateInput/DateInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("DateInput", () => {
await axeTest(container);
});

it("should render subfields", async () => {
it("should render subfields", () => {
const { rerender } = renderDateInput(defaultProps);

expect(screen.getByRole("group", { name: "Date" })).toBeInTheDocument();
Expand Down Expand Up @@ -122,7 +122,7 @@ describe("DateInput", () => {

await user.click(screen.getByRole("button", { name: /submit/i }));

await waitFor(async () => {
await waitFor(() => {
const alert = screen.getByRole("alert");
expect(alert).toBeInTheDocument();
});
Expand Down Expand Up @@ -161,7 +161,7 @@ describe("DateInput", () => {

await user.click(screen.getByRole("button", { name: /submit/i }));

await waitFor(async () => {
await waitFor(() => {
expect(submitFn).toHaveBeenCalledWith({
date: "2023-01-01",
});
Expand Down Expand Up @@ -209,12 +209,12 @@ describe("DateInput", () => {

await user.click(screen.getByRole("button", { name: /submit/i }));

await waitFor(async () => {
await waitFor(() => {
const alert = screen.getByRole("alert");
expect(within(alert).getByText(/after/i)).toBeInTheDocument();
});

await waitFor(async () => {
await waitFor(() => {
expect(submitFn).not.toHaveBeenCalled();
});
});
Expand All @@ -240,7 +240,7 @@ describe("DateInput", () => {

await user.click(screen.getByRole("button", { name: /submit/i }));

await waitFor(async () => {
await waitFor(() => {
expect(submitFn).toHaveBeenCalled();
});
});
Expand Down Expand Up @@ -286,13 +286,13 @@ describe("DateInput", () => {

await user.click(screen.getByRole("button", { name: /submit/i }));

await waitFor(async () => {
await waitFor(() => {
const alert = screen.getByRole("alert");

expect(within(alert).getByText(/before/i)).toBeInTheDocument();
});

await waitFor(async () => {
await waitFor(() => {
expect(submitFn).not.toHaveBeenCalled();
});
});
Expand All @@ -318,7 +318,7 @@ describe("DateInput", () => {

await user.click(screen.getByRole("button", { name: /submit/i }));

await waitFor(async () => {
await waitFor(() => {
expect(submitFn).toHaveBeenCalled();
});
});
Expand Down Expand Up @@ -352,14 +352,14 @@ describe("DateInput", () => {
await user.type(day, "30");
await user.click(screen.getByRole("button", { name: /submit/i }));

await waitFor(async () => {
await waitFor(() => {
const alert = screen.getByRole("alert");
expect(
within(alert).getByText(/please enter a valid date/i),
).toBeInTheDocument();
});

await waitFor(async () => {
await waitFor(() => {
expect(submitFn).not.toHaveBeenCalled();
});
});
Expand Down
10 changes: 5 additions & 5 deletions packages/forms/src/components/Repeater/Repeater.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ describe("Repeater", () => {

await user.click(screen.getByRole("button", { name: /add item/i }));

await waitFor(async () => {
await waitFor(() => {
expect(
screen.getByRole("group", { name: /test repeater/i }),
).toBeInTheDocument();
});

await waitFor(async () => {
await waitFor(() => {
expect(addFn).toHaveBeenCalled();
});
});
Expand All @@ -188,21 +188,21 @@ describe("Repeater", () => {
},
});

await waitFor(async () => {
await waitFor(() => {
expect(
screen.getAllByRole("group", { name: /test repeater/i }),
).toHaveLength(2);
});

await user.click(screen.getByRole("button", { name: /remove item 1/i }));

await waitFor(async () => {
await waitFor(() => {
expect(
screen.getAllByRole("group", { name: /test repeater/i }),
).toHaveLength(1);
});

await waitFor(async () => {
await waitFor(() => {
expect(removeFn).toHaveBeenCalledWith(0);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe("DropdownMenu", () => {
await axeTest(container);
});

it("should not render when closed", async () => {
it("should not render when closed", () => {
renderDropdownMenu({});

expect(
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/SideMenu/SideMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const renderSideMenu = (props: SideMenuProps) => {
};

describe("SideMenu", () => {
it("Should be closed if isOpen false", async () => {
it("Should be closed if isOpen false", () => {
renderSideMenu({
...defaultProps,
open: false,
Expand All @@ -43,7 +43,7 @@ describe("SideMenu", () => {
expect(nav).toHaveAttribute("data-state", "closed");
});

it("Should be open if isOpen true", async () => {
it("Should be open if isOpen true", () => {
renderSideMenu(defaultProps);

const nav = screen.getByRole("navigation", {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/Tabs/Tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("Tabs", () => {
await axeTest(container);
});

it("should only render opened tabpanel", async () => {
it("should only render opened tabpanel", () => {
renderTabs({
defaultValue: "one",
});
Expand Down

0 comments on commit 63e35b7

Please sign in to comment.