salix/client/item/src/diary/index.spec.js

44 lines
1.6 KiB
JavaScript
Raw Normal View History

import './index.js';
describe('Item', () => {
describe('Component vnItemDiary', () => {
let $componentController;
let $scope;
let controller;
let $httpBackend;
beforeEach(() => {
angular.mock.module('item');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
controller = $componentController('vnItemDiary', {$scope: $scope});
controller.item = {id: 3};
}));
describe('set warehouseFk()', () => {
it(`should call _getItemDiary() with 2 and set warehouseFk`, () => {
spyOn(controller, '_getItemDiary');
controller.warehouseFk = 2;
expect(controller._getItemDiary).toHaveBeenCalledWith(2);
expect(controller.warehouseFk).toEqual(2);
});
});
describe('_getItemDiary()', () => {
it(`should make a request to get the diary hwen is called with a number`, () => {
$httpBackend.whenGET('/item/api/Items/getDiary?params={"itemFk":3,"warehouseFk":2}').respond({data: 'item'});
$httpBackend.expectGET('/item/api/Items/getDiary?params={"itemFk":3,"warehouseFk":2}');
controller._getItemDiary(2);
$httpBackend.flush();
});
});
});
});