-
Notifications
You must be signed in to change notification settings - Fork 4
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 #490 from huwshimi/add-sidepanel-tests
WD-17055 - chore(tests): add SidePanel tests
- Loading branch information
Showing
6 changed files
with
162 additions
and
17 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 +1,2 @@ | ||
export { default } from "./Loader"; | ||
export { TestId as LoaderTestId } from "./test-types"; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum TestId { | ||
COMPONENT = "Loader", | ||
} |
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 |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { screen, within } from "@testing-library/dom"; | ||
import { render } from "@testing-library/react"; | ||
|
||
import SidePanel from "./SidePanel"; | ||
import { Label } from "./types"; | ||
import { LoaderTestId } from "components/Loader"; | ||
|
||
describe("SidePanel", () => { | ||
test("displays content", () => { | ||
const content = "Content"; | ||
render(<SidePanel>{content}</SidePanel>); | ||
expect( | ||
screen.getByRole("complementary", { | ||
name: Label.SIDE_PANEL, | ||
}), | ||
).toHaveTextContent(content); | ||
}); | ||
|
||
test("can display as normal width", () => { | ||
render(<SidePanel>Content</SidePanel>); | ||
const sidePanel = screen.getByRole("complementary", { | ||
name: Label.SIDE_PANEL, | ||
}); | ||
expect(sidePanel).not.toHaveClass("is-wide"); | ||
expect(sidePanel).not.toHaveClass("is-narrow"); | ||
}); | ||
|
||
test("can display as wide", () => { | ||
render(<SidePanel width="wide">Content</SidePanel>); | ||
expect( | ||
screen.getByRole("complementary", { | ||
name: Label.SIDE_PANEL, | ||
}), | ||
).toHaveClass("is-wide"); | ||
}); | ||
|
||
test("can display as narrow", () => { | ||
render(<SidePanel width="narrow">Content</SidePanel>); | ||
expect( | ||
screen.getByRole("complementary", { | ||
name: Label.SIDE_PANEL, | ||
}), | ||
).toHaveClass("is-narrow"); | ||
}); | ||
|
||
test("can display as split", () => { | ||
render(<SidePanel isSplit>Content</SidePanel>); | ||
expect( | ||
screen.getByRole("complementary", { | ||
name: Label.SIDE_PANEL, | ||
}), | ||
).toHaveClass("is-split"); | ||
}); | ||
|
||
test("can display as an overlay", () => { | ||
render(<SidePanel isOverlay>Content</SidePanel>); | ||
expect( | ||
screen.getByRole("complementary", { | ||
name: Label.SIDE_PANEL, | ||
}), | ||
).toHaveClass("is-overlay"); | ||
}); | ||
|
||
test("can display as pinned", () => { | ||
render(<SidePanel pinned>Content</SidePanel>); | ||
expect( | ||
screen.getByRole("complementary", { | ||
name: Label.SIDE_PANEL, | ||
}), | ||
).toHaveClass("is-pinned"); | ||
}); | ||
|
||
test("can display loading state", () => { | ||
render(<SidePanel loading>Content</SidePanel>); | ||
expect( | ||
within( | ||
screen.getByRole("complementary", { | ||
name: Label.SIDE_PANEL, | ||
}), | ||
).getByTestId(LoaderTestId.COMPONENT), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
test("can display loading error", () => { | ||
render(<SidePanel hasError>Content</SidePanel>); | ||
expect( | ||
within( | ||
screen.getByRole("complementary", { | ||
name: Label.SIDE_PANEL, | ||
}), | ||
).getByText(Label.ERROR_LOADING), | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test("HeaderControls", () => { | ||
const content = "Content"; | ||
render(<SidePanel.HeaderControls>{content}</SidePanel.HeaderControls>); | ||
expect(screen.getByText(content)).toHaveClass("p-panel__controls"); | ||
}); | ||
|
||
test("HeaderTitle", () => { | ||
const content = "Content"; | ||
render(<SidePanel.HeaderTitle>{content}</SidePanel.HeaderTitle>); | ||
expect(screen.getByText(content)).toHaveClass("p-panel__title"); | ||
}); | ||
test("Sticky", () => { | ||
const content = "Content"; | ||
render(<SidePanel.Sticky>{content}</SidePanel.Sticky>); | ||
expect(screen.getByText(content)).toHaveClass("sticky-wrapper"); | ||
}); | ||
|
||
test("Header", () => { | ||
const content = "Content"; | ||
render(<SidePanel.Header>{content}</SidePanel.Header>); | ||
expect(screen.getByText(content)).toHaveClass("p-panel__header"); | ||
}); | ||
|
||
test("Container", () => { | ||
const content = "Content"; | ||
render(<SidePanel.Container>{content}</SidePanel.Container>); | ||
expect(screen.getByText(content).parentElement).toHaveClass("p-panel"); | ||
}); | ||
|
||
test("Content", () => { | ||
const content = "Content"; | ||
render(<SidePanel.Content>{content}</SidePanel.Content>); | ||
expect(screen.getByText(content)).toHaveClass("p-panel__content"); | ||
}); | ||
|
||
test("Footer", () => { | ||
const content = "Content"; | ||
render(<SidePanel.Footer>{content}</SidePanel.Footer>); | ||
expect(screen.getByText(content)).toHaveClass("panel-footer"); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum Label { | ||
ERROR_LOADING = "Loading failed", | ||
SIDE_PANEL = "Side panel", | ||
} |