2019-10-25 11:29:05 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Travel Component vnTravelIndex', () => {
|
|
|
|
let controller;
|
2020-03-16 17:08:44 +00:00
|
|
|
let travel = {
|
2019-12-20 06:55:00 +00:00
|
|
|
id: 1,
|
|
|
|
warehouseInFk: 1,
|
|
|
|
totalEntries: 3,
|
|
|
|
isDelivered: false
|
2020-03-16 17:08:44 +00:00
|
|
|
};
|
2019-10-25 11:29:05 +00:00
|
|
|
|
2020-03-16 17:08:44 +00:00
|
|
|
beforeEach(ngModule('travel'));
|
2019-10-25 11:29:05 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject($componentController => {
|
2020-03-18 11:55:22 +00:00
|
|
|
const $element = angular.element('<vn-travel-index></vn-travel-index>');
|
|
|
|
controller = $componentController('vnTravelIndex', {$element});
|
2019-12-20 06:55:00 +00:00
|
|
|
controller.$.summary = {show: jasmine.createSpy('show')};
|
2019-10-25 11:29:05 +00:00
|
|
|
}));
|
|
|
|
|
2019-12-20 06:55:00 +00:00
|
|
|
describe('preview()', () => {
|
|
|
|
it('should show the dialog summary', () => {
|
|
|
|
let event = new MouseEvent('click', {
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true
|
|
|
|
});
|
2020-03-16 17:08:44 +00:00
|
|
|
controller.preview(event, travel);
|
2019-10-25 11:29:05 +00:00
|
|
|
|
2019-12-20 06:55:00 +00:00
|
|
|
expect(controller.$.summary.show).toHaveBeenCalledWith();
|
2019-10-25 11:29:05 +00:00
|
|
|
});
|
2019-12-20 06:55:00 +00:00
|
|
|
});
|
|
|
|
|
2020-03-10 13:09:26 +00:00
|
|
|
describe('onCloneAccept()', () => {
|
|
|
|
it('should call go() then update travelSelected in the controller', () => {
|
|
|
|
jest.spyOn(controller.$state, 'go');
|
|
|
|
|
|
|
|
const travel = {
|
2020-03-16 17:33:39 +00:00
|
|
|
ref: 1,
|
|
|
|
agencyFk: 1
|
|
|
|
};
|
|
|
|
const travelParams = {
|
|
|
|
ref: travel.ref,
|
|
|
|
agencyModeFk: travel.agencyFk
|
2020-03-10 13:09:26 +00:00
|
|
|
};
|
2020-03-16 17:33:39 +00:00
|
|
|
const queryParams = JSON.stringify(travelParams);
|
|
|
|
controller.onCloneAccept(travel);
|
2020-03-10 13:09:26 +00:00
|
|
|
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('travel.create', {q: queryParams});
|
|
|
|
});
|
|
|
|
});
|
2020-11-13 12:04:22 +00:00
|
|
|
|
|
|
|
describe('compareDate()', () => {
|
|
|
|
it('should return warning if the date passed to compareDate() is todays', () => {
|
|
|
|
const today = new Date();
|
|
|
|
|
|
|
|
const result = controller.compareDate(today);
|
|
|
|
|
|
|
|
expect(result).toEqual('warning');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return success if the date passed to compareDate() is in the future', () => {
|
|
|
|
const tomorrow = new Date();
|
|
|
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
|
|
|
|
|
|
const result = controller.compareDate(tomorrow);
|
|
|
|
|
|
|
|
expect(result).toEqual('success');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return undefined if the date passed to compareDate() is in the past', () => {
|
|
|
|
const yesterday = new Date();
|
|
|
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
|
|
|
|
|
|
const result = controller.compareDate(yesterday);
|
|
|
|
|
|
|
|
expect(result).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
2019-10-25 11:29:05 +00:00
|
|
|
});
|