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('Component vnItemBasicData', () => {
let $httpBackend;
let $scope;
let controller;
let $timeout;
let $element;
beforeEach(ngModule('item'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$timeout_) => {
$timeout = _$timeout_;
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
controller = $componentController('vnItemBasicData', {$scope, $timeout});
controller.$scope.watcher = {};
$element = angular.element('<vn-item-basic-data></vn-item-basic-data>');
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', () => {
const data = {item: {currentValue: 'the current value of an item'}};
controller.$onChanges(data);
$timeout.flush();
const newIntrastatId = 20;
$httpBackend.expect('PATCH', 'Items/1/createIntrastat').respond({id: 20});
controller.onIntrastatAccept();
$httpBackend.flush();
expect(controller.$scope.watcher.data).toMatchSnapshot();
expect(controller.item.intrastatFk).toEqual(newIntrastatId);
});
});
});