SSR-1064 mock mixin updates in unit tests
This commit is contained in:
parent
57b61ac0bf
commit
608668fb9f
3 changed files with 14 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ 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 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';
|
||||||
|
import baseMixin from '@/mixins/base-mixin';
|
||||||
|
|
||||||
let cmsContent;
|
let cmsContent;
|
||||||
|
|
||||||
|
|
@ -39,6 +40,7 @@ function setupMocks(customMountOptions) {
|
||||||
|
|
||||||
const mockMixin = {
|
const mockMixin = {
|
||||||
methods: {
|
methods: {
|
||||||
|
...baseMixin.methods,
|
||||||
getCmsContent: jest.fn((widgetName, cmsFieldName) => cmsContent[cmsFieldName])
|
getCmsContent: jest.fn((widgetName, cmsFieldName) => cmsContent[cmsFieldName])
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { useMainStore } from '@/store';
|
||||||
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 { getDamageDisplayContent } from '@/helpers/damage-review-content-generator.js';
|
import { getDamageDisplayContent } from '@/helpers/damage-review-content-generator.js';
|
||||||
|
import baseMixin from '@/mixins/base-mixin';
|
||||||
|
|
||||||
jest.mock('@/helpers/damage-review-content-generator.js', () => ({
|
jest.mock('@/helpers/damage-review-content-generator.js', () => ({
|
||||||
getDamageDisplayContent: jest.fn(),
|
getDamageDisplayContent: jest.fn(),
|
||||||
|
|
@ -16,6 +17,7 @@ jest.mock('@/helpers/damage-review-content-generator.js', () => ({
|
||||||
let cmsContent;
|
let cmsContent;
|
||||||
const mockMixin = {
|
const mockMixin = {
|
||||||
methods: {
|
methods: {
|
||||||
|
...baseMixin.methods,
|
||||||
getCmsContent: jest.fn((widgetName, cmsFieldName) => cmsContent?.[widgetName]?.[cmsFieldName] ?? '')
|
getCmsContent: jest.fn((widgetName, cmsFieldName) => cmsContent?.[widgetName]?.[cmsFieldName] ?? '')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import settleAllPromises from '@/helpers/layout-helper.js';
|
||||||
import widgetFields from '@/constants/cms-widget-fields.js';
|
import widgetFields from '@/constants/cms-widget-fields.js';
|
||||||
import { toTitleCase, formatAddress, toDisplayPhoneNumber } from '@/helpers/text-helper.js';
|
import { toTitleCase, formatAddress, toDisplayPhoneNumber } from '@/helpers/text-helper.js';
|
||||||
import { getDamageDisplayContent } from '@/helpers/damage-review-content-generator.js';
|
import { getDamageDisplayContent } from '@/helpers/damage-review-content-generator.js';
|
||||||
|
import baseMixin from '@/mixins/base-mixin';
|
||||||
|
|
||||||
// Mock fetchCmsContentForPage
|
// Mock fetchCmsContentForPage
|
||||||
jest.mock('@/helpers/cms-content-helper', () => ({
|
jest.mock('@/helpers/cms-content-helper', () => ({
|
||||||
|
|
@ -35,6 +36,12 @@ jest.mock('@/helpers/damage-review-content-generator.js', () => ({
|
||||||
// Mock our module for promises.
|
// Mock our module for promises.
|
||||||
jest.mock('@/helpers/layout-helper.js', () => jest.fn());
|
jest.mock('@/helpers/layout-helper.js', () => jest.fn());
|
||||||
|
|
||||||
|
const mockMixin = {
|
||||||
|
methods: {
|
||||||
|
...baseMixin.methods
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRunAfterInitializingStore = () => {}) {
|
function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRunAfterInitializingStore = () => {}) {
|
||||||
const mountOptions = getMountOptions({
|
const mountOptions = getMountOptions({
|
||||||
router: {
|
router: {
|
||||||
|
|
@ -52,6 +59,7 @@ function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRu
|
||||||
|
|
||||||
mountOptions.global.plugins = [testingPinia];
|
mountOptions.global.plugins = [testingPinia];
|
||||||
mountOptions.data = () => (initialData);
|
mountOptions.data = () => (initialData);
|
||||||
|
mountOptions.mixins = [mockMixin];
|
||||||
|
|
||||||
const apiResponses = { cmsContent: {} };
|
const apiResponses = { cmsContent: {} };
|
||||||
|
|
||||||
|
|
@ -775,14 +783,14 @@ describe('tpa-submit', () => {
|
||||||
[[], []],
|
[[], []],
|
||||||
[undefined, []],
|
[undefined, []],
|
||||||
[null, []]
|
[null, []]
|
||||||
])('getAnswersNullSafe', (rawAnswers, expected) => {
|
])('getInputQuestionWidgetAnswersNullSafe', (rawAnswers, expected) => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const widgetName = 'WidgetName';
|
const widgetName = 'WidgetName';
|
||||||
const { wrapper } = getMountedComponent();
|
const { wrapper } = getMountedComponent();
|
||||||
wrapper.vm.getCmsContent = jest.fn().mockImplementationOnce(() => rawAnswers);
|
wrapper.vm.getCmsContent = jest.fn().mockImplementationOnce(() => rawAnswers);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const result = wrapper.vm.getAnswersNullSafe(widgetName);
|
const result = wrapper.vm.getInputQuestionWidgetAnswersNullSafe(widgetName);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(result).toEqual(expected);
|
expect(result).toEqual(expected);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue