#1152 refactor ticket.sale

This commit is contained in:
Gerard 2019-02-26 17:32:32 +01:00
parent 44bc150d49
commit 4de73fb2a8
6 changed files with 82 additions and 62 deletions

View File

@ -160,6 +160,16 @@ let actions = {
.catch(done);
},
waitToFocus: function(selector, done) {
this.wait(selector)
.evaluate_now(selector => {
let element = document.querySelector(selector);
element.focus();
}, done, selector)
.then(done)
.catch(done);
},
isVisible: function(selector, done) {
this.wait(selector)
.evaluate_now(elementSelector => {

View File

@ -339,12 +339,13 @@ export default {
firstSaleThumbnailImage: 'vn-ticket-sale:nth-child(1) vn-tr:nth-child(1) vn-td:nth-child(3) > img',
firstSaleZoomedImage: 'body > div > div > img',
firstSaleQuantity: `vn-textfield[model="sale.quantity"]:nth-child(1) input`,
firstSaleQuantityCell: `vn-ticket-sale vn-tr:nth-child(1) > vn-td-editable`,
firstSaleQuantityClearInput: `vn-textfield[model="sale.quantity"] div.suffix > i`,
firstSaleID: 'vn-ticket-sale:nth-child(1) vn-td:nth-child(4) > span',
firstSalePrice: 'vn-ticket-sale:nth-child(1) vn-tr:nth-child(1) > vn-td:nth-child(7) > span',
firstSalePriceInput: 'vn-ticket-sale:nth-child(1) > vn-vertical > vn-popover.edit.dialog-summary.ng-isolate-scope.vn-popover.shown > div > div.content > div > vn-textfield',
firstSalePriceInput: 'vn-ticket-sale:nth-child(1) vn-popover.edit.dialog-summary.ng-isolate-scope.vn-popover.shown vn-textfield input',
firstSaleDiscount: 'vn-ticket-sale:nth-child(1) vn-td:nth-child(8) > span',
firstSaleDiscountInput: 'vn-ticket-sale:nth-child(1) vn-ticket-sale-edit-discount > div > vn-textfield > div > div > div.infix > input.ng-not-empty',
firstSaleDiscountInput: 'vn-ticket-sale:nth-child(1) vn-ticket-sale-edit-discount vn-textfield input',
firstSaleImport: 'vn-ticket-sale:nth-child(1) vn-td:nth-child(9)',
firstSaleReservedIcon: 'vn-ticket-sale vn-tr:nth-child(1) > vn-td:nth-child(2) > vn-icon:nth-child(3)',
firstSaleColour: `vn-ticket-sale vn-tr:nth-child(1) vn-td:nth-child(6) section:nth-child(1)`,

View File

@ -2,7 +2,7 @@ import selectors from '../../helpers/selectors.js';
import createNightmare from '../../helpers/nightmare';
// #1152 refactor ticket.sale, update price no funciona correctamente.
xdescribe('Ticket Edit sale path', () => {
describe('Ticket Edit sale path', () => {
const nightmare = createNightmare();
beforeAll(() => {
@ -138,7 +138,7 @@ xdescribe('Ticket Edit sale path', () => {
it('should try to add a higher quantity value and then receive an error', async() => {
const result = await nightmare
.waitToClick(selectors.ticketSales.firstSaleQuantityClearInput)
.waitToFocus(selectors.ticketSales.firstSaleQuantityCell)
.write(selectors.ticketSales.firstSaleQuantity, '9\u000d')
.waitForLastSnackbar();
@ -147,7 +147,7 @@ xdescribe('Ticket Edit sale path', () => {
it('should remove 1 from quantity', async() => {
const result = await nightmare
.waitToClick(selectors.ticketSales.firstSaleQuantityClearInput)
.waitToFocus(selectors.ticketSales.firstSaleQuantityCell)
.write(selectors.ticketSales.firstSaleQuantity, '4\u000d')
.waitForLastSnackbar();
@ -180,7 +180,6 @@ xdescribe('Ticket Edit sale path', () => {
it('should update the discount', async() => {
const result = await nightmare
.waitToClick(selectors.ticketSales.firstSaleDiscount)
.wait('vn-textfield[label="Discount"] > div[class="container selected"]') // a function selects the text after it's loaded
.write(selectors.ticketSales.firstSaleDiscountInput, '50\u000d')
// .write('body', '\u000d') // simulates enter
.waitForLastSnackbar();
@ -597,16 +596,16 @@ xdescribe('Ticket Edit sale path', () => {
describe('when state is preparation and loged as salesPerson', () => {
it(`shouldnt be able to edit the sale price`, async() => {
const result = await nightmare
.waitToClick(selectors.ticketSales.firstSalePrice)
.exists(selectors.ticketSales.firstSalePriceInput);
.waitToClick(selectors.ticketSales.firstSaleID)
.exists(selectors.ticketSales.firstSalePrice);
expect(result).toBeFalsy();
});
it(`shouldnt be able to edit the sale discount`, async() => {
const result = await nightmare
.waitToClick(selectors.ticketSales.firstSaleDiscount)
.exists(selectors.ticketSales.firstSaleDiscountInput);
.waitToClick(selectors.ticketSales.firstSaleID)
.exists(selectors.ticketSales.firstSaleDiscount);
expect(result).toBeFalsy();
});

View File

@ -3,6 +3,7 @@
</vn-horizontal>
<div pad-medium>
<vn-textfield
vn-focus
label="Discount"
model="$ctrl.newDiscount"
type="text"

View File

@ -107,14 +107,16 @@
{{::sale.itemFk | zeroFill:6}}
</span>
</vn-td>
<vn-td ng-if="!$ctrl.isEditable" number>{{sale.quantity}}</vn-td>
<vn-td ng-if="$ctrl.isEditable" number>
<vn-textfield
model="sale.quantity"
on-change="$ctrl.updateQuantity(sale.id, sale.quantity)"
type="text">
</vn-textfield>
</vn-td>
<vn-td-editable editable="!$ctrl.isEditable">
<text>{{sale.quantity}}</text>
<field>
<vn-textfield
model="sale.quantity"
on-change="$ctrl.updateQuantity(sale.id, sale.quantity)"
type="text">
</vn-textfield>
</field>
</vn-td-editable>
<vn-td expand>
<vn-fetched-tags
max-length="6"
@ -159,25 +161,34 @@
<vn-popover
class="edit dialog-summary"
vn-id="edit-price-popover"
on-open="$ctrl.getManaSalespersonMana()">
<vn-horizontal pad-medium class="header">
<h5>MANÁ: {{$ctrl.mana | currency: 'EUR':0}}</h5>
</vn-horizontal>
<div pad-medium>
<vn-textfield
label="Price"
model="$ctrl.editedPrice"
type="text"
on-change="$ctrl.updatePrice()">
<t-right-icons>
<span class="filter"></span>
</t-right-icons>
</vn-textfield>
<div class="simulator">
<p class="simulatorTitle" translate>New price</p>
<p>{{($ctrl.sale.quantity * $ctrl.editedPrice)
- (($ctrl.sale.discount * ($ctrl.sale.quantity * $ctrl.editedPrice))/100)
| currency: 'EUR':2}}</p>
on-open="$ctrl.getManaSalespersonMana()"
on-close="$ctrl.mana = null">
<vn-spinner
ng-if="$ctrl.mana == null"
style="padding: 1em;"
enable="true">
</vn-spinner>
<div ng-if="$ctrl.mana != null">
<vn-horizontal pad-medium class="header">
<h5>MANÁ: {{$ctrl.mana | currency: 'EUR':0}}</h5>
</vn-horizontal>
<div pad-medium>
<vn-textfield
vn-focus
label="Price"
model="$ctrl.editedPrice"
type="text"
on-change="$ctrl.updatePrice()">
<t-right-icons>
<span class="filter"></span>
</t-right-icons>
</vn-textfield>
<div class="simulator">
<p class="simulatorTitle" translate>New price</p>
<p>{{($ctrl.sale.quantity * $ctrl.editedPrice)
- (($ctrl.sale.discount * ($ctrl.sale.quantity * $ctrl.editedPrice))/100)
| currency: 'EUR':2}}</p>
</div>
</div>
</div>
</vn-popover>
@ -186,22 +197,36 @@
<vn-popover
class="edit dialog-summary"
vn-id="edit-popover"
on-open="$ctrl.getManaSalespersonMana()">
<vn-ticket-sale-edit-discount
mana="$ctrl.mana"
bulk="false"
edit="$ctrl.edit"
on-hide="$ctrl.hideEditPopover()">
</vn-ticket-sale-edit-discount>
on-open="$ctrl.getManaSalespersonMana()"
on-close="$ctrl.mana = null">
<vn-spinner
ng-if="$ctrl.mana == null"
style="padding: 1em;"
enable="true">
</vn-spinner>
<vn-ticket-sale-edit-discount
ng-if="$ctrl.mana != null"
mana="$ctrl.mana"
bulk="false"
edit="$ctrl.edit"
on-hide="$ctrl.hideEditPopover()">
</vn-ticket-sale-edit-discount>
</vn-popover>
<!-- Edit Dialog -->
<vn-dialog
vn-id="editDialog"
class="edit"
on-open="$ctrl.getManaSalespersonMana()">
on-open="$ctrl.getManaSalespersonMana()"
on-close="$ctrl.mana = null">
<tpl-body>
<vn-spinner
ng-if="$ctrl.mana == null"
style="padding: 1em;"
enable="true">
</vn-spinner>
<vn-ticket-sale-edit-discount
ng-if="$ctrl.mana != null"
mana="$ctrl.mana"
bulk="true"
edit="$ctrl.edit"

View File

@ -195,19 +195,6 @@ class Controller {
this.$state.go('ticket.card.sale', {id: ticketID});
}
// Focus First Input
focusFirstInput(e) {
let firstFocusable = e.querySelector('input, textarea');
if (firstFocusable) {
firstFocusable.addEventListener('focus', () => {
firstFocusable.select();
});
setTimeout(() => {
firstFocusable.focus();
}, 200);
}
}
// Slesperson Mana
getManaSalespersonMana() {
this.$http.get(`/api/Tickets/${this.$state.params.id}/getSalesPersonMana`).then(res => {
@ -248,15 +235,14 @@ class Controller {
};
this.$scope.editPricePopover.parent = event.target;
this.$scope.editPricePopover.show();
this.focusFirstInput(this.$scope.editPricePopover.$element[0]);
}
updatePrice() {
if (this.editedPrice != this.sale.price) {
this.$http.post(`/ticket/api/Sales/updatePrice`, {id: this.edit.id, price: this.editedPrice, ticketFk: this.ticket.id}).then(() => {
this.sale.price = this.edit.price;
this.$scope.model.refresh();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
this.$scope.model.refresh();
});
}
@ -274,13 +260,11 @@ class Controller {
}];
this.$scope.editPopover.parent = event.target;
this.$scope.editPopover.show();
this.focusFirstInput(this.$scope.editPopover.$element[0]);
}
showEditDialog() {
this.edit = this.getCheckedLines();
this.$scope.editDialog.show();
this.focusFirstInput(this.$scope.editDialog.$element[0]);
}
hideEditDialog() {