66 lines
2.5 KiB
JavaScript
66 lines
2.5 KiB
JavaScript
import './index.js';
|
|
import crudModel from 'core/mocks/crud-model';
|
|
|
|
describe('Item', () => {
|
|
describe('Component vnItemDiary', () => {
|
|
let $scope;
|
|
let controller;
|
|
|
|
beforeEach(ngModule('item'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope) => {
|
|
$scope = $rootScope.$new();
|
|
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()', () => {
|
|
it('should set warehouseFk property based on itemType warehouseFk', () => {
|
|
jest.spyOn(controller.$, '$applyAsync');
|
|
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
|
|
|
expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
|
|
$scope.$apply();
|
|
|
|
expect(controller.warehouseFk).toEqual(1);
|
|
expect(controller.item.id).toEqual(1);
|
|
});
|
|
|
|
it(`should set warehouseFk property based on url query warehouseFk`, () => {
|
|
jest.spyOn(controller.$, '$applyAsync');
|
|
controller.$params.warehouseFk = 4;
|
|
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
|
|
|
expect(controller.$.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
|
|
$scope.$apply();
|
|
|
|
expect(controller.warehouseFk).toEqual(4);
|
|
expect(controller.item.id).toEqual(1);
|
|
});
|
|
});
|
|
|
|
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();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|