Skip to content

Commit

Permalink
more sessions page tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Nov 2, 2023
1 parent 79021ca commit 7e4469c
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions app/static/tests/unit/components/sessions/sessionsPage.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { shallowMount } from "@vue/test-utils";
const mockRouter = {
push: jest.fn()
};
jest.mock("vue-router", () => ({
useRouter: jest.fn().mockImplementation(() => mockRouter)
}));

import {shallowMount} from "@vue/test-utils";
import Vuex from "vuex";
import VueFeather from "vue-feather";
import { RouterLink } from "vue-router";
import { nextTick } from "vue";
import SessionsPage from "../../../../src/app/components/sessions/SessionsPage.vue";
import ErrorsAlert from "../../../../src/app/components/ErrorsAlert.vue";
Expand All @@ -22,10 +28,6 @@ describe("SessionsPage", () => {
const mockLoadUserPreferences = jest.fn();
const mockInitialiseSession = jest.fn();

const mockRouter = {
push: jest.fn()
};

Object.assign(window.navigator, {
clipboard: {
writeText: mockClipboardWriteText
Expand Down Expand Up @@ -71,9 +73,6 @@ describe("SessionsPage", () => {
const options = {
global: {
plugins: [store]
},
mocks: {
$router: mockRouter
}
};

Expand All @@ -98,7 +97,7 @@ describe("SessionsPage", () => {
expect(rows.at(0)!.find("h2").text()).toBe("Sessions");

const currentSessionRow = rows.at(1)!;
expect(currentSessionRow.findComponent(RouterLink).props("to")).toBe("/");
expect(currentSessionRow.find("router-link").attributes("to")).toBe("/");
expect(currentSessionRow.find("a").text()).toBe("make a copy of the current session.");
expect(currentSessionRow.find("a").attributes("href"))
.toBe("http://localhost:3000/apps/testApp/?sessionId=abc");
Expand Down Expand Up @@ -186,7 +185,7 @@ describe("SessionsPage", () => {
expect(wrapper.find("#no-current-session").exists()).toBe(false);
const current = wrapper.find("#current-session");
expect(current.exists()).toBe(true);
expect(current.findComponent(RouterLink).props("to")).toBe("/");
expect(current.find("router-link").attributes("to")).toBe("/");
expect(current.find("a").text()).toBe("make a copy of the current session.");

expect(wrapper.find("h3").text()).toBe("Previous sessions");
Expand Down Expand Up @@ -362,11 +361,6 @@ describe("SessionsPage", () => {
window.location = realLocation;
});

it("loads user preferences on mount", () => {
const wrapper = getWrapper(sessionsMetadata, currentSessionId);
expect(mockLoadUserPreferences).toHaveBeenCalledTimes(1);
});

it("can save show unlabelled sessions preference", async () => {
const wrapper = getWrapper(sessionsMetadata, currentSessionId);
await wrapper.find("input#show-unlabelled-check").trigger("click");
Expand All @@ -387,7 +381,7 @@ describe("SessionsPage", () => {
const rows = wrapper.findAll(".container .row");

const currentSessionRow = rows.at(1)!;
expect(currentSessionRow.findComponent(RouterLink).props("to")).toBe("/");
expect(currentSessionRow.find("router-link").attributes("to")).toBe("/");
expect(currentSessionRow.find("a").text()).toBe("make a copy of the current session.");
expect(currentSessionRow.find("a").attributes("href"))
.toBe("http://localhost:3000/apps/testApp/?sessionId=abc");
Expand All @@ -413,7 +407,7 @@ describe("SessionsPage", () => {
it("clicking start session initialises session and navigates to app homepage", async () => {
const wrapper = getWrapper(sessionsMetadata, undefined);
await wrapper.find("span#start-session").trigger("click");
expect(mockInitialiseSession).toHaveBeenCalledWith({loadSessionId: "", copySession: true});
expect(mockInitialiseSession.mock.calls[0][1]).toStrictEqual({loadSessionId: "", copySession: true});
expect(mockRouter.push).toHaveBeenCalledWith("/");
});
});

0 comments on commit 7e4469c

Please sign in to comment.