salix/modules/worker/front/create/index.spec.js

134 lines
4.4 KiB
JavaScript
Raw Normal View History

2022-11-14 14:19:16 +00:00
import './index';
2023-01-04 08:23:18 +00:00
describe('Worker', () => {
describe('Component vnWorkerCreate', () => {
2022-11-14 14:19:16 +00:00
let $scope;
let $state;
let controller;
2023-01-04 08:23:18 +00:00
beforeEach(ngModule('worker'));
2022-11-14 14:19:16 +00:00
beforeEach(inject(($componentController, $rootScope, _$state_) => {
$scope = $rootScope.$new();
$state = _$state_;
$scope.watcher = {
submit: () => {
return {
then: callback => {
callback({data: {id: '1234'}});
}
};
}
};
2023-01-04 08:23:18 +00:00
const $element = angular.element('<vn-worker-create></vn-worker-create>');
controller = $componentController('vnWorkerCreate', {$element, $scope});
controller.worker = {};
controller.vnConfig = {user: {companyFk: 1}};
2022-11-14 14:19:16 +00:00
}));
describe('onSubmit()', () => {
it(`should call submit() on the watcher then expect a callback`, () => {
jest.spyOn($state, 'go');
controller.onSubmit();
2023-01-04 08:23:18 +00:00
expect(controller.$state.go).toHaveBeenCalledWith('worker.card.basicData', {id: '1234'});
2022-11-14 14:19:16 +00:00
});
});
describe('province() setter', () => {
it(`should set countryFk property`, () => {
2023-01-04 08:23:18 +00:00
controller.worker.countryFk = null;
2022-11-14 14:19:16 +00:00
controller.province = {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
};
2023-01-04 08:23:18 +00:00
expect(controller.worker.countryFk).toEqual(2);
2022-11-14 14:19:16 +00:00
});
});
describe('town() setter', () => {
it(`should set provinceFk property`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: []
};
2023-01-04 08:23:18 +00:00
expect(controller.worker.provinceFk).toEqual(1);
2022-11-14 14:19:16 +00:00
});
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: [{code: '46001'}]
};
2023-01-04 08:23:18 +00:00
expect(controller.worker.provinceFk).toEqual(1);
expect(controller.worker.postcode).toEqual('46001');
2022-11-14 14:19:16 +00:00
});
});
describe('postcode() setter', () => {
it(`should set the town, provinceFk and contryFk properties`, () => {
controller.postcode = {
townFk: 1,
code: 46001,
town: {
id: 1,
name: 'New York',
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
}
}
};
2023-01-04 08:23:18 +00:00
expect(controller.worker.city).toEqual('New York');
expect(controller.worker.provinceFk).toEqual(1);
expect(controller.worker.countryFk).toEqual(2);
});
});
describe('generateCodeUser()', () => {
it(`should generate worker code, name and company `, () => {
2023-01-04 08:23:18 +00:00
controller.worker = {
firstName: 'default',
lastNames: 'generate worker'
};
controller.generateCodeUser();
expect(controller.worker.code).toEqual('DGW');
expect(controller.worker.name).toEqual('defaultgw');
expect(controller.worker.companyFk).toEqual(controller.vnConfig.user.companyFk);
2022-11-14 14:19:16 +00:00
});
});
});
});