Merge pull request #2308 from Safelite/feature/CASH-245
CASH-245 | Add insurance-company unit tests
This commit is contained in:
commit
bc6373e3bd
2 changed files with 105 additions and 3 deletions
|
|
@ -1,3 +0,0 @@
|
|||
describe("insurance-company.vue", () => {
|
||||
it.todo("Some test for the future");
|
||||
});
|
||||
105
src/layouts/insurance-company/insurance-company.spec.js
Normal file
105
src/layouts/insurance-company/insurance-company.spec.js
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
import { shallowMount } from '@vue/test-utils';
|
||||
import InsuranceCompany from '@/layouts/insurance-company/insurance-company.vue';
|
||||
import { applicationConfig } from '@/constants/application-config.js';
|
||||
import store from "@/store";
|
||||
import baseMixin from "@/mixins/base-mixin.js";
|
||||
|
||||
|
||||
jest.mock('@/store', () => ({
|
||||
getters: {
|
||||
order: {
|
||||
payment: {
|
||||
parentAccountNumber: '12345',
|
||||
},
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
var mockRouter = {
|
||||
navigateWithoutSaving: jest.fn(),
|
||||
};
|
||||
|
||||
jest.mock('@/mixins/base-mixin.js', () => ({
|
||||
methods: {
|
||||
navigateWithoutSaving: jest.fn(),
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
navigationScenarios: {
|
||||
CLICKED_BACK: 'clicked_back',
|
||||
},
|
||||
};
|
||||
},
|
||||
}));
|
||||
|
||||
describe("insurance-company.vue", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
// Reset the store's parentAccountNumber before each test
|
||||
store.getters.order.payment.parentAccountNumber = '12345';
|
||||
});
|
||||
|
||||
test('should return true when parentAccountNumber matches CASH_PARENT_ACCOUNT_NUMBER', () => {
|
||||
applicationConfig.CASH_PARENT_ACCOUNT_NUMBER = "12345";
|
||||
const wrapper = shallowMount(InsuranceCompany, {
|
||||
global: {
|
||||
mocks: {
|
||||
$store: store
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.vm.isCashParentAccountNumber()).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false when parentAccountNumber does not match CASH_PARENT_ACCOUNT_NUMBER', () => {
|
||||
applicationConfig.CASH_PARENT_ACCOUNT_NUMBER = "12345";
|
||||
store.getters.order.payment.parentAccountNumber = '67890';
|
||||
const wrapper = shallowMount(InsuranceCompany, {
|
||||
global: {
|
||||
mocks: {
|
||||
$store: store,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.vm.isCashParentAccountNumber()).toBe(false);
|
||||
});
|
||||
|
||||
test('should call navigateWithoutSaving with { isCashSelected: true } when forceCashSelection is true', () => {
|
||||
const wrapper = shallowMount(InsuranceCompany, {
|
||||
global: {
|
||||
mocks: {
|
||||
$store: store,
|
||||
$router: mockRouter,
|
||||
},
|
||||
mixins: [baseMixin],
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
wrapper.vm.backButtonAction(true);
|
||||
expect(mockRouter.navigateWithoutSaving).toHaveBeenCalledWith(
|
||||
wrapper.vm.navigationScenarios.CLICKED_BACK,
|
||||
wrapper.vm.$route,
|
||||
{ isCashSelected: true }
|
||||
);
|
||||
});
|
||||
|
||||
test('should call navigateWithoutSaving with no extra parameter when forceCashSelection is false', () => {
|
||||
const wrapper = shallowMount(InsuranceCompany, {
|
||||
global: {
|
||||
mocks: {
|
||||
$store: store,
|
||||
$router: mockRouter,
|
||||
},
|
||||
mixins: [baseMixin],
|
||||
},
|
||||
});
|
||||
wrapper.vm.backButtonAction(false);
|
||||
expect(mockRouter.navigateWithoutSaving).toHaveBeenCalledWith(
|
||||
wrapper.vm.navigationScenarios.CLICKED_BACK,
|
||||
wrapper.vm.$route
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue