SSR-1064 moved getInputQuestionWidgetAnswersNullSafe into base-mixin
This commit is contained in:
parent
5f6cc8d38f
commit
57b61ac0bf
6 changed files with 75 additions and 31 deletions
|
|
@ -1,13 +1,13 @@
|
||||||
import { shallowMount } from '@vue/test-utils';
|
import { shallowMount } from '@vue/test-utils';
|
||||||
import { getMountOptions } from '@/helpers/unit-test-helper.js';
|
import { getMountOptions } from '@/helpers/unit-test-helper.js';
|
||||||
|
import widgetFields from '@/constants/cms-widget-fields.js';
|
||||||
import paymentMethodQuestion from '@/layouts/payment-method/payment-method-question/payment-method-question.vue';
|
import paymentMethodQuestion from '@/layouts/payment-method/payment-method-question/payment-method-question.vue';
|
||||||
|
|
||||||
let cmsContent;
|
let cmsContent;
|
||||||
|
|
||||||
const mockCmsContent = {
|
const mockCmsContent = {
|
||||||
QuestionText: 'Choose a payment option',
|
[widgetFields.INPUT_QUESTION_WIDGET.QUESTION_TEXT]: 'Choose a payment option',
|
||||||
Answers: [
|
[widgetFields.INPUT_QUESTION_WIDGET.ANSWERS]: [
|
||||||
{
|
{
|
||||||
Name: 'NameA',
|
Name: 'NameA',
|
||||||
Text: 'TextA',
|
Text: 'TextA',
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ export default {
|
||||||
return this.getCmsContent(this.cmsWidgetName, widgetFields.INPUT_QUESTION_WIDGET.QUESTION_TEXT);
|
return this.getCmsContent(this.cmsWidgetName, widgetFields.INPUT_QUESTION_WIDGET.QUESTION_TEXT);
|
||||||
},
|
},
|
||||||
paymentMethodAnswerData() {
|
paymentMethodAnswerData() {
|
||||||
const cmsData = this.getAnswersNullSafe(this.cmsWidgetName);
|
const cmsData = this.getInputQuestionWidgetAnswersNullSafe(this.cmsWidgetName);
|
||||||
|
|
||||||
return cmsData.map((answer) => ({
|
return cmsData.map((answer) => ({
|
||||||
buttonLabel: answer.Text,
|
buttonLabel: answer.Text,
|
||||||
|
|
@ -59,17 +59,6 @@ export default {
|
||||||
buttonImage: answer.AnswerImageUrl
|
buttonImage: answer.AnswerImageUrl
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
getAnswersNullSafe(widgetName) {
|
|
||||||
const rawData = this.getCmsContent(widgetName, widgetFields.INPUT_QUESTION_WIDGET.ANSWERS);
|
|
||||||
|
|
||||||
if (!rawData) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return rawData;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -33,20 +33,14 @@ export default {
|
||||||
},
|
},
|
||||||
driverSideDamageAnswers() {
|
driverSideDamageAnswers() {
|
||||||
const answerContent = getLocationAnswer(damageLocationsSelected.DRIVER, this.locationAnswers);
|
const answerContent = getLocationAnswer(damageLocationsSelected.DRIVER, this.locationAnswers);
|
||||||
return this.getAnswersNullSafe(answerContent?.SubWidgetName);
|
return this.getInputQuestionWidgetAnswersNullSafe(answerContent?.SubWidgetName);
|
||||||
},
|
},
|
||||||
passengerSideDamageAnswers() {
|
passengerSideDamageAnswers() {
|
||||||
const answerContent = getLocationAnswer(damageLocationsSelected.PASSENGER, this.locationAnswers);
|
const answerContent = getLocationAnswer(damageLocationsSelected.PASSENGER, this.locationAnswers);
|
||||||
return this.getAnswersNullSafe(answerContent?.SubWidgetName);
|
return this.getInputQuestionWidgetAnswersNullSafe(answerContent?.SubWidgetName);
|
||||||
},
|
},
|
||||||
locationAnswers() {
|
locationAnswers() {
|
||||||
return this.getAnswersNullSafe(this.damageLocationsWidgetName);
|
return this.getInputQuestionWidgetAnswersNullSafe(this.damageLocationsWidgetName);
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
getAnswersNullSafe(widgetName) {
|
|
||||||
const rawAnswers = this.getCmsContent(widgetName, 'Answers');
|
|
||||||
return rawAnswers || [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -208,15 +208,15 @@ export default {
|
||||||
return [line];
|
return [line];
|
||||||
},
|
},
|
||||||
locationAnswers() {
|
locationAnswers() {
|
||||||
return this.getAnswersNullSafe(this.widget.damageLocations);
|
return this.getInputQuestionWidgetAnswersNullSafe(this.widget.damageLocations);
|
||||||
},
|
},
|
||||||
driverSideDamageAnswers() {
|
driverSideDamageAnswers() {
|
||||||
const answerContent = getLocationAnswer(damageLocationsSelected.DRIVER, this.locationAnswers);
|
const answerContent = getLocationAnswer(damageLocationsSelected.DRIVER, this.locationAnswers);
|
||||||
return this.getAnswersNullSafe(answerContent?.SubWidgetName);
|
return this.getInputQuestionWidgetAnswersNullSafe(answerContent?.SubWidgetName);
|
||||||
},
|
},
|
||||||
passengerSideDamageAnswers() {
|
passengerSideDamageAnswers() {
|
||||||
const answerContent = getLocationAnswer(damageLocationsSelected.PASSENGER, this.locationAnswers);
|
const answerContent = getLocationAnswer(damageLocationsSelected.PASSENGER, this.locationAnswers);
|
||||||
return this.getAnswersNullSafe(answerContent?.SubWidgetName);
|
return this.getInputQuestionWidgetAnswersNullSafe(answerContent?.SubWidgetName);
|
||||||
},
|
},
|
||||||
getDamageLines() {
|
getDamageLines() {
|
||||||
const { glassToReplace, isRepair } = useMainStore().order.damage;
|
const { glassToReplace, isRepair } = useMainStore().order.damage;
|
||||||
|
|
@ -285,10 +285,6 @@ export default {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getAnswersNullSafe(widgetName) {
|
|
||||||
const rawAnswers = this.getCmsContent(widgetName, 'Answers');
|
|
||||||
return rawAnswers || [];
|
|
||||||
},
|
|
||||||
openContactDetailsModal() {
|
openContactDetailsModal() {
|
||||||
this.$refs.contactDetailsDrawer.openModal();
|
this.$refs.contactDetailsDrawer.openModal();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import vehicleCategories from '@/constants/vehicle-categories.js';
|
||||||
import queryStrings from '@/constants/query-strings';
|
import queryStrings from '@/constants/query-strings';
|
||||||
import dynamicStrings from '@/constants/dynamic-strings';
|
import dynamicStrings from '@/constants/dynamic-strings';
|
||||||
import routerParams from '@/router/router-constants/router-params';
|
import routerParams from '@/router/router-constants/router-params';
|
||||||
|
import widgetFields from '@/constants/cms-widget-fields.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
|
|
@ -19,6 +20,10 @@ export default {
|
||||||
getCmsContent(widgetName, fieldName) {
|
getCmsContent(widgetName, fieldName) {
|
||||||
return this.$root.cmsContentByWidget?.[widgetName]?.[fieldName] ? this.$root.cmsContentByWidget[widgetName][fieldName] : '';
|
return this.$root.cmsContentByWidget?.[widgetName]?.[fieldName] ? this.$root.cmsContentByWidget[widgetName][fieldName] : '';
|
||||||
},
|
},
|
||||||
|
getInputQuestionWidgetAnswersNullSafe(widgetName) {
|
||||||
|
const rawAnswers = this.getCmsContent(widgetName, widgetFields.INPUT_QUESTION_WIDGET.ANSWERS);
|
||||||
|
return rawAnswers || [];
|
||||||
|
},
|
||||||
getFooterInfoBoxHeight() {
|
getFooterInfoBoxHeight() {
|
||||||
const footerInfoBox = document.querySelector('.footer#infoBox');
|
const footerInfoBox = document.querySelector('.footer#infoBox');
|
||||||
return footerInfoBox ? footerInfoBox.offsetHeight : 0;
|
return footerInfoBox ? footerInfoBox.offsetHeight : 0;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import baseMixin from '@/mixins/base-mixin';
|
import baseMixin from '@/mixins/base-mixin';
|
||||||
import { shallowMount } from '@vue/test-utils';
|
import { shallowMount } from '@vue/test-utils';
|
||||||
|
import widgetFields from '@/constants/cms-widget-fields.js';
|
||||||
|
|
||||||
describe('base-mixin', () => {
|
describe('base-mixin', () => {
|
||||||
it('should set and get cms content', () => {
|
it('should set and get cms content', () => {
|
||||||
|
|
@ -20,4 +21,63 @@ describe('base-mixin', () => {
|
||||||
const localThis = { cmsWidgetName: 'testWidget' };
|
const localThis = { cmsWidgetName: 'testWidget' };
|
||||||
expect(baseMixin.computed.cssClassNameForCmsWidget.call(localThis)).toBe('widget-name-testWidget');
|
expect(baseMixin.computed.cssClassNameForCmsWidget.call(localThis)).toBe('widget-name-testWidget');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getInputQuestionWidgetAnswersNullSafe returns an empty array when the input question widget has no answers', () => {
|
||||||
|
// Arrange
|
||||||
|
const widgetName = 'inputQuestionWidget';
|
||||||
|
const wrapper = shallowMount(baseMixin, {
|
||||||
|
propsData: {
|
||||||
|
cmsContentByWidget: {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const cmsContent = {
|
||||||
|
[widgetName]: {
|
||||||
|
[widgetFields.INPUT_QUESTION_WIDGET.QUESTION_TEXT]: 'Choose an option',
|
||||||
|
[widgetFields.INPUT_QUESTION_WIDGET.ANSWERS]: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
wrapper.componentVM.setCmsContent(cmsContent);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const answers = wrapper.componentVM.getInputQuestionWidgetAnswersNullSafe(widgetName);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(answers).not.toBeNull(); // Check that answers is not null
|
||||||
|
expect(Array.isArray(answers)).toBeTruthy(); // Check that answers is an array
|
||||||
|
expect(answers).toHaveLength(0); // Check that answers is empty
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getInputQuestionWidgetAnswersNullSafe returns a non-empty array when the input question widget has answers', () => {
|
||||||
|
// Arrange
|
||||||
|
const widgetName = 'inputQuestionWidget';
|
||||||
|
const wrapper = shallowMount(baseMixin, {
|
||||||
|
propsData: {
|
||||||
|
cmsContentByWidget: {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const cmsContent = {
|
||||||
|
[widgetName]: {
|
||||||
|
[widgetFields.INPUT_QUESTION_WIDGET.QUESTION_TEXT]: 'Choose an option',
|
||||||
|
[widgetFields.INPUT_QUESTION_WIDGET.ANSWERS]: [
|
||||||
|
{
|
||||||
|
Name: 'NameA',
|
||||||
|
Text: 'TextA'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: 'NameB',
|
||||||
|
Text: 'TextB'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
wrapper.componentVM.setCmsContent(cmsContent);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const answers = wrapper.componentVM.getInputQuestionWidgetAnswersNullSafe(widgetName);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(answers).not.toBeNull(); // Check that answers is not null
|
||||||
|
expect(Array.isArray(answers)).toBeTruthy(); // Check that answers is an array
|
||||||
|
expect(answers).not.toHaveLength(0); // Check that answers is not empty
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue