#738 Petición de guardado al hacer click sobre un botón + test adaptados

This commit is contained in:
Carlos Jimenez 2018-10-17 09:28:38 +02:00
parent 6773e58cad
commit 0601bb662c
15 changed files with 25 additions and 46 deletions

View File

@ -102,6 +102,6 @@
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button ng-click="$ctrl.cancel($event)" label="Cancel"></vn-button>
<vn-button ng-click="$ctrl.cancel()" label="Cancel"></vn-button>
</vn-button-bar>
</form>

View File

@ -12,9 +12,7 @@ export default class Controller {
this.$.model.remove(index);
}
cancel(event) {
event.preventDefault();
event.stopImmediatePropagation();
cancel() {
this.goToIndex();
}

View File

@ -45,19 +45,11 @@ describe('Client', () => {
});
});
describe('cancel(event)', () => {
it('should call event.preventDefault(), event.stopImmediatePropagation() and goToIndex', () => {
let event = {
preventDefault: () => {},
stopImmediatePropagation: () => {}
};
spyOn(event, 'preventDefault');
spyOn(event, 'stopImmediatePropagation');
describe('cancel()', () => {
it('should call goToIndex()', () => {
spyOn(controller, 'goToIndex');
controller.cancel(event);
controller.cancel();
expect(event.preventDefault).toHaveBeenCalledWith();
expect(event.stopImmediatePropagation).toHaveBeenCalledWith();
expect(controller.goToIndex).toHaveBeenCalledWith();
});
});

View File

@ -14,7 +14,7 @@
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button ng-click="$ctrl.cancel($event)" label="Cancel"></vn-button>
<vn-button ng-click="$ctrl.cancel()" label="Cancel"></vn-button>
</vn-button-bar>
</form>
<vn-confirm

View File

@ -17,9 +17,7 @@ class Controller {
});
}
cancel(event) {
event.preventDefault();
event.stopImmediatePropagation();
cancel() {
this.goToIndex();
}

View File

@ -68,19 +68,11 @@ describe('Client', () => {
});
describe('cancel()', () => {
it('should call preventDefault, stopImmediatePropagation and goToIndex', () => {
let event = {
preventDefault: () => {},
stopImmediatePropagation: () => {}
};
spyOn(event, 'preventDefault');
spyOn(event, 'stopImmediatePropagation');
it('should call goToIndex()', () => {
spyOn(controller, 'goToIndex');
controller.cancel(event);
controller.cancel();
expect(controller.goToIndex).toHaveBeenCalledWith();
expect(event.preventDefault).toHaveBeenCalledWith();
expect(event.stopImmediatePropagation).toHaveBeenCalledWith();
});
});

View File

@ -40,6 +40,6 @@
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button ng-click="$ctrl.cancel($event)" label="Cancel"></vn-button>
<vn-button ng-click="$ctrl.cancel()" label="Cancel"></vn-button>
</vn-button-bar>
</form>

View File

@ -9,9 +9,7 @@ class Controller {
};
}
cancel(event) {
event.preventDefault();
event.stopImmediatePropagation();
cancel() {
this.goToIndex();
}

View File

@ -21,6 +21,6 @@
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button ng-click="$ctrl.cancel($event)" label="Cancel"></vn-button>
<vn-button ng-click="$ctrl.cancel()" label="Cancel"></vn-button>
</vn-button-bar>
</form>

View File

@ -9,9 +9,7 @@ export default class Controller {
};
}
cancel(event) {
event.preventDefault();
event.stopImmediatePropagation();
cancel() {
this.$state.go('client.card.note.index', {id: this.$state.params.id});
}
}

View File

@ -38,6 +38,6 @@
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button ng-click="$ctrl.cancel($event)" label="Cancel"></vn-button>
<vn-button ng-click="$ctrl.cancel()" label="Cancel"></vn-button>
</vn-button-bar>
</form>

View File

@ -9,9 +9,7 @@ class Controller {
};
}
cancel(event) {
event.preventDefault();
event.stopImmediatePropagation();
cancel() {
this.goToIndex();
}

View File

@ -34,7 +34,7 @@
</vn-card>
<vn-button-bar>
<vn-submit label="Send"></vn-submit>
<vn-button label="Preview" ng-click="$ctrl.showPreview($event)"></vn-button>
<vn-button label="Preview" ng-click="$ctrl.showPreview()"></vn-button>
<vn-button ui-sref="client.card.sample.index" label="Cancel"></vn-button>
</vn-button-bar>
</form>

View File

@ -14,9 +14,7 @@ class Controller {
};
}
showPreview(event) {
event.preventDefault();
showPreview() {
let sampleType = this.$scope.sampleType.selection;
let queryParams;

View File

@ -13,6 +13,12 @@ export default class Button extends Input {
event.stopImmediatePropagation();
});
}
$onInit() {
if (!this.type) {
this.type = 'button';
}
}
}
Button.$inject = ['$element'];
@ -22,7 +28,8 @@ ngModule.component('vnButton', {
bindings: {
label: '@?',
disabled: '<?',
icon: '@?'
icon: '@?',
type: '@?'
}
});