commit
25640b3f5d
4 changed files with 38 additions and 41 deletions
|
|
@ -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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
|
|
@ -32,6 +39,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;
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue