#757 nueva seccion 3 puntos

This commit is contained in:
Gerard 2018-11-08 15:20:42 +01:00
parent f8ef767f2c
commit b72cdde12f
9 changed files with 233 additions and 146 deletions

View File

@ -3,10 +3,19 @@
<a translate-attr="{title: 'Return to module index'}" ui-sref="ticket.index">
<vn-icon icon="chevron_left"></vn-icon>
</a>
<vn-icon icon="icon-ticket"></vn-icon>
<a translate-attr="{title: 'Preview'}" ui-sref="ticket.card.summary({id: $ctrl.ticket.id})">
<vn-icon icon="desktop_windows"></vn-icon>
</a>
<vn-icon-menu
vn-id="more-button"
icon="more_vert"
show-filter="false"
value-field="callback"
translate-fields="['name']"
data="$ctrl.moreOptions"
on-change="$ctrl.onMoreChange(value)"
on-open="$ctrl.onMoreOpen()">
</vn-icon-menu>
</vn-horizontal>
<div pad-medium>
<h5>{{::$ctrl.client.name}}</h5>
@ -84,3 +93,49 @@
</a>
</vn-horizontal>
</vn-card>
<vn-dialog class="dialog-summary"
vn-id="addTurn">
<tpl-body>
<div>
<h5 style="text-align: center">
<span translate>In which day you want to add the ticket?</span>
</h5>
<vn-tool-bar margin-medium-top>
<vn-button
label="Monday"
ng-click="$ctrl.addTurn(0)">
</vn-button>
<vn-button
label="Tuesday"
ng-click="$ctrl.addTurn(1)">
</vn-button>
<vn-button
label="Wednesday"
ng-click="$ctrl.addTurn(2)">
</vn-button>
<vn-button
label="Thursday"
ng-click="$ctrl.addTurn(3)">
</vn-button>
<vn-button
label="Friday"
ng-click="$ctrl.addTurn(4)">
</vn-button>
<vn-button
label="Saturday"
ng-click="$ctrl.addTurn(5)">
</vn-button>
<vn-button
label="Sunday"
ng-click="$ctrl.addTurn(6)">
</vn-button>
</vn-tool-bar>
</div>
</tpl-body>
</vn-dialog>
<vn-confirm
vn-id="deleteConfirmation"
on-response="$ctrl.deleteTicket(response)"
question="You are going to delete this ticket"
message="Continue anyway?">
</vn-confirm>

View File

@ -1,11 +1,64 @@
import ngModule from '../module';
class Controller {
constructor($state, $scope) {
constructor($state, $scope, $http, vnApp, $translate) {
this.$scope = $scope;
this.$state = $state;
this.$http = $http;
this.vnApp = vnApp;
this.$translate = $translate;
this.moreOptions = [
{callback: this.showAddTurnDialog, name: 'Add turn'},
{callback: this.showDeleteTicketDialog, name: 'Delete ticket'}
];
}
onMoreChange(callback) {
callback.call(this);
}
get isEditable() {
try {
return !this.ticket.tracking.state.alertLevel;
} catch (e) {}
return true;
}
// Add Turn
showAddTurnDialog() {
this.$scope.addTurn.show();
}
addTurn(day) {
let params = {ticketFk: this.ticket.id, weekDay: day};
this.$http.patch(`/ticket/api/TicketWeeklies`, params).then(() => {
this.$scope.addTurn.hide();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}
// Delete Ticket
showDeleteTicketDialog() {
if (!this.isEditable) {
this.vnApp.showError(this.$translate.instant('This ticket cant be deleted'));
return;
}
this.$scope.deleteConfirmation.show();
}
deleteTicket(response) {
if (response === 'ACCEPT') {
let params = {id: this.ticket.id};
this.$http.post(`/ticket/api/Tickets/deleted`, params).then(() => {
this.$state.go('ticket.index');
this.vnApp.showSuccess(this.$translate.instant('Ticket deleted'));
});
}
}
get ticket() {
return this._ticket;
}
@ -33,7 +86,7 @@ class Controller {
}
}
Controller.$inject = ['$state', '$scope'];
Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate'];
ngModule.component('vnTicketDescriptor', {
template: require('./index.html'),

View File

@ -0,0 +1,76 @@
import './index.js';
describe('Item Component vnTicketDescriptor', () => {
let $componentController;
let $httpBackend;
let controller;
beforeEach(() => {
angular.mock.module('item');
});
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnTicketDescriptor');
controller.ticket = {id: 2};
}));
describe('showAddTurnDialog()', () => {
it('should call contrtoller.$scope.addTurn.show()', () => {
controller.$scope.addTurn = {show: () => {}};
spyOn(controller.$scope.addTurn, 'show');
controller.showAddTurnDialog();
expect(controller.$scope.addTurn.show).toHaveBeenCalledWith();
});
});
describe('addTurn(day)', () => {
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
controller.$scope.addTurn = {hide: () => {}};
spyOn(controller.$scope.addTurn, 'hide');
$httpBackend.expectPATCH(`/ticket/api/TicketWeeklies`).respond();
controller.addTurn(1);
$httpBackend.flush();
expect(controller.$scope.addTurn.hide).toHaveBeenCalledWith();
});
});
describe('showDeleteTicketDialog()', () => {
it('should call vnApp.showError() if the ticket isnt editable', () => {
controller.ticket.tracking = {state: {alertLevel: 3}};
spyOn(controller.vnApp, 'showError');
controller.showDeleteTicketDialog();
expect(controller.vnApp.showError).toHaveBeenCalledWith('This ticket cant be deleted');
});
it('should call deleteConfirmation.show() if the ticket is editable', () => {
controller.ticket.tracking = {state: {alertLevel: 0}};
controller.$scope.deleteConfirmation = {show: () => {}};
spyOn(controller.$scope.deleteConfirmation, 'show');
controller.showDeleteTicketDialog();
expect(controller.$scope.deleteConfirmation.show).toHaveBeenCalledWith();
});
});
describe('deleteTicket(response)', () => {
it('should make a query and call vnApp.showSuccess() if the response is ACCEPT', () => {
spyOn(controller.$state, 'go');
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`/ticket/api/Tickets/deleted`, {id: 2}).respond();
controller.deleteTicket('ACCEPT');
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('ticket.index');
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket deleted');
});
});
});

View File

@ -186,7 +186,7 @@ vn-main-block {
padding: .1em;
font-size: 2.5em;
}
& > a {
& > a , & > vn-icon-menu {
@extend %clickable;
display: flex;
align-items: center;
@ -197,6 +197,10 @@ vn-main-block {
& > vn-icon {
font-size: 1.8em;
}
& vn-drop-down{
color: initial;
}
}
}
.footer {

View File

@ -14,13 +14,14 @@
ng-click="$ctrl.onStateOkClick()"
vn-tooltip="Change ticket state to 'Ok'">
</vn-button>
<vn-icon-menu
<vn-button-menu
disabled="!$ctrl.isEditable"
label="State"
url="/ticket/api/States/alertLevelIs0"
on-change="$ctrl.onStateChange(value)">
</vn-icon-menu>
<vn-icon-menu
</vn-button-menu>
<vn-button-menu
ng-show="$ctrl.isChecked"
vn-id="more-button"
label="More"
show-filter="false"
@ -28,7 +29,7 @@
translate-fields="['name']"
on-change="$ctrl.onMoreChange(value)"
on-open="$ctrl.onMoreOpen()">
</vn-icon-menu>
</vn-button-menu>
<vn-button
disabled="!$ctrl.isChecked || !$ctrl.isEditable"
ng-click="$ctrl.showRemoveLinesDialog()"
@ -161,48 +162,6 @@
quicklinks="$ctrl.quicklinks">
</vn-item-descriptor-popover>
<!-- Add Turn Dialog -->
<vn-dialog class="dialog-summary"
vn-id="addTurn">
<tpl-body>
<div>
<h5 style="text-align: center">
<span translate>In which day you want to add the ticket?</span>
</h5>
<vn-tool-bar margin-medium-top>
<vn-button
label="Monday"
ng-click="$ctrl.addTurn(0)">
</vn-button>
<vn-button
label="Tuesday"
ng-click="$ctrl.addTurn(1)">
</vn-button>
<vn-button
label="Wednesday"
ng-click="$ctrl.addTurn(2)">
</vn-button>
<vn-button
label="Thursday"
ng-click="$ctrl.addTurn(3)">
</vn-button>
<vn-button
label="Friday"
ng-click="$ctrl.addTurn(4)">
</vn-button>
<vn-button
label="Saturday"
ng-click="$ctrl.addTurn(5)">
</vn-button>
<vn-button
label="Sunday"
ng-click="$ctrl.addTurn(6)">
</vn-button>
</vn-tool-bar>
</div>
</tpl-body>
</vn-dialog>
<!-- Edit Price Popover -->
<vn-popover
class="edit dialog-summary"
@ -310,12 +269,6 @@
</div>
</vn-popover>
</vn-vertical>
<vn-confirm
vn-id="deleteConfirmation"
on-response="$ctrl.deleteTicket(response)"
question="You are going to delete this ticket"
message="Continue anyway?">
</vn-confirm>
<vn-confirm
vn-id="delete-lines"
question="You are going to delete lines of the ticket"

View File

@ -12,8 +12,6 @@ class Controller {
this.deletable = false;
this.edit = {};
this.moreOptions = [
{callback: this.showAddTurnDialog, name: 'Add turn', always: true},
{callback: this.showDeleteTicketDialog, name: 'Delete ticket', always: true},
{callback: this.markAsReserved, name: 'Mark as reserved'},
{callback: this.unmarkAsReserved, name: 'Unmark as reserved'},
{callback: this.showEditDialog, name: 'Update discount'},
@ -114,36 +112,6 @@ class Controller {
});
}
// Add Turn
showAddTurnDialog() {
this.$scope.addTurn.show();
}
addTurn(day) {
let params = {ticketFk: this.$state.params.id, weekDay: day};
this.$http.patch(`/ticket/api/TicketWeeklies`, params).then(() => {
this.$scope.addTurn.hide();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}
// Delete Ticket
showDeleteTicketDialog() {
if (!this.isEditable)
return;
this.$scope.deleteConfirmation.show();
}
deleteTicket(response) {
if (response === 'ACCEPT') {
let params = {id: this.$state.params.id};
this.$http.post(`/ticket/api/Tickets/deleted`, params).then(() => {
this.$state.go('ticket.index');
this.vnApp.showSuccess(this.$translate.instant('Ticket deleted'));
});
}
}
// Remove Lines
onRemoveLinesClick(response) {
if (response === 'ACCEPT') {

View File

@ -108,28 +108,6 @@ describe('Ticket', () => {
});
});
describe('showAddTurnDialog()', () => {
it('should call contrtoller.$scope.addTurn.show()', () => {
controller.$scope.addTurn = {show: () => {}};
spyOn(controller.$scope.addTurn, 'show');
controller.showAddTurnDialog();
expect(controller.$scope.addTurn.show).toHaveBeenCalledWith();
});
});
describe('addTurn(day)', () => {
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
spyOn(controller.$scope.addTurn, 'hide');
$httpBackend.expectPATCH(`/ticket/api/TicketWeeklies`).respond();
controller.addTurn(1);
$httpBackend.flush();
expect(controller.$scope.addTurn.hide).toHaveBeenCalledWith();
});
});
describe('onStateChange()', () => {
it('should perform a post and then call a function', () => {
$httpBackend.expectPOST(`/ticket/api/TicketTrackings/changeState`).respond();

View File

@ -358,13 +358,12 @@ export default {
moveToNewTicketButton: 'vn-ticket-sale vn-popover.transfer vn-button[label="New ticket"]',
acceptDeleteLineButton: `vn-ticket-sale > vn-confirm[vn-id="delete-lines"] button[response=ACCEPT]`,
acceptDeleteTicketButton: `vn-ticket-sale > vn-confirm[vn-id="deleteConfirmation"] button[response=ACCEPT]`,
stateMenuButton: 'vn-ticket-sale vn-tool-bar > vn-icon-menu[label="State"] button',
stateMenuButton: 'vn-ticket-sale vn-tool-bar > vn-button-menu[label="State"] button',
stateMenuOptions: 'vn-ticket-sale vn-drop-down > vn-popover ul > li:nth-child(1)',
moreMenuButton: 'vn-ticket-sale vn-tool-bar > vn-icon-menu[label="More"] button',
moreMenuDeleteOption: 'vn-ticket-sale vn-drop-down > vn-popover ul > li:nth-child(2)',
moreMenuReseveOption: 'vn-ticket-sale vn-drop-down > vn-popover ul > li:nth-child(4)',
moreMenuUnmarkResevedOption: 'vn-ticket-sale vn-drop-down > vn-popover ul > li:nth-child(5)',
moreMenuUpdateDiscount: 'vn-ticket-sale vn-drop-down > vn-popover ul > li:nth-child(6)',
moreMenuButton: 'vn-ticket-sale vn-tool-bar > vn-button-menu[label="More"] button',
moreMenuReseveOption: 'vn-ticket-sale vn-drop-down > vn-popover ul > li:nth-child(2)',
moreMenuUnmarkResevedOption: 'vn-ticket-sale vn-drop-down > vn-popover ul > li:nth-child(3)',
moreMenuUpdateDiscount: 'vn-ticket-sale vn-drop-down > vn-popover ul > li:nth-child(4)',
moreMenuUpdateDiscountInput: 'vn-ticket-sale vn-dialog.shown vn-ticket-sale-edit-discount input',
moreMenuCreateClaim: 'vn-ticket-sale vn-drop-down > vn-popover ul > li:nth-child(1)'
},

View File

@ -668,35 +668,36 @@ describe('Ticket Edit sale path', () => {
expect(url).toContain('/sale');
});
it(`should be able to delete the ticket`, async () => {
const url = await nightmare
.waitToClick(selectors.ticketSales.moreMenuButton)
.waitToClick(selectors.ticketSales.moreMenuDeleteOption)
.waitToClick(selectors.ticketSales.acceptDeleteTicketButton)
.waitForURL('/ticket/index')
.url();
expect(url).toContain('/ticket/index');
});
it(`should search for the deleted ticket`, async () => {
const result = await nightmare
.wait(selectors.ticketsIndex.searchResult)
.type(selectors.ticketsIndex.searchTicketInput, 'id:17')
.click(selectors.ticketsIndex.searchButton)
.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1)
.countElement(selectors.ticketsIndex.searchResult);
expect(result).toEqual(1);
});
it(`should search for the deleted ticket`, async () => {
const result = await nightmare
.wait(selectors.ticketsIndex.searchResultDate)
.getInnerText(selectors.ticketsIndex.searchResultDate);
expect(result).toContain(2000);
});
});
});
// TAREA #802 e2e ticket.descriptor
/* it(`should be able to delete the ticket`, async () => {
const url = await nightmare
.waitToClick(selectors.ticketSales.moreMenuButton)
.waitToClick(selectors.ticketSales.moreMenuDeleteOption)
.waitToClick(selectors.ticketSales.acceptDeleteTicketButton)
.waitForURL('/ticket/index')
.url();
expect(url).toContain('/ticket/index');
});
it(`should search for the deleted ticket`, async () => {
const result = await nightmare
.wait(selectors.ticketsIndex.searchResult)
.type(selectors.ticketsIndex.searchTicketInput, 'id:17')
.click(selectors.ticketsIndex.searchButton)
.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1)
.countElement(selectors.ticketsIndex.searchResult);
expect(result).toEqual(1);
});
it(`should search for the deleted ticket`, async () => {
const result = await nightmare
.wait(selectors.ticketsIndex.searchResultDate)
.getInnerText(selectors.ticketsIndex.searchResultDate);
expect(result).toContain(2000);
}); */