ticket notes logic refactor plus unit tests
This commit is contained in:
parent
f7cac19be4
commit
8c631012b1
|
@ -48,8 +48,8 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "/observation",
|
"url": "/observation",
|
||||||
"state": "ticket.card.observations",
|
"state": "ticket.card.observation",
|
||||||
"component": "vn-ticket-observations",
|
"component": "vn-ticket-observation",
|
||||||
"params": {
|
"params": {
|
||||||
"ticket": "$ctrl.ticket"
|
"ticket": "$ctrl.ticket"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<vn-watcher
|
<vn-watcher
|
||||||
vn-id="watcher"
|
vn-id="watcher"
|
||||||
url="/client/api/Addresses"
|
url="/ticket/api/Observation"
|
||||||
id-field="id"
|
id-field="id"
|
||||||
data="$ctrl.address"
|
data="$ctrl.address"
|
||||||
form="form">
|
form="form">
|
||||||
|
@ -31,7 +31,8 @@
|
||||||
vn-two
|
vn-two
|
||||||
margin-large-right
|
margin-large-right
|
||||||
label="Description"
|
label="Description"
|
||||||
model="ticketObservation.description">
|
model="ticketObservation.description"
|
||||||
|
rule="ticketObservation.description">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-auto pad-medium-top>
|
<vn-auto pad-medium-top>
|
||||||
<vn-icon
|
<vn-icon
|
|
@ -1,6 +1,6 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
|
|
||||||
class TicketObservations {
|
class Controller {
|
||||||
constructor($stateParams, $scope, $http, $translate, vnApp) {
|
constructor($stateParams, $scope, $http, $translate, vnApp) {
|
||||||
this.params = $stateParams;
|
this.params = $stateParams;
|
||||||
this.$scope = $scope;
|
this.$scope = $scope;
|
||||||
|
@ -116,7 +116,7 @@ class TicketObservations {
|
||||||
canSubmit = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
|
canSubmit = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
|
||||||
|
|
||||||
if (canSubmit) {
|
if (canSubmit) {
|
||||||
return this.$http.post(`/ticket/api/TicketObservations/crudTicketObservations`, observationsObj).then(() => {
|
return this.$http.post(`/ticket/api/TicketObservations/crudTicketObservation`, observationsObj).then(() => {
|
||||||
this.getObservations();
|
this.getObservations();
|
||||||
this._unsetDirtyForm();
|
this._unsetDirtyForm();
|
||||||
});
|
});
|
||||||
|
@ -129,11 +129,11 @@ class TicketObservations {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TicketObservations.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp'];
|
Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp'];
|
||||||
|
|
||||||
ngModule.component('vnTicketObservations', {
|
ngModule.component('vnTicketObservation', {
|
||||||
template: require('./ticket-observations.html'),
|
template: require('./ticket-observation.html'),
|
||||||
controller: TicketObservations,
|
controller: Controller,
|
||||||
bindings: {
|
bindings: {
|
||||||
ticket: '<'
|
ticket: '<'
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
import './ticket-observations.js';
|
import './ticket-observation.js';
|
||||||
|
|
||||||
describe('ticket', () => {
|
describe('ticket', () => {
|
||||||
describe('Component vnTicketObservations', () => {
|
describe('Component vnTicketObservation', () => {
|
||||||
let $componentController;
|
let $componentController;
|
||||||
let $state;
|
let $state;
|
||||||
let controller;
|
let controller;
|
||||||
|
@ -15,7 +15,7 @@ describe('ticket', () => {
|
||||||
$componentController = _$componentController_;
|
$componentController = _$componentController_;
|
||||||
$state = _$state_;
|
$state = _$state_;
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
controller = $componentController('vnTicketObservations', {$state: $state});
|
controller = $componentController('vnTicketObservation', {$state: $state});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('add / remove observation', () => {
|
describe('add / remove observation', () => {
|
||||||
|
@ -24,10 +24,10 @@ describe('ticket', () => {
|
||||||
spyOn(controller, '_setIconAdd').and.callThrough();
|
spyOn(controller, '_setIconAdd').and.callThrough();
|
||||||
controller.addObservation();
|
controller.addObservation();
|
||||||
|
|
||||||
expect(controller._setIconAdd).toHaveBeenCalledWith();
|
|
||||||
expect(controller.ticketObservations.length).toEqual(1);
|
expect(controller.ticketObservations.length).toEqual(1);
|
||||||
expect(controller.ticketObservations[0].id).toBe(undefined);
|
expect(controller.ticketObservations[0].id).toBe(undefined);
|
||||||
expect(controller.ticketObservations[0].showAddIcon).toBeTruthy();
|
expect(controller.ticketObservations[0].showAddIcon).toBeTruthy();
|
||||||
|
expect(controller._setIconAdd).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove an observation that occupies the position in the index given and call _setIconAdd()', () => {
|
it('should remove an observation that occupies the position in the index given and call _setIconAdd()', () => {
|
||||||
|
@ -42,11 +42,11 @@ describe('ticket', () => {
|
||||||
|
|
||||||
controller.removeObservation(index);
|
controller.removeObservation(index);
|
||||||
|
|
||||||
expect(controller._setIconAdd).toHaveBeenCalledWith();
|
|
||||||
expect(controller.ticketObservations.length).toEqual(2);
|
expect(controller.ticketObservations.length).toEqual(2);
|
||||||
expect(controller.ticketObservations[0].showAddIcon).toBeFalsy();
|
expect(controller.ticketObservations[0].showAddIcon).toBeFalsy();
|
||||||
expect(controller.ticketObservations[1].showAddIcon).toBeTruthy();
|
expect(controller.ticketObservations[1].showAddIcon).toBeTruthy();
|
||||||
expect(controller.ticketObservations[index]).toBe(undefined);
|
expect(controller.ticketObservations[index]).toBe(undefined);
|
||||||
|
expect(controller._setIconAdd).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -70,16 +70,33 @@ describe('ticket', () => {
|
||||||
|
|
||||||
describe('get Observations()', () => {
|
describe('get Observations()', () => {
|
||||||
it('should perform a GET query to receive the ticket observations', () => {
|
it('should perform a GET query to receive the ticket observations', () => {
|
||||||
let res = [{id: 1, observationTypeFk: 1, description: 'one'}];
|
let response = [{id: 1, observationTypeFk: 1, description: 'one'}];
|
||||||
|
spyOn(controller, 'setOldObservations');
|
||||||
|
|
||||||
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond(res);
|
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond(response);
|
||||||
$httpBackend.expectGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`);
|
$httpBackend.expectGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`);
|
||||||
controller.getObservations();
|
controller.getObservations();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.setOldObservations).toHaveBeenCalledWith(jasmine.any(Object));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('submit()', () => {
|
describe('submit()', () => {
|
||||||
|
it("should return an error message 'Some fields are invalid'", () => {
|
||||||
|
controller.$scope.form = {};
|
||||||
|
controller.$scope.form.$invalid = true;
|
||||||
|
spyOn(controller.vnApp, 'showMessage').and.callThrough();
|
||||||
|
controller.ticketObservations = [
|
||||||
|
{id: 1, observationTypeFk: 1, description: 'one', itemFk: 1},
|
||||||
|
{observationTypeFk: 1, description: 'one', itemFk: 1}
|
||||||
|
];
|
||||||
|
controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}};
|
||||||
|
controller.submit();
|
||||||
|
|
||||||
|
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Some fields are invalid');
|
||||||
|
});
|
||||||
|
|
||||||
it("should return an error message 'The observation type must be unique'", () => {
|
it("should return an error message 'The observation type must be unique'", () => {
|
||||||
controller.$scope.form = {};
|
controller.$scope.form = {};
|
||||||
spyOn(controller.vnApp, 'showMessage').and.callThrough();
|
spyOn(controller.vnApp, 'showMessage').and.callThrough();
|
||||||
|
@ -100,7 +117,7 @@ describe('ticket', () => {
|
||||||
controller.removedObservations = [1];
|
controller.removedObservations = [1];
|
||||||
|
|
||||||
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
|
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
|
||||||
$httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!');
|
$httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservation`).respond('ok!');
|
||||||
controller.submit();
|
controller.submit();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
|
@ -111,7 +128,7 @@ describe('ticket', () => {
|
||||||
controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one'}};
|
controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one'}};
|
||||||
|
|
||||||
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
|
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
|
||||||
$httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!');
|
$httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservation`).respond('ok!');
|
||||||
controller.submit();
|
controller.submit();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
|
@ -121,7 +138,7 @@ describe('ticket', () => {
|
||||||
controller.ticketObservations = [{observationTypeFk: 2, description: 'two'}];
|
controller.ticketObservations = [{observationTypeFk: 2, description: 'two'}];
|
||||||
|
|
||||||
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
|
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
|
||||||
$httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!');
|
$httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservation`).respond('ok!');
|
||||||
controller.submit();
|
controller.submit();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
|
@ -3,4 +3,5 @@ module.exports = function(Self) {
|
||||||
require('../methods/ticket/change-time.js')(Self);
|
require('../methods/ticket/change-time.js')(Self);
|
||||||
require('../methods/ticket/change-worker.js')(Self);
|
require('../methods/ticket/change-worker.js')(Self);
|
||||||
require('../methods/ticket/filter.js')(Self);
|
require('../methods/ticket/filter.js')(Self);
|
||||||
|
require('../methods/ticket/get-volume.js')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.installCrudModel('crudTicketObservation');
|
||||||
|
};
|
|
@ -1,3 +0,0 @@
|
||||||
module.exports = Self => {
|
|
||||||
Self.installCrudModel('crudTicketObservations');
|
|
||||||
};
|
|
|
@ -1,3 +1,3 @@
|
||||||
module.exports = function(Self) {
|
module.exports = function(Self) {
|
||||||
require('../methods/ticket/crudTicketObservations.js')(Self);
|
require('../methods/notes/crudTicketObservation.js')(Self);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue