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");
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>
<div class="current_car_info-text">
<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
v-if="hasBackButton"
:backButtonAccessibleText="backButtonAccessibleText"
@ -33,6 +40,12 @@ export default {
<style lang="scss">
h2 {
color: $gray-550;
button {
border: none;
background: none;
color: inherit;
}
}
.back-button-wrapper {
margin-left: .25rem;

View file

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

View file

@ -13,7 +13,7 @@ jest.mock("@/helpers/layout-helper.js", () => ({
describe("vehicle-make.vue", () => {
test("Make question component is initized with api data", async (done) => {
//Arange
//Arrange
const radioQuestionCmsContent = { QuestionText: "What make is your vehicle?" };
const makeQuestionInitialData = ["honda", "ford", "dodge"];
const { wrapper, apiPromise } = setupMocks( {
@ -35,7 +35,7 @@ describe("vehicle-make.vue", () => {
describe("vehicle-make.vue", () => {
test("Page header is passed data from CMS", async (done) => {
//Arange
//Arrange
const { wrapper, apiPromise } = setupMocks( { pageHeaderWidgetHeaderText: "Select a make to get started" });
//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({
radioQuestionCmsContent = {},
makeQuestionInitialData = {},
pageHeaderWidgetHeaderText = {},
mountOptionsMockData = {},
}) {
//Mock api responses
@ -85,7 +112,7 @@ function setupMocks({
loadInitialData: jest.fn(),
initializeComponent: jest.fn(),
};
const mountOptions = getMountOptions({ });
const mountOptions = getMountOptions(mountOptionsMockData);
const wrapper = shallowMount(vehicleMake, mountOptions);
const makeQuestionWrapper = wrapper.findComponent({ name: "makeQuestion" });
makeQuestionWrapper.vm.initializeComponent = makeQuestion.methods.initializeComponent;

View file

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

View file

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

View file

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