902 - Added unit tests
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
686203db18
commit
63ed592312
|
@ -33,6 +33,7 @@ class Controller extends Descriptor {
|
||||||
this.vnApp.showSuccess(this.$t('Zone deleted'));
|
this.vnApp.showSuccess(this.$t('Zone deleted'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onCloneAccept() {
|
onCloneAccept() {
|
||||||
return this.$http.post(`Zones/${this.id}/clone`).
|
return this.$http.post(`Zones/${this.id}/clone`).
|
||||||
then(res => this.$state.go('zone.card.basicData', {id: res.data.id}));
|
then(res => this.$state.go('zone.card.basicData', {id: res.data.id}));
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
import './index.js';
|
||||||
|
|
||||||
|
describe('Zone descriptor', () => {
|
||||||
|
let $httpBackend;
|
||||||
|
let controller;
|
||||||
|
let $element;
|
||||||
|
|
||||||
|
beforeEach(ngModule('zone'));
|
||||||
|
|
||||||
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
|
$element = angular.element('<vn-zone-descriptor></vn-zone-descriptor');
|
||||||
|
controller = $componentController('vnZoneDescriptor', {$element});
|
||||||
|
controller.zone = {id: 1};
|
||||||
|
controller.id = 1;
|
||||||
|
controller.$.deleteZone = {
|
||||||
|
hide: () => {},
|
||||||
|
show: () => {}
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('onDelete()', () => {
|
||||||
|
it('should make an HTTP POST query and then call the deleteZone show() method', () => {
|
||||||
|
jest.spyOn(controller.$.deleteZone, 'show');
|
||||||
|
|
||||||
|
const expectedData = [{id: 16}];
|
||||||
|
$httpBackend.when('GET', 'Tickets').respond(expectedData);
|
||||||
|
controller.onDelete();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.$.deleteZone.show).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should make an HTTP POST query and then call the deleteZone() method', () => {
|
||||||
|
jest.spyOn(controller, 'deleteZone').mockReturnThis();
|
||||||
|
|
||||||
|
const expectedData = [];
|
||||||
|
$httpBackend.when('GET', 'Tickets').respond(expectedData);
|
||||||
|
controller.onDelete();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.deleteZone).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('deleteZone()', () => {
|
||||||
|
it('should make an HTTP POST query and then call the showMessage() method', () => {
|
||||||
|
jest.spyOn(controller.$state, 'go').mockReturnThis();
|
||||||
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
|
|
||||||
|
const stateName = 'zone.index';
|
||||||
|
$httpBackend.when('POST', 'Zones/1/deleteZone').respond(200);
|
||||||
|
controller.deleteZone();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.$state.go).toHaveBeenCalledWith(stateName);
|
||||||
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Zone deleted');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onCloneAccept()', () => {
|
||||||
|
it('should make an HTTP POST query and then call the state go() method', () => {
|
||||||
|
jest.spyOn(controller.$state, 'go').mockReturnThis();
|
||||||
|
|
||||||
|
const stateName = 'zone.card.basicData';
|
||||||
|
const expectedData = {id: 1};
|
||||||
|
$httpBackend.when('POST', 'Zones/1/clone').respond(expectedData);
|
||||||
|
controller.onCloneAccept();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.$state.go).toHaveBeenCalledWith(stateName, expectedData);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -51,4 +51,26 @@ describe('component vnZoneSummary', () => {
|
||||||
expect(controller.summary).toBeDefined();
|
expect(controller.summary).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getWarehouses()', () => {
|
||||||
|
it('should make an HTTP get query and then store data on the controller', () => {
|
||||||
|
controller._zone = {id: 1};
|
||||||
|
const params = {
|
||||||
|
filter: {
|
||||||
|
include: {
|
||||||
|
relation: 'warehouse',
|
||||||
|
fields: ['name']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const serializedParams = $httpParamSerializer(params);
|
||||||
|
const query = `Zones/1/warehouses?${serializedParams}`;
|
||||||
|
$httpBackend.expect('GET', query).respond([{id: 1}]);
|
||||||
|
controller.getWarehouses();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.zoneWarehouses.length).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,13 +2,14 @@ import ngModule from '../module';
|
||||||
import Section from 'salix/components/section';
|
import Section from 'salix/components/section';
|
||||||
|
|
||||||
class Controller extends Section {
|
class Controller extends Section {
|
||||||
constructor($element, $) {
|
$onInit() {
|
||||||
super($element, $);
|
|
||||||
|
|
||||||
this.path = `Zones/${this.$params.id}/warehouses`;
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get path() {
|
||||||
|
return `Zones/${this.$params.id}/warehouses`;
|
||||||
|
}
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
let filter = {include: 'warehouse'};
|
let filter = {include: 'warehouse'};
|
||||||
this.$http.get(this.path, {params: {filter}})
|
this.$http.get(this.path, {params: {filter}})
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
import './index.js';
|
||||||
|
|
||||||
|
describe('Zone warehouses', () => {
|
||||||
|
let $httpBackend;
|
||||||
|
let $httpParamSerializer;
|
||||||
|
let controller;
|
||||||
|
let $element;
|
||||||
|
|
||||||
|
beforeEach(ngModule('zone'));
|
||||||
|
|
||||||
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
|
||||||
|
$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);
|
||||||
|
controller.onSave('accept');
|
||||||
|
$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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue