Updating tpa-submit tests
This commit is contained in:
parent
002ef3726d
commit
5121c70bcc
1 changed files with 41 additions and 30 deletions
|
|
@ -10,6 +10,7 @@ import { fetchCmsContentForPage } from '@/helpers/cms-content-helper';
|
||||||
import settleAllPromises from '@/helpers/layout-helper.js';
|
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';
|
||||||
|
|
||||||
// Mock fetchCmsContentForPage
|
// Mock fetchCmsContentForPage
|
||||||
jest.mock('@/helpers/cms-content-helper', () => ({
|
jest.mock('@/helpers/cms-content-helper', () => ({
|
||||||
|
|
@ -26,6 +27,11 @@ jest.mock('@/helpers/text-helper.js', () => ({
|
||||||
toTitleCase: jest.fn()
|
toTitleCase: jest.fn()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
jest.mock('@/helpers/damage-review-content-generator.js', () => ({
|
||||||
|
getDamageDisplayContent: jest.fn(),
|
||||||
|
getLocationAnswer: jest.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
// 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());
|
||||||
|
|
||||||
|
|
@ -61,6 +67,7 @@ function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRu
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
formatAddress.mockClear();
|
formatAddress.mockClear();
|
||||||
toDisplayPhoneNumber.mockClear();
|
toDisplayPhoneNumber.mockClear();
|
||||||
|
getDamageDisplayContent.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('tpa-submit', () => {
|
describe('tpa-submit', () => {
|
||||||
|
|
@ -343,38 +350,25 @@ describe('tpa-submit', () => {
|
||||||
expect(vehicleSection.lines).toStrictEqual(expectedLines);
|
expect(vehicleSection.lines).toStrictEqual(expectedLines);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// TODO update because this case is now much more complicated
|
test('damage section lines equal result from getDamageDisplayContent', async () => {
|
||||||
test.each([
|
// Arrange
|
||||||
['Apple sauce', 'Apple sauce']// ,
|
const { wrapper } = getMountedComponent();
|
||||||
// ['', ''],
|
const damageSectionIndex = 1;
|
||||||
// ['', undefined],
|
const expectedLines = ['hi', 'potato', 'vehicle 3'];
|
||||||
// ['', null]
|
getDamageDisplayContent.mockImplementationOnce(() => expectedLines);
|
||||||
])(
|
|
||||||
'damage line is %p when store damage is %p',
|
|
||||||
async (damageLine, storeDamage) => {
|
|
||||||
// Arrange
|
|
||||||
const initialStore = {
|
|
||||||
order: {
|
|
||||||
policy: { damageCause: storeDamage }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const { wrapper } = getMountedComponent(initialStore);
|
|
||||||
const damageSectionIndex = 1;
|
|
||||||
const expectedLines = [damageLine];
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await tpaSubmit.beforeRouteEnter.call(
|
await tpaSubmit.beforeRouteEnter.call(
|
||||||
wrapper.vm,
|
wrapper.vm,
|
||||||
{ query: { issPage: 'tpa-submit' } },
|
{ query: { issPage: 'tpa-submit' } },
|
||||||
undefined,
|
undefined,
|
||||||
(c) => c(wrapper.vm)
|
(c) => c(wrapper.vm)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
const damageSection = wrapper.vm.sections[damageSectionIndex];
|
const damageSection = wrapper.vm.sections[damageSectionIndex];
|
||||||
expect(damageSection.lines).toStrictEqual(expectedLines);
|
expect(damageSection.lines).toEqual(expectedLines);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
describe('preferred shop section', () => {
|
describe('preferred shop section', () => {
|
||||||
test('has three lines', async () => {
|
test('has three lines', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -766,5 +760,22 @@ describe('tpa-submit', () => {
|
||||||
expect(result).toBe(null);
|
expect(result).toBe(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
test.each([
|
||||||
|
[[1, 5, 6], [1, 5, 6]],
|
||||||
|
[[], []],
|
||||||
|
[undefined, []],
|
||||||
|
[null, []]
|
||||||
|
])('getAnswersNullSafe', (rawAnswers, expected) => {
|
||||||
|
// Arrange
|
||||||
|
const widgetName = 'WidgetName';
|
||||||
|
const { wrapper } = getMountedComponent();
|
||||||
|
wrapper.vm.getCmsContent = jest.fn().mockImplementationOnce(() => rawAnswers);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = wrapper.vm.getAnswersNullSafe(widgetName);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toEqual(expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue