CSR-222: changes to navigation method of back button

This commit is contained in:
Adam Caouette 2021-12-16 17:05:43 -05:00
parent 29f52c8b4b
commit 137ccd5328
4 changed files with 48 additions and 7 deletions

View file

@ -12,5 +12,6 @@ describe("FunnelSubHeader.vue", () => {
// Assert // Assert
expect(wrapper.find("h2").text()).toContain("FunnelSubHeader Content"); expect(wrapper.find("h2").text()).toContain("FunnelSubHeader Content");
wrapper.unmount();
}); });
}); });

View file

@ -4,8 +4,8 @@
<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">{{ text }}</h2>
<buttonBack <buttonBack
v-if="hasBackButton" v-if="hasBackButton"
:backButtonUrl="backButtonUrl"
:backButtonAccessibleText="backButtonAccessibleText" :backButtonAccessibleText="backButtonAccessibleText"
:backButtonAction="backButtonAction"
/> />
</div> </div>
</div> </div>
@ -21,6 +21,7 @@ export default {
hasBackButton: Boolean, hasBackButton: Boolean,
backButtonUrl: String, backButtonUrl: String,
backButtonAccessibleText: String, backButtonAccessibleText: String,
backButtonAction: Function,
}, },
components: { components: {
buttonBack, buttonBack,

View file

@ -2,6 +2,7 @@ import { shallowMount } from "@vue/test-utils";
import buttonBack from "./button-back"; import buttonBack from "./button-back";
describe("back button", () => { describe("back button", () => {
test("renders a link", () => { test("renders a link", () => {
// Arrange // Arrange
@ -17,4 +18,25 @@ describe("back button", () => {
expect(wrapper.find("a").exists()).toBe(true); expect(wrapper.find("a").exists()).toBe(true);
wrapper.unmount(); 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();
wrapper.unmount();
});
}); });

View file

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