79 lines
2.4 KiB
JavaScript
79 lines
2.4 KiB
JavaScript
import './index.js';
|
|
|
|
describe('Travel Component vnTravelIndex', () => {
|
|
let controller;
|
|
let travel = {
|
|
id: 1,
|
|
warehouseInFk: 1,
|
|
totalEntries: 3,
|
|
isDelivered: false
|
|
};
|
|
|
|
beforeEach(ngModule('travel'));
|
|
|
|
beforeEach(inject($componentController => {
|
|
const $element = angular.element('<vn-travel-index></vn-travel-index>');
|
|
controller = $componentController('vnTravelIndex', {$element});
|
|
controller.$.summary = {show: jasmine.createSpy('show')};
|
|
}));
|
|
|
|
describe('preview()', () => {
|
|
it('should show the dialog summary', () => {
|
|
let event = new MouseEvent('click', {
|
|
bubbles: true,
|
|
cancelable: true
|
|
});
|
|
controller.preview(event, travel);
|
|
|
|
expect(controller.$.summary.show).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
|
|
describe('onCloneAccept()', () => {
|
|
it('should call go() then update travelSelected in the controller', () => {
|
|
jest.spyOn(controller.$state, 'go');
|
|
|
|
const travel = {
|
|
ref: 1,
|
|
agencyModeFk: 1
|
|
};
|
|
const travelParams = {
|
|
ref: travel.ref,
|
|
agencyModeFk: travel.agencyModeFk
|
|
};
|
|
const queryParams = JSON.stringify(travelParams);
|
|
controller.onCloneAccept(travel);
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('travel.create', {q: queryParams});
|
|
});
|
|
});
|
|
|
|
describe('compareDate()', () => {
|
|
it('should return warning if the date passed to compareDate() is todays', () => {
|
|
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', () => {
|
|
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', () => {
|
|
const yesterday = Date.vnNew();
|
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
|
|
const result = controller.compareDate(yesterday);
|
|
|
|
expect(result).toBeUndefined();
|
|
});
|
|
});
|
|
});
|