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', () => {
|
2018-09-06 13:08:02 +00:00
|
|
|
let $stateParams;
|
2018-06-04 07:48:32 +00:00
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('item'));
|
2018-06-04 07:48:32 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$stateParams_) => {
|
2018-09-06 13:08:02 +00:00
|
|
|
$stateParams = _$stateParams_;
|
|
|
|
$stateParams.id = 1;
|
2018-06-04 07:48:32 +00:00
|
|
|
$scope = $rootScope.$new();
|
2018-12-22 10:59:26 +00:00
|
|
|
controller = $componentController('vnItemDiary', {$scope, $stateParams});
|
2018-09-18 11:34:11 +00:00
|
|
|
controller.$scope.model = crudModel;
|
2018-06-04 07:48:32 +00:00
|
|
|
}));
|
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
describe('isToday()', () => {
|
|
|
|
it(`should call isToday() an return true if an specified date is the current date`, () => {
|
|
|
|
let date = new Date();
|
2018-06-04 07:48:32 +00:00
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
let result = controller.isToday(date);
|
|
|
|
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should call isToday() an return false if an specified date is the current date`, () => {
|
|
|
|
let date = '2018-07-03';
|
|
|
|
|
|
|
|
let result = controller.isToday(date);
|
|
|
|
|
|
|
|
expect(result).toBeFalsy();
|
2018-06-04 07:48:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-30 10:12:41 +00:00
|
|
|
describe('freeLineIndex()', () => {
|
|
|
|
it(`should call freeLineIndex() and return an index from line with alertLevel 0 and current date`, () => {
|
2018-09-03 08:55:04 +00:00
|
|
|
let currentDate = new Date();
|
|
|
|
currentDate.setDate(currentDate.getDate() + 1);
|
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
controller.$scope.model = {data: [
|
|
|
|
{name: 'My item 1', alertLevel: 3, date: '2018-05-02'},
|
|
|
|
{name: 'My item 2', alertLevel: 1, date: '2018-05-03'},
|
2018-09-03 08:55:04 +00:00
|
|
|
{name: 'My item 3', alertLevel: 0, date: currentDate}]
|
2018-07-04 06:50:34 +00:00
|
|
|
};
|
2018-07-30 10:12:41 +00:00
|
|
|
let result = controller.freeLineIndex;
|
2018-07-04 06:50:34 +00:00
|
|
|
|
|
|
|
expect(result).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-30 10:12:41 +00:00
|
|
|
describe('onPreparationLineIndex()', () => {
|
|
|
|
it(`should call onPreparationLineIndex() and return an index from line with alertLevel 1 and isPicked true`, () => {
|
2018-09-03 08:55:04 +00:00
|
|
|
let currentDate = new Date();
|
|
|
|
currentDate.setDate(currentDate.getDate() + 1);
|
2018-07-30 10:12:41 +00:00
|
|
|
controller.$scope.model = {data: [
|
2018-11-14 10:17:33 +00:00
|
|
|
{name: 'My item 1', alertLevel: 3, isPicked: true, date: currentDate},
|
|
|
|
{name: 'My item 3', alertLevel: 1, isPicked: true, date: currentDate},
|
|
|
|
{name: 'My item 4', alertLevel: 1, isPicked: false, date: currentDate},
|
2018-09-03 08:55:04 +00:00
|
|
|
{name: 'My item 5', alertLevel: 0, isPicked: false, date: currentDate}]
|
2018-07-30 10:12:41 +00:00
|
|
|
};
|
|
|
|
let result = controller.onPreparationLineIndex;
|
|
|
|
|
2018-11-14 10:17:33 +00:00
|
|
|
expect(result).toEqual(1);
|
2018-07-30 10:12:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
describe('set item()', () => {
|
2018-09-06 13:08:02 +00:00
|
|
|
it(`should set warehouseFk property based on itemType warehouseFk`, () => {
|
2019-02-13 06:57:08 +00:00
|
|
|
spyOn(controller.$scope, '$applyAsync').and.callThrough();
|
2018-09-06 13:08:02 +00:00
|
|
|
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
2018-07-04 06:50:34 +00:00
|
|
|
|
2019-02-13 06:57:08 +00:00
|
|
|
expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
|
|
|
|
$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`, () => {
|
2019-02-13 06:57:08 +00:00
|
|
|
spyOn(controller.$scope, '$applyAsync').and.callThrough();
|
2018-09-06 13:08:02 +00:00
|
|
|
controller.$stateParams.warehouseFk = 4;
|
|
|
|
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
|
|
|
|
2019-02-13 06:57:08 +00:00
|
|
|
expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function));
|
|
|
|
$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
|
|
|
});
|
|
|
|
});
|
2018-10-05 14:13:30 +00:00
|
|
|
|
|
|
|
describe('givenTicketIndex() setter', () => {
|
|
|
|
it(`should return the index position of the line of a given ticket fk`, () => {
|
|
|
|
controller.$scope.model = {data: [
|
|
|
|
{name: 'My item 1', origin: 1, alertLevel: 3, isPicked: true, date: '2018-05-02'},
|
|
|
|
{name: 'My item 3', origin: 2, alertLevel: 1, isPicked: true, date: '2018-05-03'},
|
|
|
|
{name: 'My item 4', origin: 3, alertLevel: 1, isPicked: false, date: '2018-05-03'}]
|
|
|
|
};
|
|
|
|
controller.ticketFk = 2;
|
|
|
|
|
|
|
|
let index = controller.givenTicketIndex;
|
|
|
|
|
|
|
|
expect(controller.$scope.model.data[index].origin).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
2018-06-04 07:48:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|