Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Oct 28, 2024
1 parent 50067b9 commit 3d1a804
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
18 changes: 6 additions & 12 deletions tests/unit/components/AppHeader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import AppHeader from "@/components/AppHeader.vue";
import { mountSuspended } from "@nuxt/test-utils/runtime";
import { waitFor } from "@testing-library/vue";
import { mockVersions } from "../mocks/mockPinia";

const stubs = {
CIcon: true,
};

const versionTooltipContent = `Model version: ${mockVersions.daedalusModel} \nR API version: ${mockVersions.daedalusApi} \nWeb app version: ${mockVersions.daedalusWebApp}`;

describe("app header", () => {
it('emits "toggleSidebarVisibility" event when CHeaderToggler is clicked', async () => {
const component = await mountSuspended(AppHeader, { global: { stubs }, props: { versionTooltipContent } });
const component = await mountSuspended(AppHeader, { global: { stubs } });

await component.findComponent({ name: "CHeaderToggler" }).vm.$emit("click");
expect(component.emitted()).toHaveProperty("toggleSidebarVisibility");
Expand All @@ -21,7 +18,7 @@ describe("app header", () => {
const addEventListenerSpy = vi.spyOn(window, "addEventListener");
const removeEventListenerSpy = vi.spyOn(window, "removeEventListener");

const component = await mountSuspended(AppHeader, { global: { stubs }, props: { versionTooltipContent } });
const component = await mountSuspended(AppHeader, { global: { stubs } });
expect(addEventListenerSpy).toHaveBeenCalledWith("scroll", expect.any(Function));

const header = component.findComponent({ name: "CHeader" });
Expand All @@ -44,20 +41,17 @@ describe("app header", () => {
removeEventListenerSpy.mockRestore();
});

it("should render logo and include information about the version numbers", async () => {
it("should render logo", async () => {
const component = await mountSuspended(AppHeader, {
props: { versionTooltipContent },
global: { stubs },
});

await waitFor(() => {
const logoTitleAttribute = component
const logoSrcAttribute = component
.find(`[data-testid="ji-logo-header"]`)
.attributes()
.title;
expect(logoTitleAttribute).toContain("Model version: 1.2.3");
expect(logoTitleAttribute).toContain("R API version: 4.5.6");
expect(logoTitleAttribute).toContain("Web app version: 7.8.9");
.src;
expect(logoSrcAttribute).toContain("IMPERIAL_JAMEEL_INSTITUTE");
});
});
});
19 changes: 7 additions & 12 deletions tests/unit/components/SideBar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { VueWrapper } from "@vue/test-utils";
import SideBar from "@/components/SideBar.vue";
import { mockPinia, mockVersions } from "@/tests/unit/mocks/mockPinia";
import { mockPinia } from "@/tests/unit/mocks/mockPinia";
import { mountSuspended } from "@nuxt/test-utils/runtime";
import { waitFor } from "@testing-library/vue";

Expand All @@ -13,7 +13,6 @@ const mockCSidebarPageloadBehavior = async (coreuiSidebar: VueWrapper) => {
coreuiSidebar.vm.$emit("hide");
};

const versionTooltipContent = `Model version: ${mockVersions.daedalusModel} \nR API version: ${mockVersions.daedalusApi} \nWeb app version: ${mockVersions.daedalusWebApp}`;
describe("sidebar", () => {
describe('when the "visible" prop is initialized as false', () => {
describe("on smaller devices", () => {
Expand All @@ -23,7 +22,7 @@ describe("sidebar", () => {

it('starts as hidden, and can be opened by setting "visible" prop', async () => {
const component = await mountSuspended(SideBar, {
props: { visible: false, versionTooltipContent },
props: { visible: false },
global: { stubs, plugins },
});
const coreuiSidebar = component.findComponent({ name: "CSidebar" });
Expand All @@ -38,20 +37,18 @@ describe("sidebar", () => {
expect(coreuiSidebar.props("unfoldable")).toBe(false);
});

it("should render logo and include information about the version numbers", async () => {
it("should render logo", async () => {
const component = await mountSuspended(SideBar, {
props: { visible: false, versionTooltipContent },
props: { visible: false },
global: { stubs, plugins },
});

await waitFor(() => {
const logoTitleAttribute = component
const logoSrcAttribute = component
.find(`[data-testid="ji-logo-sidebar"]`)
.attributes()
.title;
expect(logoTitleAttribute).toContain("Model version: 1.2.3");
expect(logoTitleAttribute).toContain("R API version: 4.5.6");
expect(logoTitleAttribute).toContain("Web app version: 7.8.9");
.src;
expect(logoSrcAttribute).toContain("IMPERIAL_JAMEEL_INSTITUTE");
});
});
});
Expand All @@ -63,7 +60,6 @@ describe("sidebar", () => {

it("starts as shown", async () => {
const component = await mountSuspended(SideBar, {
props: { visible: false, versionTooltipContent },
global: { stubs, plugins },
});
const coreuiSidebar = component.findComponent({ name: "CSidebar" });
Expand All @@ -75,7 +71,6 @@ describe("sidebar", () => {

it("renders the text and href for nav items", async () => {
const component = await mountSuspended(SideBar, {
props: { visible: false, versionTooltipContent },
global: { stubs, plugins },
});
const coreuiSidebar = component.findComponent({ name: "CSidebar" });
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/pages/About.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import About from "@/pages/about.vue";
import { mountSuspended } from "@nuxt/test-utils/runtime";
import { describe, expect, it } from "vitest";
import { countryAndPathogenParams, mockedMetadata, mockPinia } from "../mocks/mockPinia";
import { countryAndPathogenParams, mockedMetadata, mockPinia, mockVersions } from "../mocks/mockPinia";

describe("about page", () => {
it("should render about with correct metadata info", async () => {
const numberOfPandemics = countryAndPathogenParams.find(p => p.id === "pathogen")!.options!.length;
const numberOfCountries = countryAndPathogenParams.find(p => p.id === "country")!.options!.length;
const component = await mountSuspended(About, { global: { plugins: [mockPinia({
metadata: { ...mockedMetadata, parameters: countryAndPathogenParams as any },
versions: mockVersions,
})] } });

const text = component.text();
Expand All @@ -19,5 +20,8 @@ describe("about page", () => {
for (const estimate of mockedMetadata.results.time_series_groups) {
expect(text).toContain(estimate.label);
}
expect(text).toContain("Model version: 1.2.3");
expect(text).toContain("R API version: 4.5.6");
expect(text).toContain("Web app version: 7.8.9");
});
});

0 comments on commit 3d1a804

Please sign in to comment.