unit tests
gitea/salix/2138-zone_event_m3 This commit looks good
Details
gitea/salix/2138-zone_event_m3 This commit looks good
Details
This commit is contained in:
parent
4add07898f
commit
442c3ba87c
|
@ -50,9 +50,15 @@ describe('Component vnCalendar', () => {
|
|||
|
||||
const day = new Date();
|
||||
day.setHours(0, 0, 0, 0);
|
||||
controller.select(day);
|
||||
|
||||
const clickEvent = new Event('click');
|
||||
const target = document.createElement('div');
|
||||
target.dispatchEvent(clickEvent);
|
||||
|
||||
controller.select(clickEvent, day);
|
||||
|
||||
let res = {
|
||||
$event: clickEvent,
|
||||
$days: [day],
|
||||
$type: 'day'
|
||||
};
|
||||
|
|
|
@ -2,15 +2,17 @@ import './index.js';
|
|||
import popover from 'core/mocks/popover';
|
||||
import crudModel from 'core/mocks/crud-model';
|
||||
|
||||
fdescribe('Zone Component vnZoneDeliveryDays', () => {
|
||||
describe('Zone Component vnZoneDeliveryDays', () => {
|
||||
let $componentController;
|
||||
let $httpBackend;
|
||||
let controller;
|
||||
let $element;
|
||||
|
||||
beforeEach(ngModule('zone'));
|
||||
|
||||
beforeEach(angular.mock.inject(_$componentController_ => {
|
||||
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
|
||||
$componentController = _$componentController_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$element = angular.element('<vn-zone-delivery-days></vn-zone-delivery-days');
|
||||
controller = $componentController('vnZoneDeliveryDays', {$element});
|
||||
controller.$.zoneEvents = popover;
|
||||
|
@ -21,12 +23,51 @@ fdescribe('Zone Component vnZoneDeliveryDays', () => {
|
|||
};
|
||||
}));
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
describe('onSelection()', () => {
|
||||
it('should return', () => {
|
||||
it('should not call the show popover method', () => {
|
||||
jest.spyOn(controller.$.zoneEvents, 'show');
|
||||
|
||||
const $event = new Event('click');
|
||||
const target = angular.element('<div>My target</div>'); // crear con DOM?
|
||||
const target = document.createElement('div');
|
||||
target.dispatchEvent($event);
|
||||
const $events = [];
|
||||
controller.onSelection($event, $events);
|
||||
|
||||
expect(controller.$.zoneEvents.show).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return', () => {
|
||||
const zoneModel = controller.$.zoneIndex.$scope.model;
|
||||
jest.spyOn(controller.$.zoneEvents, 'show');
|
||||
jest.spyOn(zoneModel, 'applyFilter');
|
||||
|
||||
const $event = new Event('click');
|
||||
const target = document.createElement('div');
|
||||
target.dispatchEvent($event);
|
||||
const $events = [
|
||||
{zoneFk: 1},
|
||||
|
@ -34,8 +75,18 @@ fdescribe('Zone Component vnZoneDeliveryDays', () => {
|
|||
{zoneFk: 8}
|
||||
];
|
||||
controller.onSelection($event, $events);
|
||||
const expectedFilter = {
|
||||
include: {
|
||||
relation: 'agencyMode',
|
||||
scope: {fields: ['name']}
|
||||
},
|
||||
where: {
|
||||
id: {inq: [1, 2, 8]}
|
||||
}
|
||||
};
|
||||
|
||||
expect(controller.$.zoneEvents.show).toHaveBeenCalledWith();
|
||||
expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(target);
|
||||
expect(zoneModel.applyFilter).toHaveBeenCalledWith(expectedFilter);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue