salix/modules/travel/front/index/index.spec.js

79 lines
2.4 KiB
JavaScript
Raw Permalink Normal View History

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 = {
ref: 1,
2022-07-13 12:36:03 +00:00
agencyModeFk: 1
};
const travelParams = {
ref: travel.ref,
2022-07-13 12:36:03 +00:00
agencyModeFk: travel.agencyModeFk
2020-03-10 13:09:26 +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});
});
});
describe('compareDate()', () => {
it('should return warning if the date passed to compareDate() is todays', () => {
2023-01-16 14:18:24 +00:00
const today = Date.vnNew();
const result = controller.compareDate(today);
expect(result).toEqual('warning');
});
it('should return success if the date passed to compareDate() is in the future', () => {
2023-01-16 14:18:24 +00:00
const tomorrow = Date.vnNew();
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', () => {
2023-01-16 14:18:24 +00:00
const yesterday = Date.vnNew();
yesterday.setDate(yesterday.getDate() - 1);
const result = controller.compareDate(yesterday);
expect(result).toBeUndefined();
});
});
2019-10-25 11:29:05 +00:00
});