unit tests
This commit is contained in:
parent
6f122bc8c3
commit
47dbab0941
3 changed files with 126 additions and 19 deletions
|
|
@ -80,4 +80,3 @@ export function anyPartWithRequiresRecalFlag(lineItems) {
|
||||||
|
|
||||||
return lineItems.some((li) => li.requiresRecalibration === true);
|
return lineItems.some((li) => li.requiresRecalibration === true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ jest.mock('@/helpers/cms-content-helper', () => ({
|
||||||
fetchCmsContentForPage: jest.fn()
|
fetchCmsContentForPage: jest.fn()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const RECAL_ACK_MODAL_REF_NAME = 'recalAckModal';
|
||||||
|
|
||||||
const mockMixin = {
|
const mockMixin = {
|
||||||
methods: {
|
methods: {
|
||||||
getCmsContent: jest.fn().mockImplementation(() => ''),
|
getCmsContent: jest.fn().mockImplementation(() => ''),
|
||||||
|
|
@ -55,6 +57,22 @@ const loadingModalStub = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const serviceLocationStub = {
|
||||||
|
render: () => {},
|
||||||
|
methods: {
|
||||||
|
forwardButtonAction: jest.fn(),
|
||||||
|
initializeComponent: jest.fn()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const recalAckModalStub = {
|
||||||
|
template: '<div></div>',
|
||||||
|
methods: {
|
||||||
|
openModal: jest.fn(),
|
||||||
|
footerButtonClick: jest.fn()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) {
|
function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) {
|
||||||
const mountOptions = getMountOptions({
|
const mountOptions = getMountOptions({
|
||||||
router: {
|
router: {
|
||||||
|
|
@ -64,7 +82,9 @@ function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) {
|
||||||
|
|
||||||
mountOptions.global.stubs = {
|
mountOptions.global.stubs = {
|
||||||
siteFooter: footerStub,
|
siteFooter: footerStub,
|
||||||
loadingModal: loadingModalStub
|
loadingModal: loadingModalStub,
|
||||||
|
serviceLocation: serviceLocationStub,
|
||||||
|
recalAckModal: recalAckModalStub
|
||||||
};
|
};
|
||||||
|
|
||||||
methodToRun();
|
methodToRun();
|
||||||
|
|
@ -75,6 +95,27 @@ function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) {
|
||||||
);
|
);
|
||||||
|
|
||||||
const wrapper = shallowMount(schedule, mountOptions);
|
const wrapper = shallowMount(schedule, mountOptions);
|
||||||
|
|
||||||
|
// Manually create the ref for recalAckModal since shallowMount doesn't populate it
|
||||||
|
Object.defineProperty(wrapper.vm.$refs, RECAL_ACK_MODAL_REF_NAME, {
|
||||||
|
value: {
|
||||||
|
openModal: jest.fn(),
|
||||||
|
footerButtonClick: jest.fn()
|
||||||
|
},
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Manually create the ref for serviceLocation since shallowMount doesn't populate it
|
||||||
|
Object.defineProperty(wrapper.vm.$refs, 'serviceLocation', {
|
||||||
|
value: {
|
||||||
|
forwardButtonAction: jest.fn(),
|
||||||
|
initializeComponent: jest.fn()
|
||||||
|
},
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
|
||||||
return { wrapper };
|
return { wrapper };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,7 +167,6 @@ afterEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('schedule-page.vue', () => {
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
Object.defineProperty(window, 'matchMedia', { value: jest.fn().mockImplementation((query) => ({
|
Object.defineProperty(window, 'matchMedia', { value: jest.fn().mockImplementation((query) => ({
|
||||||
matches: false,
|
matches: false,
|
||||||
|
|
@ -267,11 +307,23 @@ describe('schedule-page.vue', () => {
|
||||||
// Assert
|
// Assert
|
||||||
expect(testValue).toStrictEqual('01234');
|
expect(testValue).toStrictEqual('01234');
|
||||||
});
|
});
|
||||||
});
|
test('forwardButtonAction should call route method navigate', async () => {
|
||||||
test.skip('forwardButtonAction should call route method navigateWithoutSaving', async () => {
|
|
||||||
// Arrange
|
// Arrange
|
||||||
const { wrapper } = getShallowMountedComponent();
|
const { wrapper } = getShallowMountedComponent();
|
||||||
wrapper.vm.$router.navigate = jest.fn(() => ({}));
|
wrapper.vm.$router.navigate = jest.fn(() => ({}));
|
||||||
|
wrapper.vm.mainStore.saveSchedule = jest.fn();
|
||||||
|
wrapper.vm.navigationScenarios = {
|
||||||
|
CLICKED_FORWARD: 'CLICKED_FORWARD'
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mock the serviceLocation ref using Object.defineProperty to bypass readonly
|
||||||
|
Object.defineProperty(wrapper.vm.$refs, 'serviceLocation', {
|
||||||
|
value: {
|
||||||
|
forwardButtonAction: jest.fn()
|
||||||
|
},
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
|
||||||
wrapper.vm.selectedTimeSlotInfo = {
|
wrapper.vm.selectedTimeSlotInfo = {
|
||||||
timeSlot: {
|
timeSlot: {
|
||||||
routeCode: 'test-id'
|
routeCode: 'test-id'
|
||||||
|
|
@ -284,4 +336,58 @@ describe('schedule-page.vue', () => {
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
test('recalAckModal should open when part requires recal, but recal not added to order', async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = getShallowMountedComponent();
|
||||||
|
wrapper.vm.mainStore.lineItems.glassParts = [
|
||||||
|
{
|
||||||
|
partNumber: 'TEST123',
|
||||||
|
requiresRecalibration: true
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$refs[RECAL_ACK_MODAL_REF_NAME].openModal).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
test('navigation forward is blocked when recalAckModal is displayed, but checkbox has not been acknowledged', async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = getShallowMountedComponent();
|
||||||
|
wrapper.vm.mainStore.lineItems.glassParts = [
|
||||||
|
{
|
||||||
|
partNumber: 'TEST123',
|
||||||
|
requiresRecalibration: true
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
await wrapper.vm.$refs[RECAL_ACK_MODAL_REF_NAME].openModal();
|
||||||
|
await wrapper.vm.$refs[RECAL_ACK_MODAL_REF_NAME].footerButtonClick();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$router.navigate).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
test('navigation forward is allowed when checkbox has been acknowledged on recalAckModal', async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper } = getShallowMountedComponent();
|
||||||
|
wrapper.vm.mainStore.lineItems.glassParts = [
|
||||||
|
{
|
||||||
|
partNumber: 'TEST123',
|
||||||
|
requiresRecalibration: true
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await wrapper.vm.$refs[RECAL_ACK_MODAL_REF_NAME].openModal();
|
||||||
|
wrapper.vm.updateIsRecalAcknowledged(true);
|
||||||
|
await wrapper.vm.$refs[RECAL_ACK_MODAL_REF_NAME].footerButtonClick();
|
||||||
|
await wrapper.vm.forwardButtonAction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
cmsWidgetName="SuggestTimeslotModal"
|
cmsWidgetName="SuggestTimeslotModal"
|
||||||
@confirmAppointmentClicked="autoSelectTimeslotConfirmed" />
|
@confirmAppointmentClicked="autoSelectTimeslotConfirmed" />
|
||||||
<recalAckModal
|
<recalAckModal
|
||||||
ref="recalAckModal"
|
:ref="RECAL_ACK_MODAL_REF_NAME"
|
||||||
cmsWidgetName="RecalAckModalWidget"
|
cmsWidgetName="RecalAckModalWidget"
|
||||||
:ackError="ackError"
|
:ackError="ackError"
|
||||||
@recalAcknowledged="updateIsRecalAcknowledged"/>
|
@recalAcknowledged="updateIsRecalAcknowledged"/>
|
||||||
|
|
@ -117,6 +117,7 @@ import errorMessages from '@/constants/error-messages';
|
||||||
// Define constants
|
// Define constants
|
||||||
const SUGGEST_TIMESLOT_MODAL_REF_NAME = 'SuggestTimeslotModal';
|
const SUGGEST_TIMESLOT_MODAL_REF_NAME = 'SuggestTimeslotModal';
|
||||||
const TIME_SLOTS_CALL_DAYS_LIMIT = 15;
|
const TIME_SLOTS_CALL_DAYS_LIMIT = 15;
|
||||||
|
const RECAL_ACK_MODAL_REF_NAME = 'recalAckModal';
|
||||||
|
|
||||||
const getAvailableDates = async (
|
const getAvailableDates = async (
|
||||||
startDateString,
|
startDateString,
|
||||||
|
|
@ -380,6 +381,7 @@ export default {
|
||||||
selectedTimeSlotInfo: this.getSelectedTimeSlotInfo(),
|
selectedTimeSlotInfo: this.getSelectedTimeSlotInfo(),
|
||||||
showDatePickerError: false,
|
showDatePickerError: false,
|
||||||
SUGGEST_TIMESLOT_MODAL_REF_NAME,
|
SUGGEST_TIMESLOT_MODAL_REF_NAME,
|
||||||
|
RECAL_ACK_MODAL_REF_NAME,
|
||||||
isRecalAcknowledged: this.getIsRecalAcknowledgedForScheduling()
|
isRecalAcknowledged: this.getIsRecalAcknowledgedForScheduling()
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -960,7 +962,7 @@ export default {
|
||||||
async forwardButtonAction() {
|
async forwardButtonAction() {
|
||||||
if (this.displayRecalAckModal && this.isRecalAcknowledged === false) {
|
if (this.displayRecalAckModal && this.isRecalAcknowledged === false) {
|
||||||
showIssLoadingModal(false);
|
showIssLoadingModal(false);
|
||||||
this.$refs.recalAckModal.openModal();
|
this.$refs[RECAL_ACK_MODAL_REF_NAME].openModal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue