diff --git a/app/static/src/app/components/WodinSession.vue b/app/static/src/app/components/WodinSession.vue index c49138b53..b4593cb9f 100644 --- a/app/static/src/app/components/WodinSession.vue +++ b/app/static/src/app/components/WodinSession.vue @@ -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 diff --git a/app/static/tests/unit/components/SessionInitialiseModal.test.ts b/app/static/tests/unit/components/SessionInitialiseModal.test.ts new file mode 100644 index 000000000..3c79d946f --- /dev/null +++ b/app/static/tests/unit/components/SessionInitialiseModal.test.ts @@ -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); + }); +}); \ No newline at end of file