From bb1b087d1ef88271414ce32fc7fe39bf3966c531 Mon Sep 17 00:00:00 2001 From: Felix Schlegel Date: Tue, 19 Nov 2024 00:54:24 +0100 Subject: [PATCH] test: remove duplicate tests and add another --- .../paper-navigation-bar.test.ts | 22 ++++++- .../project-navigation-bar.test.ts | 15 ----- .../simple-navigation-bar.test.ts | 63 +------------------ 3 files changed, 23 insertions(+), 77 deletions(-) diff --git a/test/integration/navigation-bar/paper-navigation-bar.test.ts b/test/integration/navigation-bar/paper-navigation-bar.test.ts index e72fb3ba..f7144f93 100644 --- a/test/integration/navigation-bar/paper-navigation-bar.test.ts +++ b/test/integration/navigation-bar/paper-navigation-bar.test.ts @@ -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"; @@ -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")); + }); }); diff --git a/test/integration/navigation-bar/project-navigation-bar.test.ts b/test/integration/navigation-bar/project-navigation-bar.test.ts index 3425fcfb..504cb95a 100644 --- a/test/integration/navigation-bar/project-navigation-bar.test.ts +++ b/test/integration/navigation-bar/project-navigation-bar.test.ts @@ -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", ); @@ -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(); diff --git a/test/integration/navigation-bar/simple-navigation-bar.test.ts b/test/integration/navigation-bar/simple-navigation-bar.test.ts index 843d92bd..ebdb4632 100644 --- a/test/integration/navigation-bar/simple-navigation-bar.test.ts +++ b/test/integration/navigation-bar/simple-navigation-bar.test.ts @@ -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();