2020-06-18 10:43:33 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('component vnZoneEvents', () => {
|
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
|
|
|
beforeEach(ngModule('zone'));
|
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
2020-06-18 10:43:33 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
const $element = angular.element(`<vn-zone-events></vn-zone-events>`);
|
|
|
|
controller = $componentController('vnZoneEvents', {$element, $scope});
|
|
|
|
controller.$params = {id: 1};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('refresh()', () => {
|
|
|
|
it('should set the zone and then call both getSummary() and getWarehouses()', () => {
|
2021-11-09 09:21:28 +00:00
|
|
|
const date = '2021-10-01';
|
2021-11-09 07:39:20 +00:00
|
|
|
|
|
|
|
controller.$params.id = 999;
|
|
|
|
controller.$.calendar = {
|
2021-11-09 09:21:28 +00:00
|
|
|
firstDay: date,
|
|
|
|
lastDay: date
|
2021-11-09 07:39:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
zoneFk: controller.$params.id,
|
2021-11-09 09:21:28 +00:00
|
|
|
started: date,
|
|
|
|
ended: date
|
2021-11-09 07:39:20 +00:00
|
|
|
};
|
|
|
|
|
2021-11-09 09:21:28 +00:00
|
|
|
const query = `Zones/getEventsFiltered?ended=${date}&started=${date}&zoneFk=${params.zoneFk}`;
|
2021-11-09 07:39:20 +00:00
|
|
|
const response = {
|
|
|
|
events: 'myEvents',
|
2022-05-27 11:54:35 +00:00
|
|
|
exclusions: 'myExclusions',
|
|
|
|
geoExclusions: 'myGeoExclusions',
|
2021-11-09 07:39:20 +00:00
|
|
|
};
|
|
|
|
$httpBackend.whenGET(query).respond(response);
|
2020-06-18 10:43:33 +00:00
|
|
|
controller.refresh();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
const data = controller.$.data;
|
|
|
|
|
|
|
|
expect(data.events).toBeDefined();
|
|
|
|
expect(data.exclusions).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onSelection()', () => {
|
|
|
|
it('should call the edit() method', () => {
|
|
|
|
jest.spyOn(controller, 'edit').mockReturnThis();
|
|
|
|
|
|
|
|
const weekday = {};
|
|
|
|
const days = [];
|
|
|
|
const type = 'EventType';
|
|
|
|
const events = [{name: 'Event'}];
|
|
|
|
const exclusions = [];
|
|
|
|
controller.editMode = 'include';
|
|
|
|
controller.onSelection(days, type, weekday, events, exclusions);
|
|
|
|
|
|
|
|
expect(controller.edit).toHaveBeenCalledWith({name: 'Event'});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call the create() method', () => {
|
|
|
|
jest.spyOn(controller, 'create').mockReturnThis();
|
|
|
|
|
|
|
|
const weekday = {dated: new Date()};
|
|
|
|
const days = [weekday];
|
|
|
|
const type = 'EventType';
|
|
|
|
const events = [];
|
|
|
|
const exclusions = [];
|
|
|
|
controller.editMode = 'include';
|
|
|
|
controller.onSelection(days, type, weekday, events, exclusions);
|
|
|
|
|
|
|
|
expect(controller.create).toHaveBeenCalledWith(type, days, weekday);
|
|
|
|
});
|
|
|
|
|
2022-05-27 11:54:35 +00:00
|
|
|
// it('should call the exclusionDelete() method', () => {
|
|
|
|
// jest.spyOn(controller, 'exclusionDelete').mockReturnThis();
|
2020-06-18 10:43:33 +00:00
|
|
|
|
2022-05-27 11:54:35 +00:00
|
|
|
// const weekday = {};
|
|
|
|
// const days = [];
|
|
|
|
// const type = 'EventType';
|
|
|
|
// const events = [];
|
|
|
|
// const exclusions = [{id: 1}];
|
|
|
|
// const geoExclusions = [];
|
|
|
|
// controller.editMode = 'delete';
|
|
|
|
// controller.onSelection(days, type, weekday, events, exclusions, geoExclusions);
|
2020-06-18 10:43:33 +00:00
|
|
|
|
2022-05-27 11:54:35 +00:00
|
|
|
// expect(controller.exclusionDelete).toHaveBeenCalledWith(exclusions);
|
|
|
|
// });
|
2020-06-18 10:43:33 +00:00
|
|
|
|
|
|
|
it('should call the exclusionCreate() method', () => {
|
|
|
|
jest.spyOn(controller, 'exclusionCreate').mockReturnThis();
|
|
|
|
|
|
|
|
const days = [{dated: new Date()}];
|
2022-05-27 11:54:35 +00:00
|
|
|
controller.days = days;
|
|
|
|
controller.excludeSelected = {type: 'all'};
|
|
|
|
controller.onExcludeResponse('accept');
|
2020-06-18 10:43:33 +00:00
|
|
|
|
|
|
|
expect(controller.exclusionCreate).toHaveBeenCalledWith(days);
|
|
|
|
});
|
2022-05-27 11:54:35 +00:00
|
|
|
|
|
|
|
// it('should call the exclusionCreate() method', () => {
|
|
|
|
// jest.spyOn(controller, 'exclusionCreate').mockReturnThis();
|
|
|
|
|
|
|
|
// const weekday = {};
|
|
|
|
// const days = [{dated: new Date()}];
|
|
|
|
// const type = 'EventType';
|
|
|
|
// const events = [];
|
|
|
|
// const exclusions = [];
|
|
|
|
// controller.editMode = 'delete';
|
|
|
|
// controller.onSelection(days, type, weekday, events, exclusions);
|
|
|
|
|
|
|
|
// expect(controller.exclusionCreate).toHaveBeenCalledWith(days);
|
|
|
|
// });
|
2020-06-18 10:43:33 +00:00
|
|
|
});
|
|
|
|
|
2020-06-22 08:01:55 +00:00
|
|
|
describe('create()', () => {
|
2022-05-27 11:54:35 +00:00
|
|
|
it('shoud set the selected property and then call the includeDialog show() method', () => {
|
|
|
|
controller.$.includeDialog = {show: jest.fn()};
|
2020-06-22 08:01:55 +00:00
|
|
|
|
|
|
|
const type = 'weekday';
|
|
|
|
const days = [new Date()];
|
|
|
|
const weekday = 1;
|
|
|
|
controller.create(type, days, weekday);
|
|
|
|
|
|
|
|
const selection = controller.selected;
|
|
|
|
const firstWeekday = selection.wdays[weekday];
|
|
|
|
|
|
|
|
expect(selection.type).toEqual('indefinitely');
|
|
|
|
expect(firstWeekday).toBeTruthy();
|
|
|
|
expect(controller.isNew).toBeTruthy();
|
2022-05-27 11:54:35 +00:00
|
|
|
expect(controller.$.includeDialog.show).toHaveBeenCalledWith();
|
2020-06-22 08:01:55 +00:00
|
|
|
});
|
|
|
|
|
2022-05-27 11:54:35 +00:00
|
|
|
it('shoud set the selected property with the first day and then call the includeDialog show() method', () => {
|
|
|
|
controller.$.includeDialog = {show: jest.fn()};
|
2020-06-22 08:01:55 +00:00
|
|
|
|
|
|
|
const type = 'nonListedType';
|
|
|
|
const days = [new Date()];
|
|
|
|
const weekday = 1;
|
|
|
|
controller.create(type, days, weekday);
|
|
|
|
|
|
|
|
const selection = controller.selected;
|
|
|
|
|
|
|
|
expect(selection.type).toEqual('day');
|
|
|
|
expect(selection.dated).toEqual(days[0]);
|
|
|
|
expect(controller.isNew).toBeTruthy();
|
2022-05-27 11:54:35 +00:00
|
|
|
expect(controller.$.includeDialog.show).toHaveBeenCalledWith();
|
2020-06-22 08:01:55 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onIncludeResponse()', () => {
|
|
|
|
it('shoud call the onDelete() method', () => {
|
|
|
|
jest.spyOn(controller, 'onDelete').mockReturnValue(
|
|
|
|
new Promise(accept => accept())
|
|
|
|
);
|
|
|
|
|
|
|
|
controller.selected = {id: 1};
|
|
|
|
controller.onIncludeResponse('delete');
|
|
|
|
|
|
|
|
expect(controller.onDelete).toHaveBeenCalledWith(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shoud make an HTTP POST query to create a new one and then call the refresh() method', () => {
|
|
|
|
jest.spyOn(controller, 'refresh').mockReturnThis();
|
|
|
|
|
|
|
|
controller.selected = {id: 1};
|
|
|
|
controller.isNew = true;
|
|
|
|
|
|
|
|
$httpBackend.when('POST', `Zones/1/events`).respond(200);
|
|
|
|
controller.onIncludeResponse('accept');
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shoud make an HTTP PUT query and then call the refresh() method', () => {
|
|
|
|
jest.spyOn(controller, 'refresh').mockReturnThis();
|
|
|
|
|
|
|
|
controller.selected = {id: 1};
|
|
|
|
controller.isNew = false;
|
|
|
|
|
|
|
|
const eventId = 1;
|
|
|
|
$httpBackend.when('PUT', `Zones/1/events/${eventId}`).respond(200);
|
|
|
|
controller.onIncludeResponse('accept');
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-27 11:54:35 +00:00
|
|
|
describe('onExcludeResponse()', () => {
|
|
|
|
it('should call the exclusionDelete() method', () => {
|
|
|
|
jest.spyOn(controller, 'exclusionDelete').mockReturnThis();
|
|
|
|
|
|
|
|
const exclusions = [{id: 1}];
|
|
|
|
controller.exclusions = exclusions;
|
|
|
|
controller.onExcludeResponse('delete');
|
|
|
|
|
|
|
|
expect(controller.exclusionDelete).toHaveBeenCalledWith(exclusions);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shoud make an HTTP POST query to create a new one and then call the refresh() method', () => {
|
|
|
|
jest.spyOn(controller, 'refresh').mockReturnThis();
|
|
|
|
|
|
|
|
controller.selected = {id: 1};
|
|
|
|
controller.isNew = true;
|
|
|
|
|
|
|
|
$httpBackend.when('POST', `Zones/1/events`).respond(200);
|
|
|
|
controller.onExcludeResponse('accept');
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shoud make an HTTP PUT query and then call the refresh() method', () => {
|
|
|
|
jest.spyOn(controller, 'refresh').mockReturnThis();
|
|
|
|
|
|
|
|
controller.selected = {id: 1};
|
|
|
|
controller.isNew = false;
|
|
|
|
|
|
|
|
const eventId = 1;
|
|
|
|
$httpBackend.when('PUT', `Zones/1/events/${eventId}`).respond(200);
|
|
|
|
controller.onExcludeResponse('accept');
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-18 10:43:33 +00:00
|
|
|
describe('onDeleteResponse()', () => {
|
2020-06-22 08:01:55 +00:00
|
|
|
it('shoud make an HTTP DELETE query and then call the refresh() method', () => {
|
|
|
|
jest.spyOn(controller, 'refresh').mockReturnThis();
|
|
|
|
|
|
|
|
const eventId = 1;
|
|
|
|
$httpBackend.expect('DELETE', `Zones/1/events/1`).respond({id: 1});
|
|
|
|
controller.onDeleteResponse('accept', eventId);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
2020-06-18 10:43:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('exclusionCreate()', () => {
|
2020-06-22 08:01:55 +00:00
|
|
|
it('shoud make an HTTP POST query and then call the refresh() method', () => {
|
|
|
|
jest.spyOn(controller, 'refresh').mockReturnThis();
|
|
|
|
|
|
|
|
const dates = [new Date()];
|
|
|
|
$httpBackend.expect('POST', `Zones/1/exclusions`).respond({id: 1});
|
|
|
|
controller.exclusionCreate(dates);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
2020-06-18 10:43:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('exclusionDelete()', () => {
|
2020-06-22 08:01:55 +00:00
|
|
|
it('shoud make an HTTP DELETE query once and then call the refresh() method', () => {
|
|
|
|
jest.spyOn(controller, 'refresh').mockReturnThis();
|
|
|
|
|
|
|
|
const exclusions = [{id: 1}];
|
|
|
|
const firstExclusionId = 1;
|
|
|
|
$httpBackend.when('DELETE', `Zones/1/exclusions/${firstExclusionId}`).respond(200);
|
|
|
|
controller.exclusionDelete(exclusions);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shoud make an HTTP DELETE query for every event and then call the refresh() method', () => {
|
|
|
|
jest.spyOn(controller, 'refresh').mockReturnThis();
|
|
|
|
jest.spyOn(controller.$http, 'delete').mockReturnValue(200);
|
|
|
|
|
|
|
|
const exclusions = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
|
|
|
|
controller.exclusionDelete(exclusions);
|
|
|
|
$scope.$apply();
|
|
|
|
|
|
|
|
expect(controller.$http.delete).toHaveBeenCalledTimes(4);
|
|
|
|
expect(controller.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
2020-06-18 10:43:33 +00:00
|
|
|
});
|
|
|
|
});
|