Skip to content

Commit

Permalink
test(playwright): more flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenogorman committed Oct 25, 2023
1 parent 68f587c commit c090f2d
Show file tree
Hide file tree
Showing 3 changed files with 336 additions and 341 deletions.
27 changes: 11 additions & 16 deletions src/components/batch-selection/batch-selection.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
batchSelectionComponent,
batchSelectionButtonsByPosition,
} from "../../../playwright/components/batch-selection";
import { getComponent } from "../../../playwright/components/index";
import { HooksConfig } from "../../../playwright";

const BATCH_SELECTION_COLOR = [
Expand All @@ -39,43 +40,37 @@ test.describe("check BatchSelection component properties", () => {
test("should check hidden BatchSelection", async ({ mount, page }) => {
await mount(<BatchSelectionComponent hidden />);
const batchSelection = batchSelectionComponent(page);
await expect(batchSelection.getAttribute("hidden")).not.toBeNull();

await expect(batchSelection).toHaveAttribute("hidden", /.*/);
await expect(batchSelection).toHaveCSS("opacity", "0");
});

test("should check disabled BatchSelection", async ({ mount, page }) => {
await mount(<BatchSelectionComponent disabled />);
const batchSelection = batchSelectionComponent(page);
await expect(batchSelection).toHaveAttribute("disabled", "");

await expect(batchSelection).toHaveAttribute("disabled", /.*/);
});

([
[BATCH_SELECTION_COLOR[0], "rgb(0, 50, 76)"],
[BATCH_SELECTION_COLOR[1], "rgb(179, 194, 201)"],
[BATCH_SELECTION_COLOR[2], "rgb(255, 255, 255)"],
[BATCH_SELECTION_COLOR[3], ""],
[BATCH_SELECTION_COLOR[3], "rgba(0, 0, 0, 0)"],
] as [BatchSelectionProps["colorTheme"], string][]).forEach(
([colorTheme, backgroundColor]) => {
test(`check BatchSelection component ${colorTheme} colorTheme and it uses ${backgroundColor} as a background color`, async ({
test(`check background color is ${backgroundColor} when colorTheme is ${colorTheme}`, async ({
mount,
page,
}) => {
await mount(
<BatchSelectionComponent colorTheme={colorTheme} selectedCount={0} />
);

if (colorTheme === "transparent") {
await expect(batchSelectionComponent(page)).not.toHaveCSS(
"background-color",
backgroundColor
);
} else {
await expect(batchSelectionComponent(page)).toHaveCSS(
"background-color",
backgroundColor
);
}
const batchSelection = getComponent(page, "batch-selection");
await expect(batchSelection).toHaveCSS(
"background-color",
backgroundColor
);
});
}
);
Expand Down
60 changes: 27 additions & 33 deletions src/components/button/button.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import {
buttonDataComponent,
} from "../../../playwright/components/button/index";
import { ICON } from "../../../playwright/components/locators";
import {
checkAccessibility,
expectEventWasCalledOnce,
} from "../../../playwright/support/helper";
import { checkAccessibility } from "../../../playwright/support/helper";
import {
dlsRoot,
icon,
Expand Down Expand Up @@ -55,8 +52,6 @@ import {

const testData = [CHARACTERS.DIACRITICS, CHARACTERS.SPECIALCHARACTERS];

const messages: string[] = [];

test.describe("Button component", () => {
testData.forEach((label) => {
test(`should render label using ${label} special characters`, async ({
Expand Down Expand Up @@ -189,83 +184,82 @@ test.describe("Check events for Button component", () => {
mount,
page,
}) => {
let callbackCount = 0;
await mount(
<Button
onClick={(data) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
messages.push(data);
onClick={() => {
callbackCount += 1;
}}
>
Foo
</Button>
);

await buttonDataComponent(page).click();

await expectEventWasCalledOnce(messages, "onClick");
const buttonComponent = page.getByRole("button");
await buttonComponent.click();
expect(callbackCount).toBe(1);
});

test("should call onBlur callback when a blur event is triggered", async ({
mount,
page,
}) => {
let callbackCount = 0;
await mount(
<Button
onBlur={(data) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
messages.push(data);
onBlur={() => {
callbackCount += 1;
}}
>
Foo
</Button>
);

await buttonDataComponent(page).focus();
await buttonDataComponent(page).blur();
await expect(buttonDataComponent(page)).not.toBeFocused();
await expectEventWasCalledOnce(messages, "onBlur");
const buttonComponent = page.getByRole("button");
await buttonComponent.focus();
await buttonComponent.blur();
await expect(buttonComponent).not.toBeFocused();
expect(callbackCount).toBe(1);
});

test("should call onKeyDown callback when a keydown event is triggered", async ({
mount,
page,
}) => {
let callbackCount = 0;
await mount(
<Button
onKeyDown={(data) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
messages.push(data);
onKeyDown={() => {
callbackCount += 1;
}}
>
Foo
</Button>
);

await buttonDataComponent(page).press("Enter");
await expectEventWasCalledOnce(messages, "onKeyDown");
const buttonComponent = page.getByRole("button");
await buttonComponent.press("Enter");
expect(callbackCount).toBe(1);
});

test("should call onFocus callback when a focus event is triggered", async ({
mount,
page,
}) => {
let callbackCount = 0;
await mount(
<Button
onFocus={(data) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
messages.push(data);
onFocus={() => {
callbackCount += 1;
}}
>
Foo
</Button>
);

await buttonDataComponent(page).focus();
await expectEventWasCalledOnce(messages, "onFocus");
const buttonComponent = page.getByRole("button");
await buttonComponent.focus();
expect(callbackCount).toBe(1);
});
});

Expand Down
Loading

0 comments on commit c090f2d

Please sign in to comment.