Skip to content

Commit

Permalink
test: remove duplicate tests and add another
Browse files Browse the repository at this point in the history
  • Loading branch information
Slartibartfass2 committed Nov 19, 2024
1 parent 3564ad1 commit abd9e31
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 77 deletions.
22 changes: 21 additions & 1 deletion test/integration/navigation-bar/paper-navigation-bar.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test, describe } from "vitest";
import { expect, test, describe, assert } from "vitest";
import PaperNavigationBar from "$lib/components/composites/navigation-bar/PaperNavigationBar.svelte";
import { render, screen } from "@testing-library/svelte";

Expand Down Expand Up @@ -50,4 +50,24 @@ describe("PaperNavigationBar", () => {
const paperId = screen.getByText("#123");
expect(paperId).toBeInTheDocument();
});

test("When paper ID is not provided, then paper ID is not shown", async () => {
render(PaperNavigationBar, {
target: document.body,
props: {
user: {
firstName: "John",
lastName: "Doe",
},
backRef: "/",
paper: {
id: undefined,
title: "Example Paper Title",
authors: ["John Doe", "Jane Doe"],
},
},
});

assert.throws(() => screen.getByText("#123"));
});
});
15 changes: 0 additions & 15 deletions test/integration/navigation-bar/project-navigation-bar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,9 @@ describe("ProjectNavigationBar", () => {
},
});

const header = screen.getByRole("banner");
expect(header).toBeInTheDocument();

const nav = screen.getByRole("navigation");
expect(nav).toBeInTheDocument();

const linkTags = screen.getAllByRole("link");
expect(linkTags).toHaveLength(5);

const backButtons = linkTags.filter((link) => link.getAttribute("href") === "/");
expect(backButtons).toHaveLength(1);
const backButton = backButtons[0];
expect(backButton).toBeInTheDocument();

const dashboardLinks = linkTags.filter(
(link) => link.getAttribute("href") === "/project/123/dashboard",
);
Expand Down Expand Up @@ -76,10 +65,6 @@ describe("ProjectNavigationBar", () => {
expect(statisticsTab).toHaveAttribute("data-state", "active");
expect(statisticsTab).toHaveAttribute("aria-selected", "true");

// User initials are shown
const userInitials = screen.getByText("JD");
expect(userInitials).toBeInTheDocument();

// Project title is shown
const projectTitle = screen.getByText("Example Project Title");
expect(projectTitle).toBeInTheDocument();
Expand Down
63 changes: 2 additions & 61 deletions test/integration/navigation-bar/simple-navigation-bar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,11 @@ describe("SimpleNavigationBar", () => {
},
backRef: "/",
title: "Simple Navigation Bar",
tabs: [
{
value: "first",
label: "First",
href: "/first",
},
{
value: "second",
label: "Second",
href: "/second",
},
],
defaultTabValue: "first",
tabs: [],
defaultTabValue: "",
},
});

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();
Expand Down

0 comments on commit abd9e31

Please sign in to comment.