2509 - Added forms to create new locations + e2e #412

Merged
carlosjr merged 6 commits from 2509-add_geolocation into dev 2020-10-19 18:57:18 +00:00
24 changed files with 340 additions and 47 deletions

View File

@ -0,0 +1,3 @@
UPDATE `salix`.`ACL` SET `principalId` = 'deliveryBoss' WHERE (`id` = '194');
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Town', '*', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss');
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Province', '*', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss');

View File

@ -42,13 +42,24 @@ export default {
taxNumber: 'vn-client-create vn-textfield[ng-model="$ctrl.client.fi"]',
socialName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.socialName"]',
street: 'vn-client-create vn-textfield[ng-model="$ctrl.client.street"]',
addPostCode: 'vn-client-create vn-datalist[ng-model="$ctrl.client.postcode"] vn-icon-button[icon="add_circle"]',
addProvince: 'vn-autocomplete[ng-model="$ctrl.location.provinceFk"] vn-icon-button[icon="add_circle"]',
addCity: 'vn-autocomplete[ng-model="$ctrl.location.townFk"] vn-icon-button[icon="add_circle"]',
newProvinceName: 'vn-textfield[ng-model="$ctrl.province.name"]',
newCityName: 'vn-textfield[ng-model="$ctrl.city.name"]',
newCityProvince: 'vn-autocomplete[ng-model="$ctrl.city.provinceFk"]',
newPostcode: 'vn-textfield[ng-model="$ctrl.location.code"]',
postcode: 'vn-client-create vn-datalist[ng-model="$ctrl.client.postcode"]',
city: 'vn-client-create vn-datalist[ng-model="$ctrl.client.city"]',
province: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.provinceFk"]',
province: 'vn-autocomplete[ng-model="$ctrl.client.provinceFk"]',
country: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.countryFk"]',
dialogCountry: 'vn-autocomplete[ng-model="$ctrl.province.countryFk"]',
userName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.userName"]',
email: 'vn-client-create vn-textfield[ng-model="$ctrl.client.email"]',
salesPerson: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.salesPersonFk"]',
saveNewProvicenButton: '#saveProvince',
saveNewCityButton: '#saveCity',
saveNewPoscode: '#savePostcode',
createButton: 'vn-client-create button[type=submit]'
},
clientDescriptor: {

View File

@ -8,7 +8,7 @@ describe('Client create path', () => {
beforeAll(async() => {
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'client');
await page.loginAndModule(' deliveryBoss', 'client');
});
afterAll(async() => {
@ -45,14 +45,40 @@ describe('Client create path', () => {
expect(message.text).toBe('Some fields are invalid');
});
it(`should create a new province`, async() => {
await page.waitToClick(selectors.createClientView.addPostCode);
await page.waitToClick(selectors.createClientView.addProvince);
await page.write(selectors.createClientView.newProvinceName, 'Massachusetts');
await page.autocompleteSearch(selectors.createClientView.dialogCountry, 'España');
await page.waitToClick(selectors.createClientView.saveNewProvicenButton);
const message = await page.waitForSnackbar();
expect(message.text).toBe('The province has been created');
});
it(`should create a new city`, async() => {
await page.waitToClick(selectors.createClientView.addCity);
await page.write(selectors.createClientView.newCityName, 'Boston');
await page.autocompleteSearch(selectors.createClientView.newCityProvince, 'Massachusetts');
await page.waitToClick(selectors.createClientView.saveNewCityButton);
const message = await page.waitForSnackbar();
expect(message.text).toBe('The city has been created');
});
it(`should create a new post code`, async() => {
await page.write(selectors.createClientView.newPostcode, '61616');
await page.waitToClick(selectors.createClientView.saveNewPoscode);
const message = await page.waitForSnackbar();
expect(message.text).toBe('The postcode has been created. You can save the data now');
});
it(`should attempt to create a new user with all it's data but wrong email`, async() => {
await page.write(selectors.createClientView.name, 'Carol Danvers');
await page.write(selectors.createClientView.socialName, 'AVG tax');
await page.write(selectors.createClientView.street, 'Many places');
await page.autocompleteSearch(selectors.createClientView.country, 'España');
await page.autocompleteSearch(selectors.createClientView.province, 'Province one');
await page.write(selectors.createClientView.city, 'Valencia');
await page.write(selectors.createClientView.postcode, '46000');
await page.clearInput(selectors.createClientView.email);
await page.write(selectors.createClientView.email, 'incorrect email format');
await page.waitToClick(selectors.createClientView.createButton);
@ -82,14 +108,14 @@ describe('Client create path', () => {
const clientCountry = await page
.waitToGetProperty(selectors.createClientView.country, 'value');
expect(clientCity).toEqual('Valencia');
expect(clientProvince).toContain('Province one');
expect(clientCity).toEqual('Boston');
expect(clientProvince).toContain('Massachusetts');
expect(clientCountry).toEqual('España');
});
it(`should create a new user with all correct data`, async() => {
await page.clearInput(selectors.createClientView.postcode);
await page.write(selectors.createClientView.postcode, '46000');
await page.write(selectors.createClientView.postcode, '61616');
await page.waitToClick(selectors.createClientView.createButton);
const message = await page.waitForSnackbar();

View File

@ -26,7 +26,9 @@ describe('Entry create path', () => {
await page.autocompleteSearch(selectors.entryIndex.newEntryCompany, 'ORN');
await page.waitToClick(selectors.entryIndex.saveNewEntry);
await page.waitFor(500);
await page.waitForNavigation({
waitUntil: 'load',
});
await page.waitForState('entry.card.basicData');
});
});

View File

@ -153,9 +153,9 @@
</form>
<!-- New postcode dialog -->
<vn-client-postcode vn-id="postcode"
<vn-geo-postcode vn-id="postcode"
on-response="$ctrl.onResponse($response)">
</vn-client-postcode>
</vn-geo-postcode>
<!-- Create custom agent dialog -->
<vn-dialog class="edit"

View File

@ -74,6 +74,8 @@ export default class Controller extends Section {
onResponse(response) {
this.address.postalCode = response.code;
this.address.city = response.city;
this.address.provinceFk = response.provinceFk;
}
}

View File

@ -191,9 +191,9 @@
</form>
<!-- New postcode dialog -->
<vn-client-postcode vn-id="postcode"
<vn-geo-postcode vn-id="postcode"
on-response="$ctrl.onResponse($response)">
</vn-client-postcode>
</vn-geo-postcode>
<!-- Create custom agent dialog -->
<vn-dialog class="edit"

View File

@ -78,6 +78,8 @@ export default class Controller extends Section {
onResponse(response) {
this.address.postalCode = response.code;
this.address.city = response.city;
this.address.provinceFk = response.provinceFk;
}
}

View File

@ -5,12 +5,6 @@
insert-mode="true"
form="form">
</vn-watcher>
<vn-crud-model
auto-load="true"
url="Towns/location"
data="townLocations"
order="name">
</vn-crud-model>
<form name="form" vn-http-submit="$ctrl.onSubmit()" class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-horizontal>
@ -82,7 +76,7 @@
label="City"
ng-model="$ctrl.client.city"
selection="$ctrl.town"
data="townsLocation"
url="Towns/location"
fields="['id', 'name', 'provinceFk']"
value-field="name">
<tpl-item>
@ -136,7 +130,7 @@
</vn-button-bar>
</form>
<!-- New postcode dialog -->
<vn-client-postcode
<vn-geo-postcode
vn-id="postcode"
on-response="$ctrl.onResponse($response)">
</vn-client-postcode>
</vn-geo-postcode>

View File

@ -81,6 +81,9 @@ export default class Controller extends Section {
onResponse(response) {
this.client.postcode = response.code;
this.client.city = response.city;
this.client.provinceFk = response.provinceFk;
this.client.countryFk = response.countryFk;
}
}

View File

@ -173,7 +173,7 @@
on-accept="$ctrl.onAcceptDuplication()">
</vn-confirm>
<!-- New postcode dialog -->
<vn-client-postcode
<vn-geo-postcode
vn-id="postcode"
on-response="$ctrl.onResponse($response)">
</vn-client-postcode>
</vn-geo-postcode>

View File

@ -159,6 +159,9 @@ export default class Controller extends Section {
onResponse(response) {
this.client.postcode = response.code;
this.client.city = response.city;
this.client.provinceFk = response.provinceFk;
this.client.countryFk = response.countryFk;
}
}

View File

@ -37,6 +37,8 @@ import './web-payment';
import './log';
import './sms';
import './postcode';
import './postcode/province';
import './postcode/city';
import './dms/index';
import './dms/create';
import './dms/edit';

View File

@ -0,0 +1,27 @@
<vn-dialog class="edit"
vn-id="cityDialog"
on-open="$ctrl.onOpen()"
on-accept="$ctrl.onAccept()"
message="New city">
<tpl-body>
<p translate>Please, ensure you put the correct data!</p>
<vn-horizontal>
<vn-textfield vn-one
vn-focus
ng-model="$ctrl.city.name"
label="Name">
</vn-textfield>
<vn-autocomplete vn-one
ng-model="$ctrl.city.provinceFk"
url="Provinces"
show-field="name"
value-field="id"
label="Province">
</vn-autocomplete>
</vn-horizontal>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button id="saveCity" response="accept" translate>Save</button>
</tpl-buttons>
</vn-dialog>

View File

@ -0,0 +1,37 @@
import ngModule from '../../module';
import Component from 'core/lib/component';
class Controller extends Component { // Comprobar funcionamiento añadir ciudad
open($event) {
if ($event.defaultPrevented) return;
this.$.cityDialog.show();
$event.preventDefault();
}
onAccept() {
try {
if (!this.city.name)
throw new Error(`The city name can't be empty`);
if (!this.city.provinceFk)
throw new Error(`The province can't be empty`);
this.$http.patch(`towns`, this.city).then(res => {
this.vnApp.showMessage(this.$t('The city has been created'));
this.emit('response', {$response: res.data});
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
return true;
}
}
ngModule.vnComponent('vnGeoCity', {
template: require('./index.html'),
controller: Controller,
bindings: {
data: '<',
}
});

View File

@ -0,0 +1,34 @@
import './index';
describe('Client', () => {
describe('Component vnGeoCity', () => {
let controller;
let $httpBackend;
let $scope;
beforeEach(ngModule('client'));
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
const $element = angular.element('<vn-dialog></vn-dialog>');
controller = $componentController('vnGeoCity', {$element, $scope});
controller.client = {id: 101};
}));
describe('onAccept()', () => {
it('should perform a POST query and show a success snackbar', () => {
let params = {name: 'Gotham City', provinceFk: 1};
controller.city = {name: 'Gotham City', provinceFk: 1};
jest.spyOn(controller.vnApp, 'showMessage');
$httpBackend.expect('PATCH', `towns`, params).respond(200, params);
controller.onAccept();
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The city has been created');
});
});
});
});

View File

@ -11,7 +11,7 @@
vn-focus
vn-id="postcode"
label="Postcode"
ng-model="$ctrl.data.code"
ng-model="$ctrl.location.code"
required="true">
</vn-textfield>
<vn-autocomplete vn-one
@ -19,23 +19,39 @@
url="Towns/location"
show-field="name"
value-field="id"
ng-model="$ctrl.data.townFk"
ng-model="$ctrl.location.townFk"
selection="$ctrl.townSelection"
required="true">
<append>
<vn-icon-button
icon="add_circle"
vn-tooltip="New city"
ng-click="city.open($event)"
vn-acl="deliveryBoss"
vn-acl-action="remove">
</vn-icon-button>
</append>
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete vn-one
disabled="true"
ng-model="$ctrl.data.provinceFk"
ng-model="$ctrl.location.provinceFk"
url="Provinces"
show-field="name"
value-field="id"
label="Province">
<append>
<vn-icon-button
icon="add_circle"
vn-tooltip="New province"
ng-click="province.open($event)"
vn-acl="deliveryBoss"
vn-acl-action="remove">
</vn-icon-button>
</append>
</vn-autocomplete>
<vn-autocomplete vn-one
disabled="true"
ng-model="$ctrl.data.countryFk"
ng-model="$ctrl.location.countryFk"
url="Countries"
show-field="country"
value-field="id"
@ -45,6 +61,16 @@
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button response="accept" translate>Save</button>
<button id= "savePostcode" response="accept" translate>Save</button>
</tpl-buttons>
</vn-dialog>
</vn-dialog>
<!-- New province dialog -->
<vn-geo-province
vn-id="province"
on-response="$ctrl.onProvinceResponse($response)">
</vn-geo-province>
<!-- New city dialog -->
<vn-geo-city
vn-id="city"
on-response="$ctrl.onCityResponse($response)">
</vn-geo-city>

View File

@ -15,8 +15,9 @@ class Controller extends Component {
const province = selection.province;
const country = province.country;
this.data.provinceFk = province.id;
this.data.countryFk = country.id;
this.location.city = selection.name;
this.location.provinceFk = province.id;
this.location.countryFk = country.id;
}
open() {
@ -24,19 +25,35 @@ class Controller extends Component {
}
onOpen() {
this.location = {};
this.$.postcode.focus();
}
onProvinceResponse(response) {
this.location.provinceFk = response.id;
this.location.countryFk = response.countryFk;
}
onCityResponse(response) {
this.location.townFk = response.id;
this.location.provinceFk = response.provinceFk;
this.location.countryFk = response.countryFk;
}
onAccept() {
try {
if (!this.data.code)
if (!this.location.code)
throw new Error(`The postcode can't be empty`);
if (!this.data.townFk)
if (!this.location.townFk)
throw new Error(`The town can't be empty`);
if (!this.location.provinceFk)
throw new Error(`The province can't be empty`);
if (!this.location.provinceFk)
throw new Error(`The country can't be empty`);
this.$http.patch(`postcodes`, this.data).then(res => {
this.vnApp.showMessage(this.$t('The postcode has been saved'));
this.emit('response', {$response: res.data});
this.$http.patch(`postcodes`, this.location).then(() => {
this.vnApp.showMessage(this.$t('The postcode has been created. You can save the data now'));
this.emit('response', {$response: this.location});
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
@ -46,7 +63,7 @@ class Controller extends Component {
}
}
ngModule.vnComponent('vnClientPostcode', {
ngModule.vnComponent('vnGeoPostcode', {
template: require('./index.html'),
controller: Controller,
bindings: {

View File

@ -1,7 +1,7 @@
import './index';
describe('Client', () => {
describe('Component vnClientPostcode', () => {
describe('Component vnGeoPostcode', () => {
let controller;
let $httpBackend;
let $scope;
@ -12,14 +12,14 @@ describe('Client', () => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
const $element = angular.element('<vn-dialog></vn-dialog>');
controller = $componentController('vnClientPostcode', {$element, $scope});
controller = $componentController('vnGeoPostcode', {$element, $scope});
controller.client = {id: 101};
}));
describe('onAccept()', () => {
it('should perform a POST query and show a success snackbar', () => {
let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
controller.data = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
controller.location = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
jest.spyOn(controller.vnApp, 'showMessage');
$httpBackend.expect('PATCH', `postcodes`, params).respond(200, params);
@ -27,7 +27,7 @@ describe('Client', () => {
controller.onAccept();
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been saved');
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been created. You can save the data now');
});
});
});

View File

@ -1,5 +1,11 @@
New postcode: Nuevo código postal
New city: Nueva ciudad
New province: Nueva provincia
Please, ensure you put the correct data!: ¡Por favor, asegúrate de poner los datos correctos!
The postcode can't be empty: El código postal no puede quedar vacío
The town can't be empty: La población no puede quedar vacía
The postcode has been saved: El código postal ha sido guardado
The province can't be empty: La provincia no puede quedar vacía
The country can't be empty: El país no puede quedar vacío
The postcode has been created. You can save the data now: Se ha creado el código postal. Ahora puedes guardar los datos
The city has been created: Se ha creado la ciudad
The province has been created: Se ha creado la provincia

View File

@ -0,0 +1,27 @@
<vn-dialog class="edit"
vn-id="provinceDialog"
on-open="$ctrl.onOpen()"
on-accept="$ctrl.onAccept()"
message="New province">
<tpl-body>
<p translate>Please, ensure you put the correct data!</p>
<vn-horizontal>
<vn-textfield vn-one
vn-focus
ng-model="$ctrl.province.name"
label="Name">
</vn-textfield>
<vn-autocomplete vn-one
ng-model="$ctrl.province.countryFk"
url="Countries"
show-field="country"
value-field="id"
label="Country">
</vn-autocomplete>
</vn-horizontal>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button id="saveProvince" response="accept" translate>Save</button>
</tpl-buttons>
</vn-dialog>

View File

@ -0,0 +1,37 @@
import ngModule from '../../module';
import Component from 'core/lib/component';
class Controller extends Component {
open($event) {
if ($event.defaultPrevented) return;
this.$.provinceDialog.show();
$event.preventDefault();
}
onAccept() {
try {
if (!this.province.name)
throw new Error(`The province name can't be empty`);
if (!this.province.countryFk)
throw new Error(`The country can't be empty`);
this.$http.patch(`provinces`, this.province).then(res => {
this.vnApp.showMessage(this.$t('The province has been created'));
this.emit('response', {$response: res.data});
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
return false;
}
return true;
}
}
ngModule.vnComponent('vnGeoProvince', {
template: require('./index.html'),
controller: Controller,
bindings: {
data: '<',
}
});

View File

@ -0,0 +1,34 @@
import './index';
describe('Client', () => {
describe('Component vnGeoProvince', () => {
let controller;
let $httpBackend;
let $scope;
beforeEach(ngModule('client'));
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
const $element = angular.element('<vn-dialog></vn-dialog>');
controller = $componentController('vnGeoProvince', {$element, $scope});
controller.client = {id: 101};
}));
describe('onAccept()', () => {
it('should perform a POST query and show a success snackbar', () => {
let params = {name: 'New Jersey', countryFk: 1};
controller.province = {name: 'New Jersey', countryFk: 1};
jest.spyOn(controller.vnApp, 'showMessage');
$httpBackend.expect('PATCH', `provinces`, params).respond(200, params);
controller.onAccept();
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The province has been created');
});
});
});
});

View File

@ -1,6 +1,6 @@
@import "variables";
vn-client-postcode {
vn-geo-postcode {
vn-dialog {
p {
color: $color-alert