2018-06-04 07:48:32 +00:00
|
|
|
import './index.js';
|
2018-12-27 11:54:16 +00:00
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2018-06-04 07:48:32 +00:00
|
|
|
|
2018-07-31 11:49:54 +00:00
|
|
|
describe('Item', () => {
|
2018-06-04 07:48:32 +00:00
|
|
|
describe('Component vnItemDiary', () => {
|
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('item'));
|
2018-06-04 07:48:32 +00:00
|
|
|
|
2020-03-17 13:43:46 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
|
2018-06-04 07:48:32 +00:00
|
|
|
$scope = $rootScope.$new();
|
2020-03-17 13:43:46 +00:00
|
|
|
const $element = angular.element('<vn-item-diary></vn-item-diary>');
|
|
|
|
controller = $componentController('vnItemDiary', {$element, $scope});
|
|
|
|
controller.$.model = crudModel;
|
|
|
|
controller.$params = {id: 1};
|
2018-06-04 07:48:32 +00:00
|
|
|
}));
|
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
describe('set item()', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
it('should set warehouseFk property based on itemType warehouseFk', () => {
|
2020-03-17 13:43:46 +00:00
|
|
|
jest.spyOn(controller.$, '$applyAsync');
|
2018-09-06 13:08:02 +00:00
|
|
|
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
2018-07-04 06:50:34 +00:00
|
|
|
|
2020-03-17 13:43:46 +00:00
|
|
|
expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
|
2019-02-13 06:57:08 +00:00
|
|
|
$scope.$apply();
|
2018-09-18 11:34:11 +00:00
|
|
|
|
2018-09-06 13:08:02 +00:00
|
|
|
expect(controller.warehouseFk).toEqual(1);
|
|
|
|
expect(controller.item.id).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should set warehouseFk property based on url query warehouseFk`, () => {
|
2020-03-17 13:43:46 +00:00
|
|
|
jest.spyOn(controller.$, '$applyAsync');
|
|
|
|
controller.$params.warehouseFk = 4;
|
2018-09-06 13:08:02 +00:00
|
|
|
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
|
|
|
|
2020-03-17 13:43:46 +00:00
|
|
|
expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
|
2019-02-13 06:57:08 +00:00
|
|
|
$scope.$apply();
|
2018-09-18 11:34:11 +00:00
|
|
|
|
2018-09-06 13:08:02 +00:00
|
|
|
expect(controller.warehouseFk).toEqual(4);
|
|
|
|
expect(controller.item.id).toEqual(1);
|
2018-06-04 07:48:32 +00:00
|
|
|
});
|
|
|
|
});
|
2020-05-19 10:21:02 +00:00
|
|
|
|
|
|
|
describe('scrollToLine ()', () => {
|
|
|
|
it('should assign $location then call anchorScroll using controller value', () => {
|
|
|
|
jest.spyOn(controller, '$anchorScroll');
|
2020-05-19 11:06:59 +00:00
|
|
|
controller.lineFk = 1;
|
2020-05-19 10:21:02 +00:00
|
|
|
controller.scrollToLine('invalidValue');
|
|
|
|
|
2020-05-19 11:06:59 +00:00
|
|
|
expect(controller.$location.hash()).toEqual(`vnItemDiary-${1}`);
|
2020-05-19 10:21:02 +00:00
|
|
|
expect(controller.$anchorScroll).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should assign $location then call anchorScroll using received value', () => {
|
|
|
|
jest.spyOn(controller, '$anchorScroll');
|
2020-05-19 11:06:59 +00:00
|
|
|
controller.lineFk = undefined;
|
2020-05-19 10:21:02 +00:00
|
|
|
controller.scrollToLine(1);
|
|
|
|
|
2020-05-19 11:06:59 +00:00
|
|
|
expect(controller.$location.hash()).toEqual(`vnItemDiary-${1}`);
|
2020-05-19 10:21:02 +00:00
|
|
|
expect(controller.$anchorScroll).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2018-06-04 07:48:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|