Skip to content

Commit

Permalink
Merge pull request #6912 from Sage/FE-6612-navigationbar-rtl
Browse files Browse the repository at this point in the history
refactor(navigation-bar): convert enzyme tests to RTL
  • Loading branch information
nuria1110 authored Sep 2, 2024
2 parents 01e0572 + 8dafe64 commit 5b47320
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 249 deletions.
2 changes: 1 addition & 1 deletion src/components/global-header/global-header.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { checkAccessibility } from "../../../playwright/support/helper";

test.describe("Global Header component", () => {
test("should render without causing a ResiveObserver related error", async ({
test("should render without causing a ResizeObserver related error", async ({
mount,
page,
}) => {
Expand Down
71 changes: 35 additions & 36 deletions src/components/global-header/global-header.test.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
import { render, screen } from "@testing-library/react";
import React from "react";
import GlobalHeader, { GlobalHeaderProps } from "./global-header.component";
import GlobalHeader from "./global-header.component";

function renderer(props?: GlobalHeaderProps) {
return render(<GlobalHeader {...props}>foobar</GlobalHeader>);
}
test("should be visible with correct accessible name", () => {
render(<GlobalHeader>foobar</GlobalHeader>);

describe("Global Header", () => {
it("should be visible with correct accessible name", () => {
renderer();
expect(screen.getByRole("navigation")).toHaveAccessibleName(
"Global Header"
);
});
const globalHeader = screen.getByRole("navigation");

it("should be visible with correct styling", () => {
renderer();
expect(screen.getByRole("navigation")).toHaveStyle({
backgroundColor: "var(--colorsComponentsMenuWinterStandard500)",
color: "var(--colorsComponentsMenuYang100)",
position: "fixed",
});
});
expect(globalHeader).toBeVisible();
expect(globalHeader).toHaveAccessibleName("Global Header");
});

test("should render with 'data-component' set to 'global-header'", () => {
render(<GlobalHeader>foobar</GlobalHeader>);

expect(screen.getByRole("navigation")).toHaveAttribute(
"data-component",
"global-header"
);
});

it("should have correct z-index", () => {
renderer();
expect(screen.getByRole("navigation")).toHaveStyle("z-index: 2999");
test("should have correct z-index", () => {
render(<GlobalHeader>foobar</GlobalHeader>);

expect(screen.getByRole("navigation")).toHaveStyle("z-index: 2999");
});

describe("when logo prop is passed", () => {
it("and logo is an img element, logo is visible with correct alt text", () => {
const logo = <img src="foobar" alt="Carbon logo" />;
render(<GlobalHeader logo={logo}>foobar</GlobalHeader>);

expect(screen.getByRole("img")).toHaveAccessibleName("Carbon logo");
});

describe("when logo prop is passed", () => {
it("and logo is an img element, logo is visible with correct alt text", () => {
const logo = <img src="foobar" alt="Carbon logo" />;
renderer({ logo });
expect(screen.getByAltText("Carbon logo")).toBeInTheDocument();
});

it("and logo is a svg element, logo is visible with correct accessible name", () => {
const logo = <svg aria-label="Carbon logo" data-role="carbon-logo" />;
renderer({ logo });
expect(screen.getByTestId("carbon-logo")).toHaveAccessibleName(
"Carbon logo"
);
});
it("and logo is a svg element, logo is visible with correct accessible name", () => {
const logo = <svg aria-label="Carbon logo" data-role="carbon-logo" />;
render(<GlobalHeader logo={logo}>foobar</GlobalHeader>);

expect(screen.getByTestId("carbon-logo")).toHaveAccessibleName(
"Carbon logo"
);
});
});
22 changes: 19 additions & 3 deletions src/components/navigation-bar/navigation-bar-test.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { Menu, MenuItem } from "../menu";

export default {
title: "Navigation Bar/Test",
includeStories: ["DefaultStory", "NavigationBarWithSubmenuAndChangingHeight"],
includeStories: [
"DefaultStory",
"NavigationBarWithSubmenuAndChangingHeight",
"ResponsivePadding",
],
parameters: {
info: { disable: true },
chromatic: {
Expand All @@ -22,8 +26,9 @@ DefaultStory.args = {
navigationType: "light",
isLoading: false,
children: "Example content",
ariaLabel: undefined,
position: undefined,
ariaLabel: "",
position: "",
orientation: "",
offset: "0",
};

Expand Down Expand Up @@ -68,3 +73,14 @@ export const NavigationBarWithSubmenuAndChangingHeight = () => {
</div>
);
};

export const ResponsivePadding = () => {
return <NavigationBar>Example content</NavigationBar>;
};

ResponsivePadding.parameters = {
chromatic: {
disableSnapshot: false,
viewports: [599, 959, 1259],
},
};
209 changes: 0 additions & 209 deletions src/components/navigation-bar/navigation-bar.spec.tsx

This file was deleted.

Loading

0 comments on commit 5b47320

Please sign in to comment.