-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6912 from Sage/FE-6612-navigationbar-rtl
refactor(navigation-bar): convert enzyme tests to RTL
- Loading branch information
Showing
5 changed files
with
205 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.