Skip to content

Commit

Permalink
Merge pull request #7129 from Sage/pw_remove_awaits
Browse files Browse the repository at this point in the history
test: remove unnecessary awaits
  • Loading branch information
stephenogorman authored Dec 19, 2024
2 parents aa1bbf7 + a4932d6 commit 46bef81
Show file tree
Hide file tree
Showing 21 changed files with 416 additions and 421 deletions.
6 changes: 3 additions & 3 deletions src/components/accordion/accordion.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ test.describe("should render Accordion component", () => {
await mount(<AccordionComponent size={size} />);

const cssHeight = await getStyle(accordionTitleContainer(page), "height");
await expect(parseInt(cssHeight)).toBeLessThanOrEqual(height + 1);
await expect(parseInt(cssHeight)).toBeGreaterThanOrEqual(height - 1);
expect(parseInt(cssHeight)).toBeLessThanOrEqual(height + 1);
expect(parseInt(cssHeight)).toBeGreaterThanOrEqual(height - 1);
});
});

Expand Down Expand Up @@ -403,7 +403,7 @@ test.describe("should render Accordion component", () => {
);

const cssWidth = await getStyle(accordionTitleContainer(page), "width");
await expect(cssWidth).toContain(width);
expect(cssWidth).toContain(width);
});
});

Expand Down
399 changes: 197 additions & 202 deletions src/components/action-popover/action-popover.pw.tsx

Large diffs are not rendered by default.

88 changes: 44 additions & 44 deletions src/components/box/box.pw.tsx

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/components/card/card.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ test.describe("Check Card component properties", () => {
.locator('[data-component="card"]')
.count();

await expect(resultForColumnOne).toEqual(countOfFirstColumn);
expect(resultForColumnOne).toEqual(countOfFirstColumn);

await expect(resultForColumnTwo).toEqual(countOfSecondColumn);
expect(resultForColumnTwo).toEqual(countOfSecondColumn);
});
},
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/date-range/date-range.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ test.describe("Event tests for DateRange component", () => {
getDataElementByValue(page, "input").nth(inputIndex);
await getDataElementByValueElementInputEqInputIndex.clear();

await expect(callbackCount).toEqual(1);
expect(callbackCount).toEqual(1);
});
});

Expand All @@ -495,7 +495,7 @@ test.describe("Event tests for DateRange component", () => {

await textboxInput(page).nth(inputIndex).type(value);

await expect(callbackCount).toEqual(value.length);
expect(callbackCount).toEqual(value.length);
});
});
});
Expand All @@ -517,7 +517,7 @@ test.describe("Event tests for DateRange component", () => {

await textboxInput(page).nth(START_DATE_RANGE_INDEX).type("1");

await expect(callbackCount).toEqual(1);
expect(callbackCount).toEqual(1);
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/components/detail/detail.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test.describe("check Detail component text input", () => {
}) => {
await mount(<Detail>{text}</Detail>);

await expect(await childrenPreview(page)).toHaveText(text);
await expect(childrenPreview(page)).toHaveText(text);
});

test(`check Detail footnote on preview is ${text} footnote value`, async ({
Expand All @@ -31,7 +31,7 @@ test.describe("check Detail component text input", () => {
}) => {
await mount(<Detail footnote={text} />);

await expect(await footnotePreview(page)).toHaveText(text);
await expect(footnotePreview(page)).toHaveText(text);
});
});
});
Expand All @@ -42,9 +42,9 @@ test("should set Detail icon on preview to chevron_up", async ({
}) => {
await mount(<Detail icon="chevron_up" />);

await expect(await icon(page)).toHaveAttribute("type", "chevron_up");
await expect(icon(page)).toHaveAttribute("type", "chevron_up");
const isVisible = await icon(page).isVisible();
await expect(await isVisible).toBeTruthy();
expect(isVisible).toBeTruthy();
});

test.describe("Accessibility tests for Detail component", () => {
Expand Down
56 changes: 28 additions & 28 deletions src/components/file-input/file-input.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ test.describe("FileInput component", () => {
page,
}) => {
await mount(<FileInputComponent accept={accept} />);
const input = await hiddenInput(page, "File input");
const input = hiddenInput(page, "File input");
await expect(input).toHaveAttribute("accept", accept);
});
});
Expand All @@ -149,7 +149,7 @@ test.describe("FileInput component", () => {
page,
}) => {
await mount(<FileInputComponent buttonText={testVal} />);
const buttonElement = await selectFileButton(page, testVal);
const buttonElement = selectFileButton(page, testVal);
await expect(buttonElement).toBeVisible();
});
});
Expand All @@ -170,9 +170,9 @@ test.describe("FileInput component", () => {
page,
}) => {
await mount(<FileInputComponent label={testVal} />);
const input = await hiddenInput(page, testVal);
const input = hiddenInput(page, testVal);
await expect(input).toHaveCount(1);
const labelElement = await label(page);
const labelElement = label(page);
await expect(labelElement).toHaveText(testVal);
await expect(labelElement).toBeVisible();
});
Expand All @@ -184,7 +184,7 @@ test.describe("FileInput component", () => {
page,
}) => {
await mount(<FileInputComponent inputHint={testVal} />);
const inputHintElement = await page.getByText(testVal);
const inputHintElement = page.getByText(testVal);
await expect(inputHintElement).toBeVisible();
});
});
Expand All @@ -199,7 +199,7 @@ test.describe("FileInput component", () => {
.getPropertyValue("border-color"),
);
// TODO: should check token value (--colorsSemanticNegative500), rewrite this when we have the equivalent playwright util merged in
await expect(borderColor).toBe("rgb(203, 55, 74)");
expect(borderColor).toBe("rgb(203, 55, 74)");
});

test("should render with string error prop", async ({ mount, page }) => {
Expand All @@ -212,16 +212,16 @@ test.describe("FileInput component", () => {
.getPropertyValue("border-color"),
);
// TODO: should check token value (--colorsSemanticNegative500), rewrite this when we have the equivalent playwright util merged in
await expect(borderColor).toBe("rgb(203, 55, 74)");
const errorMessage = await page.getByText("error text");
expect(borderColor).toBe("rgb(203, 55, 74)");
const errorMessage = page.getByText("error text");
await expect(errorMessage).toBeVisible();
await expect(errorMessage).toHaveCSS("color", "rgb(203, 55, 74)");
});

specialCharacters.forEach((testVal) => {
test(`should render with id '${testVal}'`, async ({ mount, page }) => {
await mount(<FileInputComponent id={testVal} />);
const input = await hiddenInput(page, "File input");
const input = hiddenInput(page, "File input");
await expect(input).toHaveAttribute("id", testVal);
});
});
Expand Down Expand Up @@ -330,12 +330,12 @@ test.describe("with uploadStatus prop", () => {
uploadStatus={{ ...uploadingStatusProps, onAction }}
/>,
);
const actionButton = await page.getByRole("button", {
const actionButton = page.getByRole("button", {
name: "Cancel upload",
});
await expect(actionButton).toBeVisible();
await actionButton.click();
await expect(clickCount).toBe(1);
expect(clickCount).toBe(1);
});

test("in the uploading state, it renders the file name, but not as a link", async ({
Expand Down Expand Up @@ -371,9 +371,9 @@ test.describe("with uploadStatus prop", () => {
uploadStatus={{ ...uploadingStatusProps, progress: undefined }}
/>,
);
const loaderBar = await page.getByRole("progressbar");
const loaderBar = page.getByRole("progressbar");
await expect(loaderBar).toBeVisible();
await expect(await loaderBar.getAttribute("aria-valuenow")).toBeNull();
expect(await loaderBar.getAttribute("aria-valuenow")).toBeNull();
});

test("in the completed state, it renders a status message", async ({
Expand All @@ -397,20 +397,20 @@ test.describe("with uploadStatus prop", () => {
uploadStatus={{ ...completedStatusProps, onAction }}
/>,
);
const actionButton = await page.getByRole("button", {
const actionButton = page.getByRole("button", {
name: "Delete file",
});
await expect(actionButton).toBeVisible();
await actionButton.click();
await expect(clickCount).toBe(1);
expect(clickCount).toBe(1);
});

test("in the completed state, it renders the file name as a link with the provided props", async ({
mount,
page,
}) => {
await mount(<FileInputComponent uploadStatus={completedStatusProps} />);
const link = await page.getByRole("link", { name: "foo.pdf" });
const link = page.getByRole("link", { name: "foo.pdf" });
await expect(link).toBeVisible();
await expect(link).toHaveAttribute("href", "http://carbon.sage.com");
await expect(link).toHaveAttribute("target", "_blank");
Expand Down Expand Up @@ -438,7 +438,7 @@ test.describe("with uploadStatus prop", () => {
page,
}) => {
await mount(<FileInputComponent uploadStatus={previouslyStatusProps} />);
const link = await page.getByRole("link", { name: "foo.pdf" });
const link = page.getByRole("link", { name: "foo.pdf" });
await expect(link).toBeVisible();
await expect(link).toHaveAttribute("href", "http://carbon.sage.com");
await expect(link).toHaveAttribute("target", "_blank");
Expand All @@ -458,12 +458,12 @@ test.describe("with uploadStatus prop", () => {
uploadStatus={{ ...previouslyStatusProps, onAction }}
/>,
);
const actionButton = await page.getByRole("button", {
const actionButton = page.getByRole("button", {
name: "Delete file",
});
await expect(actionButton).toBeVisible();
await actionButton.click();
await expect(clickCount).toBe(1);
expect(clickCount).toBe(1);
});

test("in the previously state, it does not render a progress bar", async ({
Expand Down Expand Up @@ -493,10 +493,10 @@ test.describe("with uploadStatus prop", () => {
await mount(
<FileInputComponent uploadStatus={{ ...errorStatusProps, onAction }} />,
);
const actionButton = await page.getByRole("button", { name: "Clear" });
const actionButton = page.getByRole("button", { name: "Clear" });
await expect(actionButton).toBeVisible();
await actionButton.click();
await expect(clickCount).toBe(1);
expect(clickCount).toBe(1);
});

test("in the error state, it renders the file name, but not as a link", async ({
Expand Down Expand Up @@ -558,8 +558,8 @@ test.describe("interactions", () => {
fileName: "README.md",
fileType: "text/markdown",
});
await expect(onChangeCalls.length).toBe(1);
await expect(onChangeCalls[0]).toMatchObject({
expect(onChangeCalls.length).toBe(1);
expect(onChangeCalls[0]).toMatchObject({
name: "README.md",
type: "text/markdown",
});
Expand All @@ -585,7 +585,7 @@ test.describe("interactions", () => {
.getComputedStyle(el.parentElement as HTMLElement)
.getPropertyValue("border-width"),
);
await expect(borderWidth).toBe("2px");
expect(borderWidth).toBe("2px");
});

test("when dragging a file off the document, the component border returns to the original thickness", async ({
Expand Down Expand Up @@ -616,7 +616,7 @@ test.describe("interactions", () => {
.getComputedStyle(el.parentElement as HTMLElement)
.getPropertyValue("border-width"),
);
await expect(borderWidth).toBe("1px");
expect(borderWidth).toBe("1px");
});

test("after dropping a file, the component border returns to the original thickness", async ({
Expand Down Expand Up @@ -647,7 +647,7 @@ test.describe("interactions", () => {
.getComputedStyle(el.parentElement as HTMLElement)
.getPropertyValue("border-width"),
);
await expect(borderWidth).toBe("1px");
expect(borderWidth).toBe("1px");
});

test("while dragging a file with the component in the error state, the border color changes", async ({
Expand All @@ -671,7 +671,7 @@ test.describe("interactions", () => {
.getPropertyValue("border-color"),
);
// TODO: should check token value (--colorsSemanticNegative600), rewrite this when we have the equivalent playwright util merged in
await expect(borderColor).toBe("rgb(162, 44, 59)");
expect(borderColor).toBe("rgb(162, 44, 59)");
});

test("while dragging a file over the component, the background color changes", async ({
Expand All @@ -694,7 +694,7 @@ test.describe("interactions", () => {
.getComputedStyle(el.parentElement as HTMLElement)
.getPropertyValue("background-color"),
);
await expect(backgroundColor).toBe("rgb(204, 214, 219)");
expect(backgroundColor).toBe("rgb(204, 214, 219)");
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/components/heading/heading.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ test.describe("Heading component", () => {
}) => {
await mount(<HeadingComponent backLink="https://carbon.sage.com/" />);

const linkWrapper = await link(page);
const backLinkAnchor = await linkWrapper.locator("a");
const linkWrapper = link(page);
const backLinkAnchor = linkWrapper.locator("a");
await backLinkAnchor.focus();
await expect(backLinkAnchor).toHaveCSS(
"box-shadow",
Expand Down
2 changes: 1 addition & 1 deletion src/components/hr/hr.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test.describe("Hr component", () => {
mount,
page,
}) => {
await await mount(
await mount(
<HrComponent
mb={7}
mt={7}
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/pages.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test.describe("Prop checks for Pages component", () => {
await dataComponentButtonByText(page, "Go to second page").click();
const classAttribute = await pageComponent.getAttribute("class");

await expect(classAttribute).toContain(transition);
expect(classAttribute).toContain(transition);
});
});

Expand Down
Loading

0 comments on commit 46bef81

Please sign in to comment.