CSR-726 | Cash or Insurance Toggle
Unit Tests Default selection logic Fix for list-button-horizontal
This commit is contained in:
parent
96b3098e8c
commit
0a4ffee447
4 changed files with 93 additions and 4 deletions
|
|
@ -0,0 +1,57 @@
|
||||||
|
import { shallowMount } from "@vue/test-utils";
|
||||||
|
import CashOrInsuranceQuestion from "./cash-or-insurance-question";
|
||||||
|
|
||||||
|
|
||||||
|
describe("cash-or-insurance-question.vue", () => {
|
||||||
|
it("Should emit a false boolean value when selectedValues is 'CashAnswer' (update:modelValue)", async () => {
|
||||||
|
|
||||||
|
//Arrange
|
||||||
|
const wrapper = shallowMount(CashOrInsuranceQuestion, {
|
||||||
|
propsData: mockProps,
|
||||||
|
mixins: [mockMixin]
|
||||||
|
});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
wrapper.vm.selectedValues = "CashAnswer";
|
||||||
|
await wrapper.vm.$nextTick();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.emitted()["update:modelValue"][0]).toEqual([false]);
|
||||||
|
expect(typeof wrapper.emitted()["update:modelValue"][0][0]).toBe("boolean");
|
||||||
|
});
|
||||||
|
it("Should return 'CashAnswer' from selectedValues when modelValue is set to false", async () => {
|
||||||
|
|
||||||
|
//Arrange
|
||||||
|
const wrapper = shallowMount(CashOrInsuranceQuestion, {
|
||||||
|
propsData: mockProps,
|
||||||
|
mixins: [mockMixin]
|
||||||
|
});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
wrapper.setProps({modelValue : false});
|
||||||
|
await wrapper.vm.$nextTick();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.selectedValues).toBe("CashAnswer");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
///////////////
|
||||||
|
// Constants //
|
||||||
|
///////////////
|
||||||
|
|
||||||
|
const mockMixin = {
|
||||||
|
methods: {
|
||||||
|
getCmsContent: jest.fn((widgetName, cmsFieldName) => {
|
||||||
|
return mockCmsContent[cmsFieldName];
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mockProps = {
|
||||||
|
modelValue: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
const mockCmsContent = {
|
||||||
|
'Text': "Sample text here.",
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,9 @@
|
||||||
<script>
|
<script>
|
||||||
import buttonQuestion from "@/common-components/button-question/button-question";
|
import buttonQuestion from "@/common-components/button-question/button-question";
|
||||||
|
|
||||||
|
const cashAnswer = "CashAnswer";
|
||||||
|
const insuranceAnswer = "InsuranceAnswer";
|
||||||
|
|
||||||
export default ({
|
export default ({
|
||||||
name: "cashOrInsuranceQuestion",
|
name: "cashOrInsuranceQuestion",
|
||||||
props: {
|
props: {
|
||||||
|
|
@ -23,17 +26,18 @@ export default ({
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
answersFromCms(){
|
answersFromCms(){
|
||||||
|
//console.log(JSON.parse(JSON.stringify(this.getCmsContent(this.cmsWidgetName, 'Answers'))));
|
||||||
return this.getCmsContent(this.cmsWidgetName, 'Answers');
|
return this.getCmsContent(this.cmsWidgetName, 'Answers');
|
||||||
},
|
},
|
||||||
selectedValues: {
|
selectedValues: {
|
||||||
get: function() {
|
get: function() {
|
||||||
// Convert to CMS answer name from bool
|
// Convert to CMS answer name from bool
|
||||||
var cmsAnswerValue = this.modelValue ? "InsuranceAnswer" : "CashAnswer";
|
var cmsAnswerValue = this.modelValue ? insuranceAnswer : cashAnswer;
|
||||||
return cmsAnswerValue;
|
return cmsAnswerValue;
|
||||||
},
|
},
|
||||||
set: function(newValue) {
|
set: function(newValue) {
|
||||||
// Convert back to bool for parent component
|
// Convert back to bool for parent component
|
||||||
this.$emit("update:modelValue", newValue === "InsuranceAnswer");
|
this.$emit("update:modelValue", newValue === insuranceAnswer);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -133,19 +133,43 @@ export default {
|
||||||
// Call APIs
|
// Call APIs
|
||||||
const cmsContent = await fetchCmsContentForPage(to.query.fmgPage);
|
const cmsContent = await fetchCmsContentForPage(to.query.fmgPage);
|
||||||
|
|
||||||
|
// TODOS - modify as needed, just a rough sketch to place initializations
|
||||||
|
|
||||||
|
// get supporting lineitems
|
||||||
|
|
||||||
|
// get wiper and rain defense lineitems
|
||||||
|
|
||||||
|
// Settle promises and get results
|
||||||
|
|
||||||
|
// get price of supporting, rain defense & wipers, and parts
|
||||||
|
|
||||||
|
// Settle pricing promise and get results
|
||||||
|
|
||||||
|
|
||||||
// Call the "next" function to complete the transition to this page.
|
// Call the "next" function to complete the transition to this page.
|
||||||
next((vm) => {
|
next((vm) => {
|
||||||
vm.setCmsContent(cmsContent);
|
vm.setCmsContent(cmsContent);
|
||||||
|
vm.isInsurance = vm.getDefaultIsInsuranceValue();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
isInsurance: false,
|
cashOrInsuranceThreshhold: 600,
|
||||||
|
pricingRequestResult: null,
|
||||||
|
isInsurance: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
arePagePrerequisitesValid() {
|
arePagePrerequisitesValid() {
|
||||||
return store.getters.order.damage.isRepair || (store.getters.order.lineItems?.glassParts != null && store.getters.order.lineItems.glassParts.length > 0);
|
return store.getters.order.damage.isRepair || (store.getters.order.lineItems?.glassParts != null && store.getters.order.lineItems.glassParts.length > 0);
|
||||||
|
},
|
||||||
|
getDefaultIsInsuranceValue() {
|
||||||
|
var defaultIsInsuranceValue = this.$store.getters.order.payment.isInsurance;
|
||||||
|
if(defaultIsInsuranceValue != null) {
|
||||||
|
return defaultIsInsuranceValue;
|
||||||
|
} else {
|
||||||
|
return this.economyPackagePrice > this.cashOrInsuranceThreshhold;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
@ -155,6 +179,10 @@ export default {
|
||||||
answersFromCms() {
|
answersFromCms() {
|
||||||
return ["Pay on my own", "Pay with insurance"];
|
return ["Pay on my own", "Pay with insurance"];
|
||||||
},
|
},
|
||||||
|
economyPackagePrice() {
|
||||||
|
//TODO build out the pricing logic CSR-504
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
selectedChipCountValues: {
|
selectedChipCountValues: {
|
||||||
get: function() {
|
get: function() {
|
||||||
return this.modelValue;
|
return this.modelValue;
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ export default {
|
||||||
: this.selectedValues[0] == this.value;
|
: this.selectedValues[0] == this.value;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.checkValue = this.selectedValues;
|
this.checkValue = this.selectedValues === this.value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue