salix/modules/item/front/diary/index.spec.js

66 lines
2.5 KiB
JavaScript
Raw Normal View History

import './index.js';
2018-12-27 11:54:16 +00:00
import crudModel from 'core/mocks/crud-model';
describe('Item', () => {
describe('Component vnItemDiary', () => {
let $scope;
let controller;
beforeEach(ngModule('item'));
2020-07-23 14:46:16 +00:00
beforeEach(inject(($componentController, $rootScope) => {
$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};
}));
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}};
2020-03-17 13:43:46 +00:00
expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
$scope.$apply();
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));
$scope.$apply();
2018-09-06 13:08:02 +00:00
expect(controller.warehouseFk).toEqual(4);
expect(controller.item.id).toEqual(1);
});
});
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();
});
});
});
});