Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThorntonMatthewD committed Oct 16, 2023
1 parent d48dbfa commit fddc752
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/tests/stores/ui.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, it, expect } from "vitest";
import { setActivePinia, createPinia } from "pinia";
import { useUIStore } from "../../stores/ui";

describe("uiStore", () => {
const primeTheStore = (initBannerVisibility: boolean | null) => {
if (initBannerVisibility !== null) {
sessionStorage.setItem(
"disableHGLabsMapBanner",
initBannerVisibility.toString(),
);
}

setActivePinia(createPinia());
};

it("Upon first visit showContributionBanner is true", () => {
primeTheStore(null);

const uiStore = useUIStore();
expect(uiStore.showContributionBanner).toStrictEqual(true);
});

it("User closes the banner", () => {
primeTheStore(null);
expect(sessionStorage.getItem("disableHGLabsMapBanner")).toStrictEqual(
null,
);

const uiStore = useUIStore();
//Action triggered once someone closes the banner
uiStore.setShowContributionBanner(false);

expect(sessionStorage.getItem("disableHGLabsMapBanner")).toStrictEqual(
"false",
);
expect(uiStore.showContributionBanner).toStrictEqual(false);
});

it("User reloads page after previously closing banner in session", () => {
primeTheStore(false);

const uiStore = useUIStore();

expect(sessionStorage.getItem("disableHGLabsMapBanner")).toStrictEqual(
"false",
);
expect(uiStore.showContributionBanner).toStrictEqual(false);
});
});

0 comments on commit fddc752

Please sign in to comment.