2022-09-17 20:19:38 +03:00

146 lines
4.7 KiB
JavaScript

import { defaultOptions, defaultStatuses, defaultValues } from 'config/tables/insurance-table';
import { toJS } from 'mobx';
import RootStore from 'stores/root';
const INSURANCE_COMPANIES_OPTIONS = [
{
label: 'TEST',
value: 'TEST',
},
{
label: 'TEST2',
value: 'TEST2',
},
];
const INSURED_OPTIONS = [
{
label: 'TEST',
value: 'TEST',
},
];
describe('stores/tables/insurance', () => {
describe('[method] setRowValues', () => {
it('should set only insuranceCompany value', () => {
const rootStore = new RootStore();
const { insurance } = rootStore.$tables;
const TEST_VALUE = 'TEST_VALUE';
insurance.setRowValues('kasko', {
insuranceCompany: TEST_VALUE,
});
const KASKO_VALUES = toJS(insurance.values.find((x) => x.key === 'kasko'));
const DEFAULT_KASKO_VALUES = defaultValues.find((x) => x.key === 'kasko');
expect(KASKO_VALUES.insuranceCompany).toEqual(TEST_VALUE);
expect(KASKO_VALUES.insured).toEqual(DEFAULT_KASKO_VALUES.insured);
expect(KASKO_VALUES.insTerm).toEqual(DEFAULT_KASKO_VALUES.insTerm);
});
});
describe('[method] setRowOptions', () => {
it('should replace only insuranceCompany options', () => {
const rootStore = new RootStore();
const { insurance } = rootStore.$tables;
insurance.setRowOptions('kasko', {
insuranceCompany: INSURANCE_COMPANIES_OPTIONS,
});
const KASKO = toJS(insurance.getRowOptions('kasko'));
expect(KASKO.insuranceCompany).toEqual(INSURANCE_COMPANIES_OPTIONS);
expect(KASKO.insured).toEqual(defaultOptions.kasko.insured);
expect(KASKO.insTerm).toEqual(defaultOptions.kasko.insTerm);
});
it('should replace insuranceCompany and insured options', () => {
const rootStore = new RootStore();
const { insurance } = rootStore.$tables;
insurance.setRowOptions('kasko', {
insuranceCompany: INSURANCE_COMPANIES_OPTIONS,
insured: INSURED_OPTIONS,
});
const KASKO = toJS(insurance.getRowOptions('kasko'));
expect(KASKO.insuranceCompany).toEqual(INSURANCE_COMPANIES_OPTIONS);
expect(KASKO.insured).toEqual(INSURED_OPTIONS);
expect(KASKO.insTerm).toEqual(defaultOptions.kasko.insTerm);
});
});
describe('[method] setManyRowOptions', () => {
it('should replace only kasko options', () => {
const rootStore = new RootStore();
const { insurance } = rootStore.$tables;
insurance.setManyRowOptions({
kasko: {
insuranceCompany: INSURANCE_COMPANIES_OPTIONS,
insured: INSURED_OPTIONS,
},
});
const KASKO = toJS(insurance.getRowOptions('kasko'));
const OSAGO = toJS(insurance.getRowOptions('osago'));
const FINGAP = toJS(insurance.getRowOptions('fingap'));
expect(KASKO.insuranceCompany).toEqual(INSURANCE_COMPANIES_OPTIONS);
expect(KASKO.insured).toEqual(INSURED_OPTIONS);
expect(KASKO.insTerm).toEqual(defaultOptions.kasko.insTerm);
expect(OSAGO).toEqual(defaultOptions.osago);
expect(FINGAP).toEqual(defaultOptions.fingap);
});
it('should replace only kasko and osago options', () => {
const rootStore = new RootStore();
const { insurance } = rootStore.$tables;
insurance.setManyRowOptions({
kasko: {
insuranceCompany: INSURANCE_COMPANIES_OPTIONS,
insured: INSURED_OPTIONS,
},
osago: {
insured: INSURED_OPTIONS,
},
});
const KASKO = toJS(insurance.getRowOptions('kasko'));
const OSAGO = toJS(insurance.getRowOptions('osago'));
const FINGAP = toJS(insurance.getRowOptions('fingap'));
expect(KASKO.insuranceCompany).toEqual(INSURANCE_COMPANIES_OPTIONS);
expect(KASKO.insured).toEqual(INSURED_OPTIONS);
expect(KASKO.insTerm).toEqual(defaultOptions.kasko.insTerm);
expect(OSAGO.insured).toEqual(INSURED_OPTIONS);
expect(OSAGO.insTerm).toEqual(defaultOptions.osago.insTerm);
expect(FINGAP).toEqual(defaultOptions.fingap);
});
});
describe('[method] setRowStatuses', () => {
it('should replace only insuranceCompany and insured statuses', () => {
const rootStore = new RootStore();
const { insurance } = rootStore.$tables;
insurance.setRowStatuses('kasko', {
insuranceCompany: 'Disabled',
insured: 'Disabled',
});
const KASKO = toJS(insurance.getRowStatuses('kasko'));
expect(KASKO.insuranceCompany).toEqual('Disabled');
expect(KASKO.insured).toEqual('Disabled');
expect(KASKO.insCost).toEqual(defaultStatuses.kasko.insCost);
expect(KASKO.insTerm).toEqual(defaultStatuses.kasko.insTerm);
expect(KASKO.policyType).toEqual(defaultStatuses.kasko.policyType);
});
});
});