diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index a0883508..66c36158 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -135,7 +135,7 @@ export default { const glassPartsForStore = partsLookup.data.glassPieceParts; // TODO KO delete for quote mvp - this.navigateForward(glassPartsForStore, null, this.shouldGoToHeritageQuote); + this.navigateForward(glassPartsForStore, null); }, }, components: { diff --git a/src/router/index.js b/src/router/index.js index 4c3f435e..708a61e7 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -5,6 +5,7 @@ import { routingTable } from "@/router/router-constants/routing-table"; import { useMainStore } from '@/store'; import eventBus from "@/helpers/event-bus/event-bus"; import { globalEvents, globalEventTypes } from "@/constants/events"; +import baseMixin from "@/mixins/base-mixin"; import analyticsMixin from "@/mixins/analytics-mixin"; @@ -87,14 +88,14 @@ async function GetRouteInfoFromPageName(pageName) { return routeData; }; -router.navigate = (scenario, currentRoute, optionalQuery = {}, optionalParams = {}) => { +router.navigate = (scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) => { - navigate(scenario, currentRoute, false, optionalQuery, optionalParams); + navigate(scenario, currentRoute, false, optionalQuery, optionalParams, optionalPageData); } // Navigate to the next route, depending on the scenario. -function navigate (scenario, currentRoute, optionalQuery = {}, optionalParams = {}) { +function navigate (scenario, currentRoute, optionalQuery = {}, optionalParams = {}, optionalPageData = {}) { if (!scenario) { console.error("No scenario provided. Please review the routing table."); return; @@ -109,6 +110,16 @@ function navigate (scenario, currentRoute, optionalQuery = {}, optionalParams = } if (matchingScenarioMap.destinationIssPageValue) { + + // Update page data to the store for next page if provided. Otherwise, keep existing page data or set to empty object + const existingPageDataForPage = useMainStore().pageData(matchingScenarioMap.destinationIssPageValue); + baseMixin.methods.savePageDataToStore( + matchingScenarioMap.destinationIssPageValue, + Object.keys(optionalPageData).length > 0 + ? optionalPageData + : existingPageDataForPage ?? {} + ); + // We're always pushing the same path, just changing query strings. Make sure our optional query strings get combined with our issPage one. router.push({ name: "root", diff --git a/src/router/router.spec.js b/src/router/router.spec.js index 521b382e..c21d2752 100644 --- a/src/router/router.spec.js +++ b/src/router/router.spec.js @@ -1,35 +1,19 @@ import router from "@/router/"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import { issPageValues } from "@/router/router-constants/issPage-values"; - import { createApp } from 'vue'; import { createPinia } from "pinia"; import App from '@/App.vue'; -const originalLocation = global.location - describe("Router", () => { beforeAll(() => { const vueApp = createApp(App); const pinia = createPinia(); vueApp.use(pinia); - }) - - it("Should change the location when navigating to external site", () => { - delete global.location - global.location = { assign: jest.fn() } - - let scenario = navigationScenarios.CLICKED_TEST; - let currentRoute = { query: { issPage: issPageValues.WELCOME_PAGE }}; - - router.navigate(scenario, currentRoute); - - expect(global.location.assign).toHaveBeenCalledTimes(1) - - global.location = originalLocation; }); + it("Should push next view when navigating locally", () => { let scenario = navigationScenarios.CLICKED_FORWARD; let currentRoute = { query: { issPage: issPageValues.WELCOME_PAGE }}; @@ -37,7 +21,7 @@ describe("Router", () => { router.push = jest.fn(); router.navigate(scenario, currentRoute); - expect(router.push.mock.calls[0][0].query.issPage).toBe(issPageValues.VEHICLE_YEAR) + expect(router.push.mock.calls[0][0].query.issPage).toBe(issPageValues.VEHICLE_YEAR); });