2020-02-26 06:02:03 +00:00
|
|
|
import './index.js';
|
|
|
|
import popover from 'core/mocks/popover';
|
|
|
|
import crudModel from 'core/mocks/crud-model';
|
|
|
|
|
2020-02-26 10:05:29 +00:00
|
|
|
describe('Zone Component vnZoneDeliveryDays', () => {
|
2020-02-26 06:02:03 +00:00
|
|
|
let $componentController;
|
2020-02-26 10:05:29 +00:00
|
|
|
let $httpBackend;
|
2020-02-26 06:02:03 +00:00
|
|
|
let controller;
|
|
|
|
let $element;
|
|
|
|
|
|
|
|
beforeEach(ngModule('zone'));
|
|
|
|
|
2020-02-26 10:05:29 +00:00
|
|
|
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
|
2020-02-26 06:02:03 +00:00
|
|
|
$componentController = _$componentController_;
|
2020-02-26 10:05:29 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2020-02-26 06:02:03 +00:00
|
|
|
$element = angular.element('<vn-zone-delivery-days></vn-zone-delivery-days');
|
|
|
|
controller = $componentController('vnZoneDeliveryDays', {$element});
|
|
|
|
controller.$.zoneEvents = popover;
|
|
|
|
controller.$.zoneIndex = {
|
|
|
|
$scope: {
|
|
|
|
model: crudModel
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
|
2020-02-26 10:05:29 +00:00
|
|
|
describe('onSubmit()', () => {
|
|
|
|
it('should make an HTTP GET query and then call the showMessage() method', () => {
|
|
|
|
jest.spyOn(controller.vnApp, 'showMessage');
|
|
|
|
|
|
|
|
const expectedData = {events: []};
|
|
|
|
$httpBackend.when('GET', 'Zones/getEvents').respond({events: []});
|
|
|
|
controller.onSubmit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$.data).toBeDefined();
|
|
|
|
expect(controller.$.data).toEqual(expectedData);
|
|
|
|
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No service for the specified zone');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should make an HTTP GET query and then set the data property', () => {
|
|
|
|
const expectedData = {events: [{zoneFk: 1}]};
|
|
|
|
$httpBackend.when('GET', 'Zones/getEvents').respond({events: [{zoneFk: 1}]});
|
|
|
|
controller.onSubmit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$.data).toBeDefined();
|
|
|
|
expect(controller.$.data).toEqual(expectedData);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-26 06:02:03 +00:00
|
|
|
describe('onSelection()', () => {
|
2020-02-26 11:24:48 +00:00
|
|
|
it('should not call the show popover method if events array is empty', () => {
|
2020-02-26 10:05:29 +00:00
|
|
|
jest.spyOn(controller.$.zoneEvents, 'show');
|
|
|
|
|
2020-02-26 11:24:48 +00:00
|
|
|
const event = new Event('click');
|
2020-02-26 10:05:29 +00:00
|
|
|
const target = document.createElement('div');
|
2020-02-26 11:24:48 +00:00
|
|
|
target.dispatchEvent(event);
|
|
|
|
const events = [];
|
|
|
|
controller.onSelection(event, events);
|
2020-02-26 10:05:29 +00:00
|
|
|
|
|
|
|
expect(controller.$.zoneEvents.show).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2020-02-26 11:24:48 +00:00
|
|
|
it('should call the show() method and then call the applyFilter() method with the expected ids', () => {
|
2020-02-26 10:05:29 +00:00
|
|
|
const zoneModel = controller.$.zoneIndex.$scope.model;
|
2020-02-26 06:02:03 +00:00
|
|
|
jest.spyOn(controller.$.zoneEvents, 'show');
|
2020-02-26 10:05:29 +00:00
|
|
|
jest.spyOn(zoneModel, 'applyFilter');
|
2020-02-26 06:02:03 +00:00
|
|
|
|
2020-02-26 11:24:48 +00:00
|
|
|
const event = new Event('click');
|
2020-02-26 10:05:29 +00:00
|
|
|
const target = document.createElement('div');
|
2020-02-26 06:02:03 +00:00
|
|
|
target.dispatchEvent($event);
|
2020-02-26 11:24:48 +00:00
|
|
|
const events = [
|
2020-02-26 06:02:03 +00:00
|
|
|
{zoneFk: 1},
|
|
|
|
{zoneFk: 2},
|
|
|
|
{zoneFk: 8}
|
|
|
|
];
|
2020-02-26 11:24:48 +00:00
|
|
|
controller.onSelection(event, events);
|
2020-02-26 10:05:29 +00:00
|
|
|
const expectedFilter = {
|
|
|
|
include: {
|
|
|
|
relation: 'agencyMode',
|
|
|
|
scope: {fields: ['name']}
|
|
|
|
},
|
|
|
|
where: {
|
|
|
|
id: {inq: [1, 2, 8]}
|
|
|
|
}
|
|
|
|
};
|
2020-02-26 06:02:03 +00:00
|
|
|
|
2020-02-26 10:05:29 +00:00
|
|
|
expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(target);
|
|
|
|
expect(zoneModel.applyFilter).toHaveBeenCalledWith(expectedFilter);
|
2020-02-26 06:02:03 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|