#124 address edit and address observations bugs plus unit tests and e2e path
This commit is contained in:
parent
5fc446c05f
commit
2249f0a9be
|
@ -8,9 +8,9 @@
|
||||||
url="/client/api/Addresses"
|
url="/client/api/Addresses"
|
||||||
id-field="id"
|
id-field="id"
|
||||||
data="$ctrl.address"
|
data="$ctrl.address"
|
||||||
form="form">
|
form="addressForm">
|
||||||
</vn-watcher>
|
</vn-watcher>
|
||||||
<form name="form" ng-submit="$ctrl.submit()">
|
<form name="addressForm" ng-submit="$ctrl.submit()">
|
||||||
<vn-card pad-large>
|
<vn-card pad-large>
|
||||||
<vn-title>Address</vn-title>
|
<vn-title>Address</vn-title>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
|
@ -50,6 +50,11 @@
|
||||||
<vn-textfield vn-one label="Mobile" field="$ctrl.address.mobile"></vn-textfield>
|
<vn-textfield vn-one label="Mobile" field="$ctrl.address.mobile"></vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-one margin-medium-top>
|
<vn-one margin-medium-top>
|
||||||
|
</vn-card>
|
||||||
|
</form>
|
||||||
|
<vn-watcher form="notesForm"></vn-watcher>
|
||||||
|
<form name="notesForm" ng-submit="$ctrl.submit()">
|
||||||
|
<vn-card pad-large>
|
||||||
<vn-title>Notes</vn-title>
|
<vn-title>Notes</vn-title>
|
||||||
<mg-ajax path="/client/api/ObservationTypes" options="mgIndex as observationsTypes"></mg-ajax>
|
<mg-ajax path="/client/api/ObservationTypes" options="mgIndex as observationsTypes"></mg-ajax>
|
||||||
<vn-horizontal ng-repeat="observation in $ctrl.observations track by $index">
|
<vn-horizontal ng-repeat="observation in $ctrl.observations track by $index">
|
||||||
|
|
|
@ -51,18 +51,22 @@ export default class Controller {
|
||||||
return this.$http.post(`/client/api/AddressObservations/crudAddressObservations`, observationsObject);
|
return this.$http.post(`/client/api/AddressObservations/crudAddressObservations`, observationsObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
_observationsEquals(ob1, ob2) {
|
equalObservations(oldObj, newObj) {
|
||||||
return ob1.id === ob2.id && ob1.observationTypeFk === ob2.observationTypeFk && ob1.description === ob2.description;
|
return oldObj.id === newObj.id && oldObj.observationTypeFk === newObj.observationTypeFk && oldObj.description === newObj.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
if (this.$scope.form.$invalid) {
|
if (this.$scope.addressForm.$invalid || this.$scope.notesForm.$invalid) {
|
||||||
|
this.vnApp.showMessage(
|
||||||
|
this.$translate.instant('Some fields are invalid')
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let canSubmitWatcher = this.$scope.watcher.dataChanged();
|
let canSubmitWatcher = this.$scope.watcher.dataChanged();
|
||||||
let canSubmitObservations;
|
let canSubmitObservations;
|
||||||
let repeatedTypes = false;
|
let repeatedTypes = false;
|
||||||
|
let emptyFields = false;
|
||||||
let types = [];
|
let types = [];
|
||||||
let observationsObj = {
|
let observationsObj = {
|
||||||
delete: this.removedObservations,
|
delete: this.removedObservations,
|
||||||
|
@ -70,13 +74,17 @@ export default class Controller {
|
||||||
update: []
|
update: []
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let i = 0; i < this.observations.length; i++) {
|
this.observations.forEach(observation => {
|
||||||
let observation = this.observations[i];
|
|
||||||
let isNewObservation = observation.id === undefined;
|
let isNewObservation = observation.id === undefined;
|
||||||
|
|
||||||
if (observation.observationTypeFk && types.indexOf(observation.observationTypeFk) !== -1) {
|
if (observation.observationTypeFk && types.indexOf(observation.observationTypeFk) !== -1) {
|
||||||
repeatedTypes = true;
|
repeatedTypes = true;
|
||||||
break;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (observation.observationTypeFk === null || observation.description === null) {
|
||||||
|
emptyFields = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (observation.observationTypeFk)
|
if (observation.observationTypeFk)
|
||||||
|
@ -84,10 +92,10 @@ export default class Controller {
|
||||||
|
|
||||||
if (isNewObservation && observation.observationTypeFk && observation.description) {
|
if (isNewObservation && observation.observationTypeFk && observation.description) {
|
||||||
observationsObj.create.push(observation);
|
observationsObj.create.push(observation);
|
||||||
} else if (!isNewObservation && !this._observationsEquals(this.oldObservations[observation.id], observation)) {
|
} else if (!isNewObservation && !this.equalObservations(this.oldObservations[observation.id], observation)) {
|
||||||
observationsObj.update.push(observation);
|
observationsObj.update.push(observation);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
canSubmitObservations = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
|
canSubmitObservations = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
|
||||||
|
|
||||||
|
@ -95,15 +103,21 @@ export default class Controller {
|
||||||
this.vnApp.showMessage(
|
this.vnApp.showMessage(
|
||||||
this.$translate.instant('The observation type must be unique')
|
this.$translate.instant('The observation type must be unique')
|
||||||
);
|
);
|
||||||
|
} else if (emptyFields) {
|
||||||
|
this.vnApp.showMessage(
|
||||||
|
this.$translate.instant('No field can be blank')
|
||||||
|
);
|
||||||
} else if (canSubmitWatcher && !canSubmitObservations) {
|
} else if (canSubmitWatcher && !canSubmitObservations) {
|
||||||
this.$scope.watcher.submit().then(() => {
|
this.$scope.watcher.submit().then(() => {
|
||||||
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
|
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
|
||||||
});
|
});
|
||||||
} else if (!canSubmitWatcher && canSubmitObservations) {
|
} else if (!canSubmitWatcher && canSubmitObservations) {
|
||||||
|
console.log('noWatcher canNotes');
|
||||||
this._submitObservations(observationsObj).then(() => {
|
this._submitObservations(observationsObj).then(() => {
|
||||||
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
|
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
|
||||||
});
|
});
|
||||||
} else if (canSubmitWatcher && canSubmitObservations) {
|
} else if (canSubmitWatcher && canSubmitObservations) {
|
||||||
|
console.log('canWatcher canNotes');
|
||||||
this.$q.all([this.$scope.watcher.submit(), this._submitObservations(observationsObj)]).then(() => {
|
this.$q.all([this.$scope.watcher.submit(), this._submitObservations(observationsObj)]).then(() => {
|
||||||
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
|
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,7 @@ describe('Client', () => {
|
||||||
it('should return true if two observations are equals independent of control attributes', () => {
|
it('should return true if two observations are equals independent of control attributes', () => {
|
||||||
let ob1 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: true};
|
let ob1 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: true};
|
||||||
let ob2 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: false};
|
let ob2 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: false};
|
||||||
let equals = controller._observationsEquals(ob2, ob1);
|
let equals = controller.equalObservations(ob2, ob1);
|
||||||
|
|
||||||
expect(equals).toBeTruthy();
|
expect(equals).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
@ -35,7 +35,7 @@ describe('Client', () => {
|
||||||
it('should return false if two observations are not equals independent of control attributes', () => {
|
it('should return false if two observations are not equals independent of control attributes', () => {
|
||||||
let ob1 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: true};
|
let ob1 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: true};
|
||||||
let ob2 = {id: 1, observationTypeFk: 1, description: 'Spiderman sucks', showAddIcon: true};
|
let ob2 = {id: 1, observationTypeFk: 1, description: 'Spiderman sucks', showAddIcon: true};
|
||||||
let equals = controller._observationsEquals(ob2, ob1);
|
let equals = controller.equalObservations(ob2, ob1);
|
||||||
|
|
||||||
expect(equals).toBeFalsy();
|
expect(equals).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
@ -45,7 +45,7 @@ describe('Client', () => {
|
||||||
it('should perform a GET query to receive the address observations', () => {
|
it('should perform a GET query to receive the address observations', () => {
|
||||||
let filter = {where: {addressFk: 1}, include: {relation: 'observationType'}};
|
let filter = {where: {addressFk: 1}, include: {relation: 'observationType'}};
|
||||||
let res = ['some notes'];
|
let res = ['some notes'];
|
||||||
$httpBackend.when('GET', `/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).respond(res);
|
$httpBackend.whenGET(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).respond(res);
|
||||||
$httpBackend.expectGET(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`);
|
$httpBackend.expectGET(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`);
|
||||||
controller.$onInit();
|
controller.$onInit();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
|
@ -203,8 +203,8 @@ export default class Watcher extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
dataChanged() {
|
dataChanged() {
|
||||||
if (this.form && this.form.$dirty) return true;
|
|
||||||
let newData = this.copyInNewObject(this.data);
|
let newData = this.copyInNewObject(this.data);
|
||||||
|
if (this.form && this.form.$dirty) return !isEqual(newData, this.orgData);
|
||||||
return !isEqual(newData, this.orgData);
|
return !isEqual(newData, this.orgData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,8 +103,8 @@ export default {
|
||||||
firstObservationTypeSelect: `${components.vnAutocomplete}[field="observation.observationTypeFk"]:nth-child(1) input`,
|
firstObservationTypeSelect: `${components.vnAutocomplete}[field="observation.observationTypeFk"]:nth-child(1) input`,
|
||||||
firstObservationTypeSelectOptionOne: `${components.vnAutocomplete}[field="observation.observationTypeFk"] vn-drop-down ul > li:nth-child(1)`,
|
firstObservationTypeSelectOptionOne: `${components.vnAutocomplete}[field="observation.observationTypeFk"] vn-drop-down ul > li:nth-child(1)`,
|
||||||
firstObservationDescriptionInput: `vn-horizontal:nth-child(3) > vn-textfield[label="Description"] > div > input`,
|
firstObservationDescriptionInput: `vn-horizontal:nth-child(3) > vn-textfield[label="Description"] > div > input`,
|
||||||
secondObservationTypeSelect: `${components.vnAutocomplete}[field="observation.observationTypeFk"]:nth-child(2) input`,
|
secondObservationTypeSelect: `vn-horizontal:nth-child(4) > ${components.vnAutocomplete}[field="observation.observationTypeFk"] input`,
|
||||||
secondObservationTypeSelectOptionTwo: `${components.vnAutocomplete}[field="observation.observationTypeFk"] vn-drop-down ul > li:nth-child(2)`,
|
secondObservationTypeSelectOptionTwo: `vn-horizontal:nth-child(4) > ${components.vnAutocomplete}[field="observation.observationTypeFk"] vn-drop-down ul > li:nth-child(2)`,
|
||||||
secondObservationDescriptionInput: `vn-horizontal:nth-child(4) > vn-textfield[label="Description"] > div > input`,
|
secondObservationDescriptionInput: `vn-horizontal:nth-child(4) > vn-textfield[label="Description"] > div > input`,
|
||||||
thirdObservationTypeSelect: `${components.vnAutocomplete}[field="observation.observationTypeFk"]:nth-child(3) input`,
|
thirdObservationTypeSelect: `${components.vnAutocomplete}[field="observation.observationTypeFk"]:nth-child(3) input`,
|
||||||
thirdObservationTypeSelectOptionThree: `${components.vnAutocomplete}[field="observation.observationTypeFk"] vn-drop-down ul > li:nth-child(3)`,
|
thirdObservationTypeSelectOptionThree: `${components.vnAutocomplete}[field="observation.observationTypeFk"] vn-drop-down ul > li:nth-child(3)`,
|
||||||
|
|
|
@ -1,99 +1,99 @@
|
||||||
// import selectors from '../../helpers/selectors.js';
|
import selectors from '../../helpers/selectors.js';
|
||||||
// import createNightmare from '../../helpers/helpers';
|
import createNightmare from '../../helpers/helpers';
|
||||||
|
|
||||||
// describe('Client', () => {
|
describe('Client', () => {
|
||||||
// describe('Add address notes path', () => {
|
describe('Add address notes path', () => {
|
||||||
// const nightmare = createNightmare();
|
const nightmare = createNightmare();
|
||||||
|
|
||||||
// beforeAll(() => {
|
beforeAll(() => {
|
||||||
// return nightmare
|
return nightmare
|
||||||
// .waitForLogin('developer');
|
.waitForLogin('developer');
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it('should click on the Clients button of the top bar menu', () => {
|
it('should click on the Clients button of the top bar menu', () => {
|
||||||
// return nightmare
|
return nightmare
|
||||||
// .waitToClick(selectors.globalItems.applicationsMenuButton)
|
.waitToClick(selectors.globalItems.applicationsMenuButton)
|
||||||
// .wait(selectors.globalItems.applicationsMenuVisible)
|
.wait(selectors.globalItems.applicationsMenuVisible)
|
||||||
// .waitToClick(selectors.globalItems.clientsButton)
|
.waitToClick(selectors.globalItems.clientsButton)
|
||||||
// .wait(selectors.clientsIndex.createClientButton)
|
.wait(selectors.clientsIndex.createClientButton)
|
||||||
// .parsedUrl()
|
.parsedUrl()
|
||||||
// .then(url => {
|
.then(url => {
|
||||||
// expect(url.hash).toEqual('#!/clients');
|
expect(url.hash).toEqual('#!/clients');
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it('should search for the user Petter Parker', () => {
|
it('should search for the user Petter Parker', () => {
|
||||||
// return nightmare
|
return nightmare
|
||||||
// .wait(selectors.clientsIndex.searchResult)
|
.wait(selectors.clientsIndex.searchResult)
|
||||||
// .type(selectors.clientsIndex.searchClientInput, 'Petter Parker')
|
.type(selectors.clientsIndex.searchClientInput, 'Petter Parker')
|
||||||
// .click(selectors.clientsIndex.searchButton)
|
.click(selectors.clientsIndex.searchButton)
|
||||||
// .waitForNumberOfElements(selectors.clientsIndex.searchResult, 1)
|
.waitForNumberOfElements(selectors.clientsIndex.searchResult, 1)
|
||||||
// .countSearchResults(selectors.clientsIndex.searchResult)
|
.countSearchResults(selectors.clientsIndex.searchResult)
|
||||||
// .then(result => {
|
.then(result => {
|
||||||
// expect(result).toEqual(1);
|
expect(result).toEqual(1);
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it(`should click on the search result to access to the client addresses`, () => {
|
it(`should click on the search result to access to the client addresses`, () => {
|
||||||
// return nightmare
|
return nightmare
|
||||||
// .waitForTextInElement(selectors.clientsIndex.searchResult, 'Petter Parker')
|
.waitForTextInElement(selectors.clientsIndex.searchResult, 'Petter Parker')
|
||||||
// .waitToClick(selectors.clientsIndex.searchResult)
|
.waitToClick(selectors.clientsIndex.searchResult)
|
||||||
// .waitToClick(selectors.clientAddresses.addressesButton)
|
.waitToClick(selectors.clientAddresses.addressesButton)
|
||||||
// .waitForURL('addresses/list')
|
.waitForURL('addresses/list')
|
||||||
// .url()
|
.url()
|
||||||
// .then(url => {
|
.then(url => {
|
||||||
// expect(url).toContain('addresses/list');
|
expect(url).toContain('addresses/list');
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it(`should click on the edit icon of the default address`, () => {
|
it(`should click on the edit icon of the default address`, () => {
|
||||||
// return nightmare
|
return nightmare
|
||||||
// .waitForTextInElement(selectors.clientAddresses.defaultAddress, '20 Ingram Street')
|
.waitForTextInElement(selectors.clientAddresses.defaultAddress, '20 Ingram Street')
|
||||||
// .waitToClick(selectors.clientAddresses.firstEditButton)
|
.waitToClick(selectors.clientAddresses.firstEditButton)
|
||||||
// .waitForURL('/edit')
|
.waitForURL('/edit')
|
||||||
// .url()
|
.url()
|
||||||
// .then(result => {
|
.then(result => {
|
||||||
// expect(result).toContain('/edit');
|
expect(result).toContain('/edit');
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it('should not save a description without observation type', () => {
|
it('should not save a description without observation type', () => {
|
||||||
// return nightmare
|
return nightmare
|
||||||
// .waitToClick(selectors.clientAddresses.addObservationButton)
|
.waitToClick(selectors.clientAddresses.addObservationButton)
|
||||||
// .wait(selectors.clientAddresses.firstObservationDescriptionInput)
|
.wait(selectors.clientAddresses.firstObservationDescriptionInput)
|
||||||
// .type(selectors.clientAddresses.firstObservationDescriptionInput, 'first description')
|
.type(selectors.clientAddresses.firstObservationDescriptionInput, 'first description')
|
||||||
// .waitToClick(selectors.clientAddresses.saveButton)
|
.waitToClick(selectors.clientAddresses.saveButton)
|
||||||
// .waitForSnackbar()
|
.waitForSnackbar()
|
||||||
// .then(result => {
|
.then(result => {
|
||||||
// expect(result).toContain('Some fields are invalid');
|
expect(result).toContain('No field can be blank');
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it('should not save an observation type without description', () => {
|
it('should not save an observation type without description', () => {
|
||||||
// return nightmare
|
return nightmare
|
||||||
// .clearInput(selectors.clientAddresses.firstObservationDescriptionInput)
|
.clearInput(selectors.clientAddresses.firstObservationDescriptionInput)
|
||||||
// .waitToClick(selectors.clientAddresses.firstObservationTypeSelect)
|
.waitToClick(selectors.clientAddresses.firstObservationTypeSelect)
|
||||||
// .waitToClick(selectors.clientAddresses.firstObservationTypeSelectOptionOne)
|
.waitToClick(selectors.clientAddresses.firstObservationTypeSelectOptionOne)
|
||||||
// .waitToClick(selectors.clientAddresses.saveButton)
|
.waitToClick(selectors.clientAddresses.saveButton)
|
||||||
// .waitForSnackbar()
|
.waitForSnackbar()
|
||||||
// .then(result => {
|
.then(result => {
|
||||||
// expect(result).toContain('Some fields are invalid');
|
expect(result).toContain('Some fields are invalid');
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it('should create two new observations', () => {
|
it('should create two new observations', () => {
|
||||||
// return nightmare
|
return nightmare
|
||||||
// .type(selectors.clientAddresses.firstObservationDescriptionInput, 'first description')
|
.type(selectors.clientAddresses.firstObservationDescriptionInput, 'first description')
|
||||||
// .waitToClick(selectors.clientAddresses.addObservationButton)
|
.waitToClick(selectors.clientAddresses.addObservationButton)
|
||||||
// .waitToClick(selectors.clientAddresses.secondObservationTypeSelect)
|
.waitToClick(selectors.clientAddresses.secondObservationTypeSelect)
|
||||||
// .waitToClick(selectors.clientAddresses.secondObservationTypeSelectOptionTwo)
|
.waitToClick(selectors.clientAddresses.secondObservationTypeSelectOptionTwo)
|
||||||
// .type(selectors.clientAddresses.secondObservationDescriptionInput, 'second description')
|
.type(selectors.clientAddresses.secondObservationDescriptionInput, 'second description')
|
||||||
// .waitToClick(selectors.clientAddresses.saveButton)
|
.waitToClick(selectors.clientAddresses.saveButton)
|
||||||
// .waitForSnackbar()
|
.waitForSnackbar()
|
||||||
// .then(result => {
|
.then(result => {
|
||||||
// expect(result).toContain('pepinillos saved!');
|
expect(result).toContain('Data saved!');
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ describe('Ticket', () => {
|
||||||
.click(selectors.createStateView.saveStateButton)
|
.click(selectors.createStateView.saveStateButton)
|
||||||
.waitForSnackbar()
|
.waitForSnackbar()
|
||||||
.then(result => {
|
.then(result => {
|
||||||
expect(result).toContain('El estado no puede estar en blanco'); // OLE!
|
expect(result).toContain('No changes to save');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue