Updated unit test
gitea/salix/2113-item_data_add_instrastat This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-02-17 13:32:12 +01:00
parent 844b27acb9
commit 7d8e88e884
1 changed files with 15 additions and 10 deletions

View File

@ -2,26 +2,31 @@ import './index.js';
describe('vnItemBasicData', () => { describe('vnItemBasicData', () => {
describe('Component vnItemBasicData', () => { describe('Component vnItemBasicData', () => {
let $httpBackend;
let $scope; let $scope;
let controller; let controller;
let $timeout; let $element;
beforeEach(ngModule('item')); beforeEach(ngModule('item'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$timeout_) => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
$timeout = _$timeout_; $httpBackend = _$httpBackend_;
$scope = $rootScope.$new(); $scope = $rootScope.$new();
controller = $componentController('vnItemBasicData', {$scope, $timeout}); $element = angular.element('<vn-item-basic-data></vn-item-basic-data>');
controller.$scope.watcher = {}; controller = $componentController('vnItemBasicData', {$element, $scope});
controller.$.watcher = {};
controller.$params.id = 1;
controller.item = {id: 1, name: 'Rainbow Coral'};
})); }));
describe('$onChanges()', () => { describe('onIntrastatAccept()', () => {
it('should pass the data to the watcher', () => { it('should pass the data to the watcher', () => {
const data = {item: {currentValue: 'the current value of an item'}}; const newIntrastatId = 20;
controller.$onChanges(data); $httpBackend.expect('PATCH', 'Items/1/createIntrastat').respond({id: 20});
$timeout.flush(); controller.onIntrastatAccept();
$httpBackend.flush();
expect(controller.$scope.watcher.data).toMatchSnapshot(); expect(controller.item.intrastatFk).toEqual(newIntrastatId);
}); });
}); });
}); });