claim.details isEditable
gitea/salix/1575-claim_details_discountError This commit looks good Details

This commit is contained in:
Bernat Exposito Domenech 2020-01-07 13:03:45 +01:00
parent cd0fc6d8d3
commit 8b0fd79f15
4 changed files with 37 additions and 9 deletions

View File

@ -54,7 +54,7 @@
</vn-td> </vn-td>
<vn-td number>{{::saleClaimed.sale.price | currency: 'EUR':2}}</vn-td> <vn-td number>{{::saleClaimed.sale.price | currency: 'EUR':2}}</vn-td>
<vn-td number> <vn-td number>
<span class="link" <span ng-class="{'link': $ctrl.isEditable}"
vn-tooltip="Edit discount" vn-tooltip="Edit discount"
ng-click="$ctrl.showEditPopover($event, saleClaimed)"> ng-click="$ctrl.showEditPopover($event, saleClaimed)">
{{saleClaimed.sale.discount}} % {{saleClaimed.sale.discount}} %

View File

@ -29,8 +29,10 @@ class Controller {
set salesClaimed(value) { set salesClaimed(value) {
this._salesClaimed = value; this._salesClaimed = value;
if (value) if (value) {
this.calculateTotals(); this.calculateTotals();
this.isClaimEditable();
}
} }
get salesClaimed() { get salesClaimed() {
@ -134,6 +136,12 @@ class Controller {
}); });
} }
isClaimEditable() {
this.$http.get(`Tickets/${this.claim.ticketFk}/isEditable`).then(res => {
this.isEditable = res.data;
});
}
updateDiscount() { updateDiscount() {
const claimedSale = this.saleClaimed.sale; const claimedSale = this.saleClaimed.sale;
if (this.newDiscount != claimedSale.discount) { if (this.newDiscount != claimedSale.discount) {

View File

@ -17,13 +17,14 @@ describe('claim', () => {
show: () => {} show: () => {}
}; };
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpBackend.when('GET', 'Claims/ClaimBeginnings').respond({}); $httpBackend.whenGET('Claims/ClaimBeginnings').respond({});
$httpBackend.whenGET(`Tickets/1/isEditable`).respond(true);
$state = _$state_; $state = _$state_;
aclService = {hasAny: () => true}; aclService = {hasAny: () => true};
controller = $componentController('vnClaimDetail', {$state, aclService, $scope}); controller = $componentController('vnClaimDetail', {$state, aclService, $scope});
controller.claim = {ticketFk: 1};
controller.salesToClaim = [{saleFk: 1}, {saleFk: 2}]; controller.salesToClaim = [{saleFk: 1}, {saleFk: 2}];
controller.salesClaimed = [{id: 1, sale: {}}]; controller.salesClaimed = [{id: 1, sale: {}}];
controller.claim = {ticketFk: 1};
controller.$.model = crudModel; controller.$.model = crudModel;
controller.$.addSales = { controller.$.addSales = {
hide: () => {}, hide: () => {},
@ -36,7 +37,6 @@ describe('claim', () => {
describe('openAddSalesDialog()', () => { describe('openAddSalesDialog()', () => {
it('should call getClaimableFromTicket and $.addSales.show', () => { it('should call getClaimableFromTicket and $.addSales.show', () => {
controller.$ = {addSales: {show: () => {}}};
spyOn(controller, 'getClaimableFromTicket'); spyOn(controller, 'getClaimableFromTicket');
spyOn(controller.$.addSales, 'show'); spyOn(controller.$.addSales, 'show');
controller.openAddSalesDialog(); controller.openAddSalesDialog();
@ -146,5 +146,14 @@ describe('claim', () => {
expect(controller.$.descriptor.show).toHaveBeenCalledWith(); expect(controller.$.descriptor.show).toHaveBeenCalledWith();
}); });
}); });
describe('isClaimEditable()', () => {
it('should check if the claim is editable', () => {
controller.isClaimEditable();
$httpBackend.flush();
expect(controller.isEditable).toBeTruthy();
});
});
}); });
}); });

View File

@ -29,13 +29,24 @@ describe('Component VnClientWebAccess', () => {
}); });
describe('isCustomer()', () => { describe('isCustomer()', () => {
it(`should perform a query if client is defined with an ID`, () => { it('should return a true if the password can be modified', () => {
controller.client = {id: '1234'}; controller.client = {id: '1234'};
controller.isCustomer();
$httpBackend.when('GET', `Clients/${controller.client.id}/hasCustomerRole`).respond('ok'); $httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond({isCustomer: true});
$httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`); controller.isCustomer();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.canChangePassword).toBeTruthy();
});
it(`should return a false if the password can't be modified`, () => {
controller.client = {id: '1234'};
$httpBackend.expectGET(`Clients/${controller.client.id}/hasCustomerRole`).respond({isCustomer: false});
controller.isCustomer();
$httpBackend.flush();
expect(controller.canChangePassword).toBeFalsy();
}); });
}); });