Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Nov 3, 2023
1 parent d929214 commit 934dd55
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 71 deletions.
6 changes: 3 additions & 3 deletions app/static/src/app/components/SessionInitialiseModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import { computed, defineProps, defineEmits } from "vue";
import userMessages from "../userMessages";
const props = defineProps({
open: Boolean
open: Boolean
});
const emit = defineEmits(["newSession", "reloadSession"]);
const modalStyle = computed(() => {
return { display: props.open ? "block" : "none" };
return { display: props.open ? "block" : "none" };
});
const modalText = userMessages.sessions.initialise;
</script>
</script>
18 changes: 11 additions & 7 deletions app/static/src/app/components/WodinSession.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

<script lang="ts">
import {
computed,
defineComponent, onMounted, Ref, ref, watch
computed,
defineComponent, onMounted, Ref, ref, watch
} from "vue";
import { RouterView } from "vue-router";
import { useStore } from "vuex";
import SessionInitialiseModal from "./SessionInitialiseModal.vue";
import { AppStateAction } from "../store/appState/actions";
import { ErrorsMutation } from "../store/errors/mutations";
import { localStorageManager } from "../localStorageManager";
import {AppStateGetter} from "../store/appState/getters";
import {SessionMetadata} from "../types/responseTypes";
import { AppStateGetter } from "../store/appState/getters";
import { SessionMetadata } from "../types/responseTypes";
export default defineComponent({
name: "WodinSession",
Expand All @@ -43,6 +43,8 @@ export default defineComponent({
const appInitialised = computed(() => !!store.state.config && !!store.state.sessions.sessionsMetadata);
const latestSessionId: Ref<null|string> = ref(null);
// These props won't change as provided by server
// eslint-disable-next-line vue/no-setup-props-destructure
const {
appName,
baseUrl,
Expand Down Expand Up @@ -75,12 +77,14 @@ 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 - initialise as soon as config available
const sessions = localStorageManager.getSessionIds(store.state.appName, store.getters[AppStateGetter.baseUrlPath]);
const baseUrlPath = store.getters[AppStateGetter.baseUrlPath];
const sessions = localStorageManager.getSessionIds(store.state.appName, baseUrlPath);
const sessionId = sessions.length ? sessions[0] : null;
// check latest session id is actually available from the back end
const sessionAvailable = sessionId && !!store.state.sessions.sessionsMetadata.find((s: SessionMetadata) => s.id === sessionId);
const sessionAvailable = sessionId
&& !!store.state.sessions.sessionsMetadata.find((s: SessionMetadata) => s.id === sessionId);
if (sessionAvailable) {
latestSessionId.value = sessionId;
latestSessionId.value = sessionId;
}
if (newValue && (loadSessionId || !latestSessionId.value)) {
Expand Down
6 changes: 3 additions & 3 deletions app/static/src/app/components/sessions/SessionsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ import {
} from "vue";
import { useStore } from "vuex";
import VueFeather from "vue-feather";
import {RouterLink, useRouter} from "vue-router";
import { RouterLink, useRouter } from "vue-router";
import { AppStateAction } from "../../store/appState/actions";
import { SessionsAction } from "../../store/sessions/actions";
import userMessages from "../../userMessages";
Expand Down Expand Up @@ -292,8 +292,8 @@ export default defineComponent({
};
const newSession = () => {
store.dispatch(AppStateAction.InitialiseSession, { loadSessionId: "", copySession: true });
router.push("/");
store.dispatch(AppStateAction.InitialiseSession, { loadSessionId: "", copySession: true });
router.push("/");
};
const loadSessionFromCode = () => {
Expand Down
4 changes: 2 additions & 2 deletions app/static/src/app/store/appState/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FitState } from "../fit/state";
import { SessionsAction } from "../sessions/actions";
import { localStorageManager } from "../../localStorageManager";
import { AppStateGetter } from "./getters";
import {InitialiseAppPayload, InitialiseSessionPayload} from "../../types/payloadTypes";
import { InitialiseAppPayload, InitialiseSessionPayload } from "../../types/payloadTypes";

export enum AppStateAction {
InitialiseApp = "InitialiseApp",
Expand All @@ -36,7 +36,7 @@ async function immediateUploadState(context: ActionContext<AppState, AppState>)

export const appStateActions: ActionTree<AppState, AppState> = {
async [AppStateAction.InitialiseApp](context, payload: InitialiseAppPayload) {
const { commit, dispatch} = context;
const { commit, dispatch } = context;
const {
appName,
baseUrl,
Expand Down
2 changes: 1 addition & 1 deletion app/static/src/app/store/appState/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { VersionsState } from "../versions/state";
import { GraphSettingsState } from "../graphSettings/state";
import { LanguageState } from "../../../../translationPackage/store/state";
import { MultiSensitivityState } from "../multiSensitivity/state";
import {SessionsState} from "../sessions/state";
import { SessionsState } from "../sessions/state";

export enum AppType {
Basic = "basic",
Expand Down
8 changes: 4 additions & 4 deletions app/static/tests/e2e/sessions.etest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ test.describe("Sessions tests", () => {
await loadAppPage(page);

// We don't see the modal on load first session...
await expect(await page.locator("#session-initialise-modal .modal")).not.toBeVisible({timeout});
await expect(await page.locator("#session-initialise-modal .modal")).not.toBeVisible({ timeout });

// ..but we should on the second
await loadAppPage(page);
await expect(await page.locator("#session-initialise-modal .modal")).toBeVisible({timeout});
await expect(await page.locator("#session-initialise-modal .modal")).toBeVisible({ timeout });

// select new session and make some changes, including set label
await page.click("#new-session");
await expect(await page.locator("#session-initialise-modal .modal")).not.toBeVisible({timeout});
await expect(await page.locator("#session-initialise-modal .modal")).not.toBeVisible({ timeout });

await page.click(":nth-match(.wodin-left .nav-tabs a, 2)"); // select code tab
await writeCode(page, newFitCode);
Expand All @@ -311,7 +311,7 @@ test.describe("Sessions tests", () => {

// refresh page and select reload latest - should see the changes and new label
await loadAppPage(page);
await expect(await page.locator("#session-initialise-modal .modal")).toBeVisible({timeout});
await expect(await page.locator("#session-initialise-modal .modal")).toBeVisible({ timeout });
await page.click("#reload-session");
await page.click(":nth-match(.wodin-left .nav-tabs a, 2)"); // select code tab
await expectNewFitCode(page);
Expand Down
2 changes: 1 addition & 1 deletion app/static/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { LanguageState } from "../translationPackage/store/state";
import { Language } from "../src/app/types/languageTypes";
import { noSensitivityUpdateRequired } from "../src/app/store/sensitivity/sensitivity";
import { MultiSensitivityState } from "../src/app/store/multiSensitivity/state";
import {SessionsState} from "../src/app/store/sessions/state";
import { SessionsState } from "../src/app/store/sessions/state";

export const mockAxios = new MockAdapter(axios);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {shallowMount} from "@vue/test-utils";
import { shallowMount } from "@vue/test-utils";
import SessionInitialiseModal from "../../../src/app/components/SessionInitialiseModal.vue";

describe("SessionInitialiseModal", () => {
Expand All @@ -9,7 +9,8 @@ describe("SessionInitialiseModal", () => {
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("#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?");
Expand All @@ -35,4 +36,4 @@ describe("SessionInitialiseModal", () => {
await wrapper.find("button#reload-session").trigger("click");
expect(wrapper.emitted().reloadSession.length).toBe(1);
});
});
});
18 changes: 9 additions & 9 deletions app/static/tests/unit/components/sessions/sessionsPage.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const mockRouter = {
push: jest.fn()
};
jest.mock("vue-router", () => ({
useRouter: jest.fn().mockImplementation(() => mockRouter)
}));

import {shallowMount} from "@vue/test-utils";
import { shallowMount } from "@vue/test-utils";
import Vuex from "vuex";
import VueFeather from "vue-feather";
import { nextTick } from "vue";
Expand All @@ -19,6 +12,13 @@ import EditSessionLabel from "../../../../src/app/components/sessions/EditSessio
import ConfirmModal from "../../../../src/app/components/ConfirmModal.vue";
import { AppStateAction } from "../../../../src/app/store/appState/actions";

const mockRouter = {
push: jest.fn()
};
jest.mock("vue-router", () => ({
useRouter: jest.fn().mockImplementation(() => mockRouter)
}));

describe("SessionsPage", () => {
const mockGetSessions = jest.fn();
const mockGenerateFriendlyId = jest.fn();
Expand Down Expand Up @@ -407,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.mock.calls[0][1]).toStrictEqual({loadSessionId: "", copySession: true});
expect(mockInitialiseSession.mock.calls[0][1]).toStrictEqual({ loadSessionId: "", copySession: true });
expect(mockRouter.push).toHaveBeenCalledWith("/");
});
});
59 changes: 30 additions & 29 deletions app/static/tests/unit/components/wodinSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {shallowMount, VueWrapper} from "@vue/test-utils";
import { shallowMount, VueWrapper } from "@vue/test-utils";
import { RouterView } from "vue-router";
import Vuex, {Store} from "vuex";
import Vuex, { Store } from "vuex";
import { nextTick } from "vue";
import WodinSession from "../../../src/app/components/WodinSession.vue";
import { AppStateAction } from "../../../src/app/store/appState/actions";
import { mockBasicState} from "../../mocks";
import { mockBasicState } from "../../mocks";
import { BasicState } from "../../../src/app/store/basic/state";
import { ErrorsMutation } from "../../../src/app/store/errors/mutations";
import { Language } from "../../../src/app/types/languageTypes";
import {AppConfigBase, SessionMetadata} from "../../../src/app/types/responseTypes";
import { AppConfigBase, SessionMetadata } from "../../../src/app/types/responseTypes";
import SessionInitialiseModal from "../../../src/app/components/SessionInitialiseModal.vue";
import {mutations as sessionsMutations, SessionsMutation} from "../../../src/app/store/sessions/mutations";
import {getters as appStateGetters} from "../../../src/app/store/appState/getters";
import {localStorageManager} from "../../../src/app/localStorageManager";
import {nextTick} from "vue";
import {LanguageState} from "../../../translationPackage/store/state";
import {InitialiseSessionPayload} from "../../../src/app/types/payloadTypes";
import { mutations as sessionsMutations, SessionsMutation } from "../../../src/app/store/sessions/mutations";
import { getters as appStateGetters } from "../../../src/app/store/appState/getters";
import { localStorageManager } from "../../../src/app/localStorageManager";
import { LanguageState } from "../../../translationPackage/store/state";
import { InitialiseSessionPayload } from "../../../src/app/types/payloadTypes";

const realLocation = window.location;

Expand Down Expand Up @@ -52,7 +52,7 @@ describe("WodinSession", () => {
language: LanguageState,
config: Partial<AppConfigBase> | null,
sessionsMetadata: Partial<SessionMetadata>[] | null
};
}

const defaultStoreOptions = {
appName: "test",
Expand Down Expand Up @@ -123,7 +123,7 @@ describe("WodinSession", () => {
global: {
plugins: [store]
},
props: {...defaultProps, ...props}
props: { ...defaultProps, ...props }
};

return shallowMount(WodinSession, options);
Expand Down Expand Up @@ -154,14 +154,14 @@ describe("WodinSession", () => {
});

it("does not show modal when app is not initialised (no app config)", () => {
const wrapper = getWrapper(getStore({config: null}));
const wrapper = getWrapper(getStore({ config: null }));
expect(wrapper.findComponent(SessionInitialiseModal).props("open")).toBe(false);
// router view is also not shown yet
expect(wrapper.findComponent(RouterView).exists()).toBe(false);
});

it("does not show modal when app is not initialised (no sessions metadata)", () => {
const wrapper = getWrapper(getStore({sessionsMetadata: null}));
const wrapper = getWrapper(getStore({ sessionsMetadata: null }));
expect(wrapper.findComponent(SessionInitialiseModal).props("open")).toBe(false);
});

Expand All @@ -174,7 +174,7 @@ describe("WodinSession", () => {
});

it("adds expected error when shareNotFound prop is set", () => {
const wrapper = getWrapper(getStore(), {shareNotFound: "cheeky-monkey"});
const wrapper = getWrapper(getStore(), { shareNotFound: "cheeky-monkey" });
expect(wrapper.findComponent(RouterView).exists()).toBe(true);
expect(mockAddError).toHaveBeenCalledTimes(1);
expect(mockAddError.mock.calls[0][1]).toStrictEqual({ detail: "Share id not found: cheeky-monkey" });
Expand All @@ -183,16 +183,17 @@ describe("WodinSession", () => {
it("initialises new session when selected in modal", async () => {
const wrapper = getWrapper(getStore());
await wrapper.findComponent(SessionInitialiseModal).vm.$emit("newSession");
expect(mockInitialiseSession.mock.calls[0][1]).toStrictEqual({loadSessionId: "", copySession: true});
expect(mockInitialiseSession.mock.calls[0][1]).toStrictEqual({ loadSessionId: "", copySession: true });
expect(wrapper.findComponent(SessionInitialiseModal).props("open")).toBe(false);
});

const initialiseAppSessionsMetadata = async (store: Store<BasicState>, sessionMetadata = [{id: "1234"}]) => {
const initialiseAppSessionsMetadata = async (store: Store<BasicState>, sessionMetadata = [{ id: "1234" }]) => {
store!.commit(`sessions/${SessionsMutation.SetSessionsMetadata}`, sessionMetadata);
await nextTick();
};

const expectImmediateInitialiseSession = (wrapper: VueWrapper<any>, initialisePayload: InitialiseSessionPayload, getSessionIds: jest.SpyInstance) => {
const expectImmediateInitialiseSession = (wrapper: VueWrapper<any>, initialisePayload: InitialiseSessionPayload,
getSessionIds: jest.SpyInstance) => {
expect(mockInitialiseSession.mock.calls[0][1]).toStrictEqual(initialisePayload);
expect(wrapper.findComponent(SessionInitialiseModal).props("open")).toBe(false);
expect(getSessionIds).toHaveBeenCalledWith("test", "site1");
Expand All @@ -201,38 +202,38 @@ describe("WodinSession", () => {
it("initialises reload of most recent session when selected in modal", async () => {
// this requires that we update appInitialise to trigger the watch which initialises latestSessionId
const getSessionIds = mockGetSessionIds();
const store = getStore({sessionsMetadata: null});
const store = getStore({ sessionsMetadata: null });
const wrapper = getWrapper(store);
await initialiseAppSessionsMetadata(store);

await wrapper.findComponent(SessionInitialiseModal).vm.$emit("reloadSession");
expectImmediateInitialiseSession(wrapper, {loadSessionId: "1234", copySession: false}, getSessionIds);
expectImmediateInitialiseSession(wrapper, { loadSessionId: "1234", copySession: false }, getSessionIds);
});

it("initialises session immediately on appInitialised if loadSessionId is set", async () => {
const getSessionIds = mockGetSessionIds();
const store = getStore({sessionsMetadata: null});
const wrapper = getWrapper(store, {loadSessionId: "abcd"});
const store = getStore({ sessionsMetadata: null });
const wrapper = getWrapper(store, { loadSessionId: "abcd" });
await initialiseAppSessionsMetadata(store);

expectImmediateInitialiseSession(wrapper, {loadSessionId: "abcd", copySession: true}, getSessionIds);
expectImmediateInitialiseSession(wrapper, { loadSessionId: "abcd", copySession: true }, getSessionIds);
});

it("initialises new session immediately on appInitialised if no session ids in local storage", async () => {
const getSessionIds = mockGetSessionIds([]);
const store = getStore({sessionsMetadata: null});
const store = getStore({ sessionsMetadata: null });
const wrapper = getWrapper(store);
await initialiseAppSessionsMetadata(store);

expectImmediateInitialiseSession(wrapper, {loadSessionId: "", copySession: true}, getSessionIds);
expectImmediateInitialiseSession(wrapper, { loadSessionId: "", copySession: true }, getSessionIds);
});

it("initialises new session immediately on appInitialised if latest session id not available in sessions metadata", async () => {
it("initialises new session immediately on appInitialised if latest session not in sessions metadata", async () => {
const getSessionIds = mockGetSessionIds();
const store = getStore({sessionsMetadata: null});
const store = getStore({ sessionsMetadata: null });
const wrapper = getWrapper(store);
await initialiseAppSessionsMetadata(store, [{id: "5678"}]);
await initialiseAppSessionsMetadata(store, [{ id: "5678" }]);

expectImmediateInitialiseSession(wrapper, {loadSessionId: "", copySession: true}, getSessionIds);
expectImmediateInitialiseSession(wrapper, { loadSessionId: "", copySession: true }, getSessionIds);
});
});
Loading

0 comments on commit 934dd55

Please sign in to comment.