-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added unit tests for platformswitcher component
- Loading branch information
1 parent
5605124
commit d3464ae
Showing
6 changed files
with
161 additions
and
0 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
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
26 changes: 26 additions & 0 deletions
26
src/components/AppLayout/__test__/PlatformSwitcher.spec.tsx
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,26 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { PlatformSwitcher } from "../PlatformSwitcher"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
const PlatformSwitcherComponent = () => ( | ||
<PlatformSwitcher | ||
buttonProps={{ icon: <span>icon</span> }} | ||
bottomLink={{ text: "CFD link", href: "#" }} | ||
> | ||
<span>platform switcher child</span> | ||
</PlatformSwitcher> | ||
); | ||
|
||
describe("PlatformSwitcher Component", () => { | ||
it("renders without crashing", async () => { | ||
render(<PlatformSwitcherComponent />); | ||
await userEvent.click(screen.getByRole("button")); | ||
expect(screen.getByText("platform switcher child")).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders the bottom link if provided", async () => { | ||
render(<PlatformSwitcherComponent />); | ||
await userEvent.click(screen.getByRole("button")); | ||
expect(screen.getByText("CFD link")).toBeInTheDocument(); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
src/components/AppLayout/__test__/PlatformSwitcherButton.spec.tsx
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,39 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { PlatformSwitcherButton } from "../PlatformSwitcher/PlatformSwitcherButton"; | ||
|
||
describe("PlatformSwitcherButton Component", () => { | ||
const TestIcon = () => <span>Test Icon</span>; | ||
|
||
it("renders without crashing", () => { | ||
render( | ||
<PlatformSwitcherButton icon={<TestIcon />} isExpanded={false} />, | ||
); | ||
expect(screen.getByRole("button")).toBeInTheDocument(); | ||
}); | ||
|
||
it("displays the provided icon", () => { | ||
render( | ||
<PlatformSwitcherButton icon={<TestIcon />} isExpanded={false} />, | ||
); | ||
expect(screen.getByText("Test Icon")).toBeInTheDocument(); | ||
}); | ||
|
||
it("shows expanded chevron when isExpanded is true", () => { | ||
render(<PlatformSwitcherButton icon={<TestIcon />} isExpanded />); | ||
expect(screen.getByRole("img")).toHaveClass( | ||
"deriv-platform-switcher__button-chevron__expanded", | ||
); | ||
}); | ||
|
||
it("applies custom class names to the chevron", () => { | ||
const customClassName = "custom-chevron-class"; | ||
render( | ||
<PlatformSwitcherButton | ||
icon={<TestIcon />} | ||
isExpanded={false} | ||
chevronIconClassName={customClassName} | ||
/>, | ||
); | ||
expect(screen.getByRole("img")).toHaveClass(customClassName); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
src/components/AppLayout/__test__/PlatformSwitcherItem.spec.tsx
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,66 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { PlatformSwitcherItem } from "../PlatformSwitcher/PlatformSwitcherItem"; | ||
|
||
describe("PlatformSwitcherItem Component", () => { | ||
const TestIcon = () => <div>Test Icon</div>; | ||
|
||
it("renders without crashing", () => { | ||
render( | ||
<PlatformSwitcherItem | ||
icon={<TestIcon />} | ||
active={false} | ||
description="Test Description" | ||
/>, | ||
); | ||
expect(screen.getByRole("link")).toBeInTheDocument(); | ||
}); | ||
|
||
it("shows as active when active prop is true", () => { | ||
render( | ||
<PlatformSwitcherItem | ||
icon={<TestIcon />} | ||
active | ||
description="Active Item" | ||
/>, | ||
); | ||
expect(screen.getByRole("link")).toHaveClass( | ||
"deriv-platform-switcher__item--active", | ||
); | ||
}); | ||
|
||
it("displays the correct description content as text", () => { | ||
render( | ||
<PlatformSwitcherItem | ||
icon={<TestIcon />} | ||
active={false} | ||
description="Simple Description" | ||
/>, | ||
); | ||
expect(screen.getByText("Simple Description")).toBeInTheDocument(); | ||
}); | ||
|
||
it("displays the correct description content as JSX", () => { | ||
const JsxDescription = <span>JSX Description</span>; | ||
render( | ||
<PlatformSwitcherItem | ||
icon={<TestIcon />} | ||
active={false} | ||
description={JsxDescription} | ||
/>, | ||
); | ||
expect(screen.getByText("JSX Description")).toBeInTheDocument(); | ||
}); | ||
|
||
it("applies custom class names correctly", () => { | ||
const customClassName = "custom-item-class"; | ||
render( | ||
<PlatformSwitcherItem | ||
icon={<TestIcon />} | ||
active={false} | ||
description="Test" | ||
className={customClassName} | ||
/>, | ||
); | ||
expect(screen.getByRole("link")).toHaveClass(customClassName); | ||
}); | ||
}); |