Skip to content

Commit

Permalink
SessionInitialiseModal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Nov 1, 2023
1 parent 8981e3d commit f8f71d9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/static/src/app/components/WodinSession.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export default defineComponent({
};
watch(appInitialised, (newValue) => {
// We don't need to show session initialise modal if we have a
// loadSessionId (loading from share) or if there are no previous sessions
// We don't need to show session initialise modal if we have a loadSessionId (loading from share) or if
// there are no previous sessions - initialise as soon as config available
const sessions = localStorageManager.getSessionIds(store.state.appName, store.getters[AppStateGetter.baseUrlPath]);
const sessionId = sessions.length ? sessions[0] : null;
// check latest session id is actually available from the back end
Expand Down
38 changes: 38 additions & 0 deletions app/static/tests/unit/components/SessionInitialiseModal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {shallowMount} from "@vue/test-utils";
import SessionInitialiseModal from "../../../src/app/components/SessionInitialiseModal.vue";

describe("SessionInitialiseModal", () => {
const getWrapper = (open = true) => {
return shallowMount(SessionInitialiseModal, { props: { open } });
};

it("renders as expected when open is true", () => {
const wrapper = getWrapper();
expect(wrapper.find("#session-initialise-modal .modal").classes()).toContain("show");
expect((wrapper.find("#session-initialise-modal .modal").element as HTMLDivElement).style.display).toBe("block");
expect(wrapper.find(".modal-backdrop").exists()).toBe(true);
expect(wrapper.find(".modal-body").text())
.toBe("Would you like to reload the most recent session or start a new session?");
expect(wrapper.find("button#reload-session").text()).toBe("Reload session");
expect(wrapper.find("button#new-session").text()).toBe("New session");
});

it("renders as expected when open is false", () => {
const wrapper = getWrapper(false);
expect(wrapper.find("#session-initialise-modal .modal").classes()).not.toContain("show");
expect((wrapper.find("#session-initialise-modal .modal").element as HTMLDivElement).style.display).toBe("none");
expect(wrapper.find(".modal-backdrop").exists()).toBe(false);
});

it("emits on new session", async () => {
const wrapper = getWrapper();
await wrapper.find("button#new-session").trigger("click");
expect(wrapper.emitted().newSession.length).toBe(1);
});

it("emits on reload session", async () => {
const wrapper = getWrapper();
await wrapper.find("button#reload-session").trigger("click");
expect(wrapper.emitted().reloadSession.length).toBe(1);
});
});

0 comments on commit f8f71d9

Please sign in to comment.