Merge branch 'develop' into feature/CSR-76

This commit is contained in:
Max 2021-12-20 16:44:52 -05:00
commit ea5fb973d4
8 changed files with 88 additions and 48 deletions

View file

@ -14,4 +14,19 @@ describe("FunnelSubHeader.vue", () => {
expect(wrapper.find("h2").text()).toContain("FunnelSubHeader Content"); expect(wrapper.find("h2").text()).toContain("FunnelSubHeader Content");
wrapper.unmount(); wrapper.unmount();
}); });
it("Should render the button inside of header if backButtonAction provided", () => {
// Act
const testFn = () => {}
const wrapper = shallowMount(FunnelSubHeader, {
propsData: {
text: "FunnelSubHeader Content",
hasBackButton: true,
backButtonAction: testFn,
},
});
// Assert
expect(wrapper.find("h2").find("button").text()).toContain("FunnelSubHeader Content");
wrapper.unmount();
});
}); });

View file

@ -1,7 +1,14 @@
<template> <template>
<div class="current_car_info-text"> <div class="current_car_info-text">
<div class="d-flex align-items-center justify-content-center"> <div class="d-flex align-items-center justify-content-center">
<h2 class="text-center fs-5 d-block fw-normal mb-0">{{ text }}</h2> <h2 class="text-center fs-5 d-block fw-normal mb-0">
<button v-if="hasBackButton && backButtonAction" @click="backButtonAction">
{{ text }}
</button>
<span v-else>
{{ text }}
</span>
</h2>
<buttonBack <buttonBack
v-if="hasBackButton" v-if="hasBackButton"
:backButtonAccessibleText="backButtonAccessibleText" :backButtonAccessibleText="backButtonAccessibleText"
@ -33,6 +40,12 @@ export default {
<style lang="scss"> <style lang="scss">
h2 { h2 {
color: $gray-550; color: $gray-550;
button {
border: none;
background: none;
color: inherit;
}
} }
.back-button-wrapper { .back-button-wrapper {
margin-left: .25rem; margin-left: .25rem;

View file

@ -1,5 +1,6 @@
import { storeActions } from "@/constants/store-actions"; import { storeActions } from "@/constants/store-actions";
import { storeMutations } from "@/constants/store-mutations.js"; import { storeMutations } from "@/constants/store-mutations.js";
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios.js";
export function getMountOptions(mockData) { export function getMountOptions(mockData) {
// Define our mocks to attached to the 'global' object for Vue/Jest. // Define our mocks to attached to the 'global' object for Vue/Jest.
@ -21,6 +22,7 @@ export function getMountOptions(mockData) {
// Mock const files // Mock const files
mocks.storeActions = storeActions; mocks.storeActions = storeActions;
mocks.storeMutations = storeMutations; mocks.storeMutations = storeMutations;
mocks.navigationScenarios = navigationScenarios;
// Mock $store and $router when accessing this.$store/$router // Mock $store and $router when accessing this.$store/$router
mocks.$store = mockData.store; mocks.$store = mockData.store;

View file

@ -13,7 +13,7 @@ jest.mock("@/helpers/layout-helper.js", () => ({
describe("vehicle-make.vue", () => { describe("vehicle-make.vue", () => {
test("Make question component is initized with api data", async (done) => { test("Make question component is initized with api data", async (done) => {
//Arange //Arrange
const radioQuestionCmsContent = { QuestionText: "What make is your vehicle?" }; const radioQuestionCmsContent = { QuestionText: "What make is your vehicle?" };
const makeQuestionInitialData = ["honda", "ford", "dodge"]; const makeQuestionInitialData = ["honda", "ford", "dodge"];
const { wrapper, apiPromise } = setupMocks( { const { wrapper, apiPromise } = setupMocks( {
@ -35,7 +35,7 @@ describe("vehicle-make.vue", () => {
describe("vehicle-make.vue", () => { describe("vehicle-make.vue", () => {
test("Page header is passed data from CMS", async (done) => { test("Page header is passed data from CMS", async (done) => {
//Arange //Arrange
const { wrapper, apiPromise } = setupMocks( { pageHeaderWidgetHeaderText: "Select a make to get started" }); const { wrapper, apiPromise } = setupMocks( { pageHeaderWidgetHeaderText: "Select a make to get started" });
//Act //Act
@ -51,10 +51,37 @@ describe("vehicle-make.vue", () => {
}); });
}); });
describe("vehicle-make.vue", () => {
test("BackButtonAction triggers a router.navigate change", async (done) => {
//Arrange
const { wrapper, apiPromise } = setupMocks( {
pageHeaderWidgetHeaderText: "Select a make to get started",
mountOptionsMockData: {
router: {
navigate: jest.fn()
},
},
});
//Act
vehicleMake.beforeRouteEnter.call(wrapper.vm, { query: { fmgPage: "vehicle-make" } }, undefined, (c) => c(wrapper.vm));
wrapper.vm.backButtonAction();
await nextTick();
//Assert
apiPromise.finally(() => {
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
done();
});
});
});
function setupMocks({ function setupMocks({
radioQuestionCmsContent = {}, radioQuestionCmsContent = {},
makeQuestionInitialData = {}, makeQuestionInitialData = {},
pageHeaderWidgetHeaderText = {}, pageHeaderWidgetHeaderText = {},
mountOptionsMockData = {},
}) { }) {
//Mock api responses //Mock api responses
@ -85,7 +112,7 @@ function setupMocks({
loadInitialData: jest.fn(), loadInitialData: jest.fn(),
initializeComponent: jest.fn(), initializeComponent: jest.fn(),
}; };
const mountOptions = getMountOptions({ }); const mountOptions = getMountOptions(mountOptionsMockData);
const wrapper = shallowMount(vehicleMake, mountOptions); const wrapper = shallowMount(vehicleMake, mountOptions);
const makeQuestionWrapper = wrapper.findComponent({ name: "makeQuestion" }); const makeQuestionWrapper = wrapper.findComponent({ name: "makeQuestion" });
makeQuestionWrapper.vm.initializeComponent = makeQuestion.methods.initializeComponent; makeQuestionWrapper.vm.initializeComponent = makeQuestion.methods.initializeComponent;

View file

@ -4,7 +4,13 @@
<div class="select-car"> <div class="select-car">
<div class="select-car-form rounded text-center"> <div class="select-car-form rounded text-center">
<vehicleBanner :vehicleImageSrc="vehicleBannerWidget.GenericVehicleImage" /> <vehicleBanner :vehicleImageSrc="vehicleBannerWidget.GenericVehicleImage" />
<funnelSubHeader :text="pageHeaderWidgets.HeaderText" class="Header" /> <funnelSubHeader
:text="pageHeaderWidgets.HeaderText"
:hasBackButton="true"
backButtonAccessibleText="Change Vehicle Year"
:backButtonAction="backButtonAction"
class="Header"
/>
<makeQuestion v-model="selectedMake" ref="makeQuestion" /> <makeQuestion v-model="selectedMake" ref="makeQuestion" />
</div> </div>
</div> </div>
@ -60,6 +66,13 @@ export default {
}); });
}, },
methods: {
backButtonAction: function () {
// route to move backwards
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
}
},
watch: { watch: {
selectedMake(make) { selectedMake(make) {
this.$store.commit(this.storeMutations.UPDATE_MAKE, make); this.$store.commit(this.storeMutations.UPDATE_MAKE, make);

View file

@ -13,7 +13,7 @@ jest.mock("@/helpers/layout-helper.js", () => ({
describe("vehicle-year.vue", () => { describe("vehicle-year.vue", () => {
test("Year question component is initized with api data", async (done) => { test("Year question component is initized with api data", async (done) => {
//Arange //Arrange
const radioQuestionCmsContent = { QuestionText: "What year is your vehicle?" }; const radioQuestionCmsContent = { QuestionText: "What year is your vehicle?" };
const yearQuestionInitialData = ["2023", "2022", "2021"]; const yearQuestionInitialData = ["2023", "2022", "2021"];
const { wrapper, apiPromise } = setupMocks( { const { wrapper, apiPromise } = setupMocks( {
@ -35,7 +35,7 @@ describe("vehicle-year.vue", () => {
describe("vehicle-year.vue", () => { describe("vehicle-year.vue", () => {
test("Page header is passed data from CMS", async (done) => { test("Page header is passed data from CMS", async (done) => {
//Arange //Arrange
const { wrapper, apiPromise } = setupMocks( { pageHeaderWidgetHeaderText: "Select a year to get started" }); const { wrapper, apiPromise } = setupMocks( { pageHeaderWidgetHeaderText: "Select a year to get started" });
//Act //Act
@ -54,6 +54,7 @@ function setupMocks({
radioQuestionCmsContent = {}, radioQuestionCmsContent = {},
yearQuestionInitialData = {}, yearQuestionInitialData = {},
pageHeaderWidgetHeaderText = {}, pageHeaderWidgetHeaderText = {},
mountOptionsMockData = {},
}) { }) {
//Mock api responses //Mock api responses
@ -84,7 +85,7 @@ function setupMocks({
loadInitialData: jest.fn(), loadInitialData: jest.fn(),
initializeComponent: jest.fn(), initializeComponent: jest.fn(),
}; };
const mountOptions = getMountOptions({ }); const mountOptions = getMountOptions(mountOptionsMockData);
const wrapper = shallowMount(vehicleYear, mountOptions); const wrapper = shallowMount(vehicleYear, mountOptions);
const yearQuestionWrapper = wrapper.findComponent({ name: "yearQuestion" }); const yearQuestionWrapper = wrapper.findComponent({ name: "yearQuestion" });
yearQuestionWrapper.vm.initializeComponent = yearQuestion.methods.initializeComponent; yearQuestionWrapper.vm.initializeComponent = yearQuestion.methods.initializeComponent;

View file

@ -3,39 +3,20 @@ import buttonBack from "./button-back";
describe("back button", () => { describe("back button", () => {
test("renders a link", () => { test("renders a button", () => {
// Arrange
// Act
const wrapper = shallowMount(buttonBack, {
propsData: {
backButtonUrl: "#",
backButtonAccessibleText: "something",
},
});
// Assert
expect(wrapper.find("a").exists()).toBe(true);
wrapper.unmount();
});
test("should execute handleClick function if it is clicked on", async () => {
// Arrange // Arrange
const myFunction = () => {}; const myFunction = () => {};
// Act // Act
const wrapper = shallowMount(buttonBack, { const wrapper = shallowMount(buttonBack, {
propsData: { propsData: {
backButtonAction: myFunction, backButtonAction: myFunction,
backButtonAccessibleText: "something", backButtonAccessibleText: "something",
}, },
}); });
const handleClickMethod = jest.spyOn(wrapper.vm, "handleClick");
await wrapper.find("a").trigger("click");
// Assert // Assert
expect(handleClickMethod).toHaveBeenCalled(); expect(wrapper.find("button").exists()).toBe(true);
wrapper.unmount(); wrapper.unmount();
}); });

View file

@ -1,8 +1,7 @@
<template> <template>
<a <button
v-if="backButtonUrl || backButtonAction" v-if="backButtonAction"
:href="backButtonUrl || '#'" @click="backButtonAction"
@click="handleClick($event)"
class="back-button-wrapper d-flex p-0" class="back-button-wrapper d-flex p-0"
:aria-label="backButtonAccessibleText" :aria-label="backButtonAccessibleText"
> >
@ -10,34 +9,23 @@
<div class="arrow-left"></div> <div class="arrow-left"></div>
<div class="box"></div> <div class="box"></div>
</div> </div>
</a> </button>
</template> </template>
<script> <script>
export default { export default {
name: "buttonBack", name: "buttonBack",
props: { props: {
backButtonUrl: {
type: String,
default: "",
},
backButtonAccessibleText: { backButtonAccessibleText: {
type: String, type: String,
required: true, required: true,
default: "",
}, },
backButtonAction: { backButtonAction: {
type: Function, type: Function,
default: null, default: null,
} }
}, },
methods: {
handleClick: function (event) {
if (this.backButtonAction) {
event.preventDefault();
this.backButtonAction();
}
},
},
}; };
</script> </script>