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-03-17 13:43:46 +00:00
beforeEach(angular.mock.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');
controller.ticketFk = 1;
controller.scrollToLine('invalidValue');
expect(controller.$location).toEqual(`vnItemDiary-${1}`);
expect(controller.$anchorScroll).toHaveBeenCalledWith();
});
it('should assign $location then call anchorScroll using received value', () => {
jest.spyOn(controller, '$anchorScroll');
controller.ticketFk = undefined;
controller.scrollToLine(1);
expect(controller.$location).toEqual(`vnItemDiary-${1}`);
expect(controller.$anchorScroll).toHaveBeenCalledWith();
});
});
});
});