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 widgetFields from '@/constants/cms-widget-fields.js';
|
||||
import { toTitleCase, formatAddress, toDisplayPhoneNumber } from '@/helpers/text-helper.js';
|
||||
import { getDamageDisplayContent } from '@/helpers/damage-review-content-generator.js';
|
||||
|
||||
// Mock fetchCmsContentForPage
|
||||
jest.mock('@/helpers/cms-content-helper', () => ({
|
||||
|
|
@ -26,6 +27,11 @@ jest.mock('@/helpers/text-helper.js', () => ({
|
|||
toTitleCase: jest.fn()
|
||||
}));
|
||||
|
||||
jest.mock('@/helpers/damage-review-content-generator.js', () => ({
|
||||
getDamageDisplayContent: jest.fn(),
|
||||
getLocationAnswer: jest.fn()
|
||||
}));
|
||||
|
||||
// Mock our module for promises.
|
||||
jest.mock('@/helpers/layout-helper.js', () => jest.fn());
|
||||
|
||||
|
|
@ -61,6 +67,7 @@ function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRu
|
|||
beforeEach(() => {
|
||||
formatAddress.mockClear();
|
||||
toDisplayPhoneNumber.mockClear();
|
||||
getDamageDisplayContent.mockClear();
|
||||
});
|
||||
|
||||
describe('tpa-submit', () => {
|
||||
|
|
@ -343,38 +350,25 @@ describe('tpa-submit', () => {
|
|||
expect(vehicleSection.lines).toStrictEqual(expectedLines);
|
||||
}
|
||||
);
|
||||
// TODO update because this case is now much more complicated
|
||||
test.each([
|
||||
['Apple sauce', 'Apple sauce']// ,
|
||||
// ['', ''],
|
||||
// ['', undefined],
|
||||
// ['', null]
|
||||
])(
|
||||
'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];
|
||||
test('damage section lines equal result from getDamageDisplayContent', async () => {
|
||||
// Arrange
|
||||
const { wrapper } = getMountedComponent();
|
||||
const damageSectionIndex = 1;
|
||||
const expectedLines = ['hi', 'potato', 'vehicle 3'];
|
||||
getDamageDisplayContent.mockImplementationOnce(() => expectedLines);
|
||||
|
||||
// Act
|
||||
await tpaSubmit.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { issPage: 'tpa-submit' } },
|
||||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
// Act
|
||||
await tpaSubmit.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { issPage: 'tpa-submit' } },
|
||||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
|
||||
// Assert
|
||||
const damageSection = wrapper.vm.sections[damageSectionIndex];
|
||||
expect(damageSection.lines).toStrictEqual(expectedLines);
|
||||
}
|
||||
);
|
||||
// Assert
|
||||
const damageSection = wrapper.vm.sections[damageSectionIndex];
|
||||
expect(damageSection.lines).toEqual(expectedLines);
|
||||
});
|
||||
describe('preferred shop section', () => {
|
||||
test('has three lines', async () => {
|
||||
// Arrange
|
||||
|
|
@ -766,5 +760,22 @@ describe('tpa-submit', () => {
|
|||
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