salix/modules/zone/front/warehouses/index.spec.js

61 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

2020-06-17 09:51:57 +00:00
import './index.js';
describe('Zone warehouses', () => {
let $httpBackend;
let $httpParamSerializer;
let controller;
let $element;
beforeEach(ngModule('zone'));
2020-07-23 14:46:16 +00:00
beforeEach(inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
2020-06-17 09:51:57 +00:00
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
$element = angular.element('<vn-zone-warehouses></vn-zone-warehouses');
controller = $componentController('vnZoneWarehouses', {$element});
controller.zone = {id: 1};
controller.$params = {id: 1};
controller.$.dialog = {hide: jest.fn()};
}));
describe('refresh()', () => {
it('should make an HTTP GET query and then set the data', () => {
const params = {filter: {include: 'warehouse'}};
const serializedParams = $httpParamSerializer(params);
const path = `Zones/1/warehouses?${serializedParams}`;
$httpBackend.expect('GET', path).respond([{id: 1, name: 'Warehouse one'}]);
controller.refresh();
$httpBackend.flush();
expect(controller.$.data).toBeDefined();
});
});
describe('onSave()', () => {
it('should make an HTTP POST query and then call the refresh() method', () => {
jest.spyOn(controller, 'refresh').mockReturnThis();
$httpBackend.expect('POST', `Zones/1/warehouses`).respond(200);
2020-07-29 08:47:48 +00:00
controller.onSave();
2020-06-17 09:51:57 +00:00
$httpBackend.flush();
expect(controller.selected).toBeNull();
expect(controller.isNew).toBeNull();
expect(controller.$.dialog.hide).toHaveBeenCalledWith();
expect(controller.refresh).toHaveBeenCalledWith();
});
});
describe('delete()', () => {
it('should make an HTTP DELETE query and then set deleteRow property to null value', () => {
controller.deleteRow = {id: 1};
controller.$.data = [{id: 1}];
$httpBackend.expect('DELETE', `Zones/1/warehouses/1`).respond(200);
controller.delete();
$httpBackend.flush();
expect(controller.deleteRow).toBeNull();
});
});
});