diff --git a/src/common-components/funnel-header/funnel-header.vue b/src/common-components/funnel-header/funnel-header.vue index f2934cb37..853363ec8 100644 --- a/src/common-components/funnel-header/funnel-header.vue +++ b/src/common-components/funnel-header/funnel-header.vue @@ -1,33 +1,64 @@ diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index baee845e4..3f258a310 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -3,6 +3,10 @@ const endpoints = { url: "/content/api/v1/content/RouteInfo", method: "POST", }, + GetHomepageInfo: { + url: "/content/api/v1/content/HomepageInfo", + method: "GET", + }, GetVehicleYears: { url: "/vehicle/api/v1/vehicle/years", method: "GET", diff --git a/src/constants/events.js b/src/constants/events.js new file mode 100644 index 000000000..91461d535 --- /dev/null +++ b/src/constants/events.js @@ -0,0 +1,17 @@ +const globalEvents = { + Categories: { + GLOBAL_ALERT: "GLOBAL_ALERT", + }, + SubCategories: { + PAGE_NOT_FOUND: "PAGE_NOT_FOUND", + } +} + +const globalEventTypes = { + Success: "alert-success", + Warning: "alert-warning", + Info: "alert-info", + Danger: "alert-danger", +} + +export {globalEvents, globalEventTypes} \ No newline at end of file diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index d052bed32..263f153df 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -1,5 +1,6 @@ const storeActions = { GET_ROUTE_INFO_ACTION: "getRouteInfo", + GET_HOMEPAGE_NAME: "getHomepageName", GET_PAGE_DATA: "getPageData", GET_VEHICLE_YEARS: "getVehicleYears", GET_VEHICLE_MAKES: "getVehicleMakes", @@ -10,6 +11,9 @@ const storeActions = { GET_EVOX_IMAGE: "getEvoxImage", LOOKUP_VEHICLE_BY_YMMS: "lookupVehicleByYmms", LOOKUP_VEHICLE_BY_VIN: "lookupVehicleByVin", + // EVENT BUS + ADD_EVENT_TO_BUS: "addEventToBus", + REMOVE_EVENT_FROM_BUS: "removeEventFromBus", }; export { storeActions }; diff --git a/src/constants/store-mutations.js b/src/constants/store-mutations.js index 61882b691..ba5aae017 100644 --- a/src/constants/store-mutations.js +++ b/src/constants/store-mutations.js @@ -4,6 +4,7 @@ const storeMutations = { UPDATE_MODEL: "updateModel", UPDATE_STYLE: "updateStyle", UPDATE_VEHICLE: "updateVehicle", + UPDATE_LAST_PAGE: "updateLastPage", }; export { storeMutations }; diff --git a/src/helpers/event-bus/event-bus.js b/src/helpers/event-bus/event-bus.js new file mode 100644 index 000000000..8ac156776 --- /dev/null +++ b/src/helpers/event-bus/event-bus.js @@ -0,0 +1,25 @@ +import store from "@/store"; +import { storeActions } from "@/constants/store-actions.js"; + +export default { + // Adds event to the bus given its category, subcategory, and eventValue; + addEventToBus(category, subCategory, eventValue) { + store.commit(storeActions.ADD_EVENT_TO_BUS, { category: category, subCategory: subCategory, eventValue: eventValue }); + }, + + // Finds event on the bus, removes the item, and returns its value to the caller. + readAndPopEventFromBus(category, subCategory) { + const event = store.getters.eventBusItem(category, subCategory); + + store.commit(storeActions.REMOVE_EVENT_FROM_BUS, { category: category, subCategory: subCategory }); + + return event; + }, + + // Finds the event on the bus and returns its value to the caller, does not remove it. + readEventFromBus(category, subCategory) { + const event = store.getters.eventBusItem(category, subCategory); + + return event; + }, +} \ No newline at end of file diff --git a/src/helpers/event-bus/event-bus.spec.js b/src/helpers/event-bus/event-bus.spec.js new file mode 100644 index 000000000..d20c11044 --- /dev/null +++ b/src/helpers/event-bus/event-bus.spec.js @@ -0,0 +1,50 @@ +import { globalEvents, globalEventTypes } from "@/constants/events"; +import eventBus from "@/helpers/event-bus/event-bus"; +import store from "@/store"; + +describe("event-bus.js", () => { + + let event = { + isDismissible: true, + messageCopy: 'You can get a quote by starting on this page.', + messageHeadline: 'We\'re sorry, something went wrong.', + type: globalEventTypes.Danger + }; + + it("Puts item on bus and then take it off", () => { + + // Arrange / Act + eventBus.addEventToBus( + globalEvents.Categories.GLOBAL_ALERT, + globalEvents.SubCategories.PAGE_NOT_FOUND, + event + ); + + + // Assert + expect(store.getters.eventBusItem(globalEvents.Categories.GLOBAL_ALERT, globalEvents.SubCategories.PAGE_NOT_FOUND)).toEqual(event); + + expect(store.state.applicationUser.eventBus.length).toEqual(1); + + // Arrange / Act + const eventValue = eventBus.readAndPopEventFromBus(globalEvents.Categories.GLOBAL_ALERT, globalEvents.SubCategories.PAGE_NOT_FOUND); + + // Assert + expect(eventValue).toEqual(event); + + expect(store.state.applicationUser.eventBus.length).toEqual(0); + }); + + it("Reads event from bus, should have event value.", () => { + // Arrange / Act + eventBus.addEventToBus( + globalEvents.Categories.GLOBAL_ALERT, + globalEvents.SubCategories.PAGE_NOT_FOUND, + event + ); + + // Assert + expect(eventBus.readEventFromBus(globalEvents.Categories.GLOBAL_ALERT, globalEvents.SubCategories.PAGE_NOT_FOUND)).toEqual(event); + + }); +}); \ No newline at end of file diff --git a/src/layouts/not-found/not-found.vue b/src/layouts/not-found/not-found.vue deleted file mode 100644 index 6c4cc8e33..000000000 --- a/src/layouts/not-found/not-found.vue +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/src/layouts/vehicle-damage/vehicle-damage.vue b/src/layouts/vehicle-damage/vehicle-damage.vue index ea77b4494..65e9a7bba 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.vue +++ b/src/layouts/vehicle-damage/vehicle-damage.vue @@ -22,7 +22,7 @@ import { storeActions } from "@/constants/store-actions"; export default ({ name: "vehicle-damage", - beforeRouteEnter(to, from, next) { + async beforeRouteEnter(to, from, next) { // Call APIs const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage); const damageOptionsPromise = baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.GET_DAMAGE_OPTIONS, {carId: store.getters.vehicle.carId}); @@ -39,21 +39,27 @@ export default ({ }, ]; - settleAllPromises(promiseResultMap).then((resultMap) => { - // Call the "next" function to complete the transition to this page. - next((vm) => { - vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget); - vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget); - vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget); - // use resultMap.damageOptions for damage options - }); - }); + const resultMap = await settleAllPromises(promiseResultMap); - }, - components: { - funnelHeader, - vehicleBanner, - funnelSubHeader, + // Call the "next" function to complete the transition to this page. + next((vm) => { + vm.$refs.funnelHeader.initializeComponent( + resultMap.cmsContent.FunnelHeaderWidget + ); + vm.$refs.vehicleBanner.initializeComponent( + resultMap.cmsContent.VehicleBannerWidget + ); + vm.$refs.funnelSubHeader.initializeComponent( + resultMap.cmsContent.FunnelSubHeaderWidget + ); + // use resultMap.damageOptions for damage options + }); + }, -}) + components: { + funnelHeader, + vehicleBanner, + funnelSubHeader, + }, +}); diff --git a/src/layouts/vehicle-make/vehicle-make.vue b/src/layouts/vehicle-make/vehicle-make.vue index 031ffb20b..823a8a74d 100644 --- a/src/layouts/vehicle-make/vehicle-make.vue +++ b/src/layouts/vehicle-make/vehicle-make.vue @@ -34,11 +34,11 @@ export default { }, computed: {}, - beforeRouteEnter(to, from, next) { - + async beforeRouteEnter(to, from, next) { // Call APIs const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage); - const makeQuestionInitialDataPromise = makeQuestion.methods.loadInitialData(); + const makeQuestionInitialDataPromise = + makeQuestion.methods.loadInitialData(); // Settle promises and get results const promiseResultMap = [ @@ -51,14 +51,24 @@ export default { promise: makeQuestionInitialDataPromise, }, ]; - settleAllPromises(promiseResultMap).then((resultMap) => { - // Call the "next" function to complete the transition to this page. - next((vm) => { - vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget); - vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget); - vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget); - vm.$refs.makeQuestion.initializeComponent(resultMap.cmsContent.VehicleMakeQuestion, resultMap.makeQuestionInitialData); - }); + + const resultMap = await settleAllPromises(promiseResultMap); + + // Call the "next" function to complete the transition to this page. + next((vm) => { + vm.$refs.funnelSubHeader.initializeComponent( + resultMap.cmsContent.FunnelSubHeaderWidget + ); + vm.$refs.funnelHeader.initializeComponent( + resultMap.cmsContent.FunnelHeaderWidget + ); + vm.$refs.vehicleBanner.initializeComponent( + resultMap.cmsContent.VehicleBannerWidget + ); + vm.$refs.makeQuestion.initializeComponent( + resultMap.cmsContent.VehicleMakeQuestion, + resultMap.makeQuestionInitialData + ); }); }, @@ -66,14 +76,17 @@ export default { backButtonAction() { // route to move backwards this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route); - } + }, }, watch: { selectedMake(make) { this.$store.commit(this.storeMutations.UPDATE_MAKE, make); - this.$router.navigate(this.navigationScenarios.SELECTED_MAKE, this.$route); - } + this.$router.navigate( + this.navigationScenarios.SELECTED_MAKE, + this.$route + ); + }, }, components: { diff --git a/src/layouts/vehicle-model/vehicle-model.vue b/src/layouts/vehicle-model/vehicle-model.vue index 8d99afdb8..247a0bc1d 100644 --- a/src/layouts/vehicle-model/vehicle-model.vue +++ b/src/layouts/vehicle-model/vehicle-model.vue @@ -4,7 +4,7 @@
- { - // Call the "next" function to complete the transition to this page. - next((vm) => { - vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget); - vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget); - vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget); - vm.$refs.modelQuestion.initializeComponent(resultMap.cmsContent.VehicleModelQuestion, resultMap.modelQuestionInitialData); - }); + + const resultMap = await settleAllPromises(promiseResultMap); + + // Call the "next" function to complete the transition to this page. + next((vm) => { + vm.$refs.funnelSubHeader.initializeComponent( + resultMap.cmsContent.FunnelSubHeaderWidget + ); + vm.$refs.funnelHeader.initializeComponent( + resultMap.cmsContent.FunnelHeaderWidget + ); + vm.$refs.vehicleBanner.initializeComponent( + resultMap.cmsContent.VehicleBannerWidget + ); + vm.$refs.modelQuestion.initializeComponent( + resultMap.cmsContent.VehicleModelQuestion, + resultMap.modelQuestionInitialData + ); }); }, @@ -66,14 +76,17 @@ export default { backButtonAction() { // route to move backwards this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route); - } + }, }, watch: { selectedModel(model) { this.$store.commit(this.storeMutations.UPDATE_MODEL, model); - this.$router.navigate(this.navigationScenarios.SELECTED_MODEL, this.$route); - } + this.$router.navigate( + this.navigationScenarios.SELECTED_MODEL, + this.$route + ); + }, }, components: { diff --git a/src/layouts/vehicle-style/vehicle-style.vue b/src/layouts/vehicle-style/vehicle-style.vue index a9ac67ef5..8d88b1d84 100644 --- a/src/layouts/vehicle-style/vehicle-style.vue +++ b/src/layouts/vehicle-style/vehicle-style.vue @@ -4,7 +4,7 @@
- { - // Call the "next" function to complete the transition to this page. - next((vm) => { - vm.$refs.funnelSubHeader.initializeComponent(resultMap.cmsContent.FunnelSubHeaderWidget); - vm.$refs.funnelHeader.initializeComponent(resultMap.cmsContent.FunnelHeaderWidget); - vm.$refs.vehicleBanner.initializeComponent(resultMap.cmsContent.VehicleBannerWidget); - vm.$refs.styleQuestion.initializeComponent(resultMap.cmsContent.VehicleStyleQuestion, resultMap.styleQuestionInitialData); - }); + + const resultMap = await settleAllPromises(promiseResultMap); + + // Call the "next" function to complete the transition to this page. + next((vm) => { + vm.$refs.funnelSubHeader.initializeComponent( + resultMap.cmsContent.FunnelSubHeaderWidget + ); + vm.$refs.funnelHeader.initializeComponent( + resultMap.cmsContent.FunnelHeaderWidget + ); + vm.$refs.vehicleBanner.initializeComponent( + resultMap.cmsContent.VehicleBannerWidget + ); + vm.$refs.styleQuestion.initializeComponent( + resultMap.cmsContent.VehicleStyleQuestion, + resultMap.styleQuestionInitialData + ); }); }, diff --git a/src/layouts/vehicle-year/vehicle-year.vue b/src/layouts/vehicle-year/vehicle-year.vue index e95865f57..dbf488ea2 100644 --- a/src/layouts/vehicle-year/vehicle-year.vue +++ b/src/layouts/vehicle-year/vehicle-year.vue @@ -1,5 +1,5 @@