-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added integration test for simple navigation bar
- Loading branch information
1 parent
1ca1aa1
commit 6777c25
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
test/integration/navigation-bar/simple-navigation-bar.test.ts
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,84 @@ | ||
import { expect, test, describe } from "vitest"; | ||
import SimpleNavigationBar from "$lib/components/composites/navigation-bar/SimpleNavigationBar.svelte"; | ||
import { render, screen } from "@testing-library/svelte"; | ||
|
||
describe("SimpleNavigationBar", () => { | ||
test("When all props are provided, then whole navigation bar is shown", () => { | ||
render(SimpleNavigationBar, { | ||
target: document.body, | ||
props: { | ||
user: { | ||
firstName: "John", | ||
lastName: "Doe", | ||
}, | ||
backRef: "/", | ||
title: "Simple Navigation Bar", | ||
tabs: [ | ||
{ | ||
value: "first", | ||
label: "First", | ||
href: "/first", | ||
}, | ||
{ | ||
value: "second", | ||
label: "Second", | ||
href: "/second", | ||
}, | ||
], | ||
defaultTabValue: "first", | ||
}, | ||
}); | ||
|
||
const header = screen.getByRole("banner"); | ||
expect(header).toBeInTheDocument(); | ||
|
||
const nav = screen.getByRole("navigation"); | ||
expect(nav).toBeInTheDocument(); | ||
|
||
const linkTags = screen.getAllByRole("link"); | ||
expect(linkTags).toHaveLength(3); | ||
|
||
const backButtons = linkTags.filter((link) => link.getAttribute("href") === "/"); | ||
expect(backButtons).toHaveLength(1); | ||
const backButton = backButtons[0]; | ||
expect(backButton).toBeInTheDocument(); | ||
|
||
const firstLinks = linkTags.filter((link) => link.getAttribute("href") === "/first"); | ||
expect(firstLinks).toHaveLength(1); | ||
const firstLink = firstLinks[0]; | ||
expect(firstLink).toBeInTheDocument(); | ||
expect(firstLink).toHaveTextContent("First"); | ||
|
||
const secondLinks = linkTags.filter((link) => link.getAttribute("href") === "/second"); | ||
expect(secondLinks).toHaveLength(1); | ||
const secondLink = secondLinks[0]; | ||
expect(secondLink).toBeInTheDocument(); | ||
expect(secondLink).toHaveTextContent("Second"); | ||
|
||
// Buttons have tab role | ||
const tabs = screen.getAllByRole("tab"); | ||
expect(tabs).toHaveLength(2); | ||
|
||
// First tab is selected | ||
const firstTabs = tabs.filter((tab) => tab.getAttribute("tabindex") == "0"); | ||
expect(firstTabs).toHaveLength(1); | ||
const firstTab = firstTabs[0]; | ||
expect(firstTab).toHaveAttribute("data-state", "active"); | ||
expect(firstTab).toHaveAttribute("aria-selected", "true"); | ||
|
||
// Second tab is not selected | ||
const secondTabs = tabs.filter((tab) => tab.getAttribute("tabindex") == "-1"); | ||
expect(secondTabs).toHaveLength(1); | ||
const secondTab = secondTabs[0]; | ||
expect(secondTab).toHaveAttribute("data-state", "inactive"); | ||
expect(secondTab).toHaveAttribute("aria-selected", "false"); | ||
|
||
// User initials are shown | ||
const userInitials = screen.getByText("JD"); | ||
expect(userInitials).toBeInTheDocument(); | ||
|
||
// Title is shown | ||
const title = screen.getByText("Simple Navigation Bar"); | ||
expect(title).toBeInTheDocument(); | ||
}); | ||
}); |