ticket notes logic refactor plus unit tests
This commit is contained in:
parent
f7cac19be4
commit
8c631012b1
|
@ -48,8 +48,8 @@
|
|||
},
|
||||
{
|
||||
"url": "/observation",
|
||||
"state": "ticket.card.observations",
|
||||
"component": "vn-ticket-observations",
|
||||
"state": "ticket.card.observation",
|
||||
"component": "vn-ticket-observation",
|
||||
"params": {
|
||||
"ticket": "$ctrl.ticket"
|
||||
},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
url="/client/api/Addresses"
|
||||
url="/ticket/api/Observation"
|
||||
id-field="id"
|
||||
data="$ctrl.address"
|
||||
form="form">
|
||||
|
@ -31,7 +31,8 @@
|
|||
vn-two
|
||||
margin-large-right
|
||||
label="Description"
|
||||
model="ticketObservation.description">
|
||||
model="ticketObservation.description"
|
||||
rule="ticketObservation.description">
|
||||
</vn-textfield>
|
||||
<vn-auto pad-medium-top>
|
||||
<vn-icon
|
|
@ -1,6 +1,6 @@
|
|||
import ngModule from '../module';
|
||||
|
||||
class TicketObservations {
|
||||
class Controller {
|
||||
constructor($stateParams, $scope, $http, $translate, vnApp) {
|
||||
this.params = $stateParams;
|
||||
this.$scope = $scope;
|
||||
|
@ -116,7 +116,7 @@ class TicketObservations {
|
|||
canSubmit = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
|
||||
|
||||
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._unsetDirtyForm();
|
||||
});
|
||||
|
@ -129,11 +129,11 @@ class TicketObservations {
|
|||
}
|
||||
}
|
||||
|
||||
TicketObservations.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp'];
|
||||
Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp'];
|
||||
|
||||
ngModule.component('vnTicketObservations', {
|
||||
template: require('./ticket-observations.html'),
|
||||
controller: TicketObservations,
|
||||
ngModule.component('vnTicketObservation', {
|
||||
template: require('./ticket-observation.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
ticket: '<'
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import './ticket-observations.js';
|
||||
import './ticket-observation.js';
|
||||
|
||||
describe('ticket', () => {
|
||||
describe('Component vnTicketObservations', () => {
|
||||
describe('Component vnTicketObservation', () => {
|
||||
let $componentController;
|
||||
let $state;
|
||||
let controller;
|
||||
|
@ -15,7 +15,7 @@ describe('ticket', () => {
|
|||
$componentController = _$componentController_;
|
||||
$state = _$state_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
controller = $componentController('vnTicketObservations', {$state: $state});
|
||||
controller = $componentController('vnTicketObservation', {$state: $state});
|
||||
}));
|
||||
|
||||
describe('add / remove observation', () => {
|
||||
|
@ -24,10 +24,10 @@ describe('ticket', () => {
|
|||
spyOn(controller, '_setIconAdd').and.callThrough();
|
||||
controller.addObservation();
|
||||
|
||||
expect(controller._setIconAdd).toHaveBeenCalledWith();
|
||||
expect(controller.ticketObservations.length).toEqual(1);
|
||||
expect(controller.ticketObservations[0].id).toBe(undefined);
|
||||
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()', () => {
|
||||
|
@ -42,11 +42,11 @@ describe('ticket', () => {
|
|||
|
||||
controller.removeObservation(index);
|
||||
|
||||
expect(controller._setIconAdd).toHaveBeenCalledWith();
|
||||
expect(controller.ticketObservations.length).toEqual(2);
|
||||
expect(controller.ticketObservations[0].showAddIcon).toBeFalsy();
|
||||
expect(controller.ticketObservations[1].showAddIcon).toBeTruthy();
|
||||
expect(controller.ticketObservations[index]).toBe(undefined);
|
||||
expect(controller._setIconAdd).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -70,16 +70,33 @@ describe('ticket', () => {
|
|||
|
||||
describe('get 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"]}`);
|
||||
controller.getObservations();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.setOldObservations).toHaveBeenCalledWith(jasmine.any(Object));
|
||||
});
|
||||
});
|
||||
|
||||
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'", () => {
|
||||
controller.$scope.form = {};
|
||||
spyOn(controller.vnApp, 'showMessage').and.callThrough();
|
||||
|
@ -100,7 +117,7 @@ describe('ticket', () => {
|
|||
controller.removedObservations = [1];
|
||||
|
||||
$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();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
@ -111,7 +128,7 @@ describe('ticket', () => {
|
|||
controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one'}};
|
||||
|
||||
$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();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
@ -121,7 +138,7 @@ describe('ticket', () => {
|
|||
controller.ticketObservations = [{observationTypeFk: 2, description: 'two'}];
|
||||
|
||||
$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();
|
||||
$httpBackend.flush();
|
||||
});
|
|
@ -3,4 +3,5 @@ module.exports = function(Self) {
|
|||
require('../methods/ticket/change-time.js')(Self);
|
||||
require('../methods/ticket/change-worker.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) {
|
||||
require('../methods/ticket/crudTicketObservations.js')(Self);
|
||||
require('../methods/notes/crudTicketObservation.js')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue