Skip to content

Commit

Permalink
Merge pull request #6265 from Sage/hr-playwright-conversion
Browse files Browse the repository at this point in the history
test(hr): migrate from cypress to playwright - FE-6126
  • Loading branch information
DipperTheDan authored Aug 23, 2023
2 parents 68fb6c0 + d7b8b9b commit 2b39818
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 77 deletions.
76 changes: 0 additions & 76 deletions cypress/components/hr/hr.cy.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion cypress/components/split-button/split-button.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ context("Tests for SplitButton component", () => {
"have.css",
"border-radius",
"0px 32px 32px 0px"
)
);
});

it("should have the expected border radius on children container and buttons", () => {
Expand Down
9 changes: 9 additions & 0 deletions playwright/components/hr/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Page } from "@playwright/test";
import HR_COMPONENT from "./locators";

// component preview locators
const hrComponent = (page: Page) => {
return page.locator(HR_COMPONENT);
};

export default hrComponent;
4 changes: 4 additions & 0 deletions playwright/components/hr/locators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// component preview locators
const HR_COMPONENT = '[data-component="hr"]';

export default HR_COMPONENT;
69 changes: 69 additions & 0 deletions src/components/hr/components.test-pw.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from "react";
import Hr, { HrProps } from ".";
import Form from "../form";
import Textbox from "../textbox";
import Button from "../button";

export const Default = (props: HrProps) => {
return <Hr {...props} />;
};

export const DifferentSpacing = () => <Hr mt={7} mb={7} />;

export const InsideForm = () => (
<Form
onSubmit={() => {}}
leftSideButtons={<Button onClick={() => {}}>Cancel</Button>}
saveButton={
<Button buttonType="primary" type="submit">
Save
</Button>
}
stickyFooter={false}
>
<Textbox label="Textbox" />
<Textbox label="Textbox" />
<Hr mb={7} mt={7} />
<Textbox label="Textbox" />
</Form>
);

export const InsideFormInlineLabels = () => (
<Form
onSubmit={() => {}}
leftSideButtons={<Button onClick={() => {}}>Cancel</Button>}
saveButton={
<Button buttonType="primary" type="submit">
Save
</Button>
}
stickyFooter={false}
>
<Textbox
label="Textbox"
labelAlign="right"
labelInline
labelWidth={10}
inputWidth={50}
/>
<Textbox
label="Textbox"
labelAlign="right"
labelInline
labelWidth={10}
inputWidth={50}
/>
<Hr mb={7} mt={7} ml="10%" mr="40%" />
<Textbox
label="Textbox"
labelAlign="right"
labelInline
labelWidth={10}
inputWidth={50}
/>
</Form>
);

export const EnablingAdaptiveBehaviour = () => (
<Hr mb={7} mt={7} ml="10%" mr="40%" adaptiveMxBreakpoint={960} />
);
101 changes: 101 additions & 0 deletions src/components/hr/hr.pw.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React from "react";
import { test, expect } from "@playwright/experimental-ct-react17";
import { checkAccessibility } from "../../../playwright/support/helper";

import {
Default,
DifferentSpacing,
EnablingAdaptiveBehaviour,
InsideForm,
InsideFormInlineLabels,
} from "../hr/components.test-pw";
import hrComponent from "../../../playwright/components/hr/index";
import HrComponent from "./hr.component";

test.describe("Hr component", () => {
test("renders with expected margin", async ({ mount, page }) => {
await mount(<HrComponent />);

await expect(hrComponent(page)).toHaveCSS("margin-top", "24px");
await expect(hrComponent(page)).toHaveCSS("margin-bottom", "24px");
});

[
[799, 80, 320],
[800, 80, 320],
[801, 0, 0],
].forEach(([breakpoint, leftMargin, rightMargin]) => {
test.use({ viewport: { width: 800, height: 300 } });

test(`adaptiveMaxBreakpoint props set to ${breakpoint} applies the expected left and right margins`, async ({
mount,
page,
}) => {
await await mount(
<HrComponent
mb={7}
mt={7}
ml="10%"
mr="40%"
adaptiveMxBreakpoint={breakpoint}
/>
);

await expect(hrComponent(page)).toHaveCSS(
"margin-left",
`${leftMargin}px`
);
await expect(hrComponent(page)).toHaveCSS(
"margin-right",
`${rightMargin}px`
);
});
});
});

test.describe("Accessibility tests for Hr component", () => {
test("should pass accessibility tests for Default example", async ({
mount,
page,
}) => {
await mount(<Default />);

await checkAccessibility(page);
});

test("should pass accessibility tests for DifferentSpacing example", async ({
mount,
page,
}) => {
await mount(<DifferentSpacing />);

await checkAccessibility(page);
});

test("should pass accessibility tests for EnablingAdaptiveBehaviour example", async ({
mount,
page,
}) => {
await mount(<EnablingAdaptiveBehaviour />);

await checkAccessibility(page);
});

test("should pass accessibility tests for InsideForm example", async ({
mount,
page,
}) => {
await mount(<InsideForm />);

await checkAccessibility(page);
});

test("should pass accessibility tests for InsideFormInlineLabels example", async ({
mount,
page,
}) => {
await mount(<InsideFormInlineLabels />);

await checkAccessibility(page);
});
});

0 comments on commit 2b39818

Please sign in to comment.