Skip to content

Commit

Permalink
session page tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Nov 2, 2023
1 parent b3c6456 commit 79021ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/static/src/app/components/sessions/SessionsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<div class="row mb-3" id="no-current-session" v-if="!currentSession">
<span>
<span class="brand-link clickable" @click="newSession">
<span id="start-session" class="brand-link clickable" @click="newSession">
Start a new session
</span>
<span v-if="previousSessions && previousSessions.length" id="load-previous-span">
Expand Down Expand Up @@ -292,7 +292,7 @@ export default defineComponent({
};
const newSession = () => {
store.dispatch(AppStateAction.InitialiseSession, { loadSessionId: "", copySession: false });
store.dispatch(AppStateAction.InitialiseSession, { loadSessionId: "", copySession: true });
router.push("/");
};
Expand Down
22 changes: 19 additions & 3 deletions app/static/tests/unit/components/sessions/sessionsPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ describe("SessionsPage", () => {
const mockDeleteSession = jest.fn();
const mockSaveUserPreferences = jest.fn();
const mockLoadUserPreferences = jest.fn();
const mockInitialiseSession = jest.fn();

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

Object.assign(window.navigator, {
clipboard: {
Expand All @@ -45,7 +50,8 @@ describe("SessionsPage", () => {
}),
actions: {
[AppStateAction.SaveUserPreferences]: mockSaveUserPreferences,
[AppStateAction.LoadUserPreferences]: mockLoadUserPreferences
[AppStateAction.LoadUserPreferences]: mockLoadUserPreferences,
[AppStateAction.InitialiseSession]: mockInitialiseSession
} as any,
modules: {
sessions: {
Expand All @@ -65,6 +71,9 @@ describe("SessionsPage", () => {
const options = {
global: {
plugins: [store]
},
mocks: {
$router: mockRouter
}
};

Expand Down Expand Up @@ -164,7 +173,7 @@ describe("SessionsPage", () => {
expect(wrapper.find("#current-session").exists()).toBe(false);
const noCurrent = wrapper.find("#no-current-session");
expect(noCurrent.exists()).toBe(true);
expect(noCurrent.findComponent(RouterLink).props("to")).toBe("/");
expect(noCurrent.find("span#start-session").text()).toBe("Start a new session");
expect(noCurrent.find("#load-previous-span").text()).toBe("or load a previous session.");

expect(wrapper.find("#previous-sessions-headers").exists()).toBe(true);
Expand All @@ -191,7 +200,7 @@ describe("SessionsPage", () => {
expect(wrapper.find("#current-session").exists()).toBe(false);
const noCurrent = wrapper.find("#no-current-session");
expect(noCurrent.exists()).toBe(true);
expect(noCurrent.findComponent(RouterLink).props("to")).toBe("/");
expect(noCurrent.find("span#start-session").text()).toBe("Start a new session");
expect(noCurrent.find("#load-previous-span").exists()).toBe(false);

expect(wrapper.find("#previous-sessions-headers").exists()).toBe(false);
Expand Down Expand Up @@ -400,4 +409,11 @@ describe("SessionsPage", () => {
expect((wrapper.find("input#show-unlabelled-check").element as HTMLInputElement).checked).toBe(false);
expect((wrapper.find("input#show-duplicates-check").element as HTMLInputElement).checked).toBe(true);
});

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(mockRouter.push).toHaveBeenCalledWith("/");
});
});

0 comments on commit 79021ca

Please sign in to comment.