arreglado teste del nuevo descriptor para client
This commit is contained in:
parent
3ec5594e71
commit
34953e3a71
|
@ -7,14 +7,8 @@
|
||||||
<vn-auto style="min-width: 18em; padding-left: 1em; padding-bottom: 1em;">
|
<vn-auto style="min-width: 18em; padding-left: 1em; padding-bottom: 1em;">
|
||||||
<vn-descriptor
|
<vn-descriptor
|
||||||
client="$ctrl.client"
|
client="$ctrl.client"
|
||||||
active="$ctrl.client.active"
|
|
||||||
class="display-block" >
|
class="display-block" >
|
||||||
</vn-descriptor>
|
</vn-descriptor>
|
||||||
<vn-new-descriptor
|
|
||||||
client="$ctrl.client"
|
|
||||||
active="$ctrl.client.active"
|
|
||||||
class="display-block" >
|
|
||||||
</vn-new-descriptor>
|
|
||||||
<vn-left-menu></vn-left-menu>
|
<vn-left-menu></vn-left-menu>
|
||||||
</vn-auto>
|
</vn-auto>
|
||||||
<vn-one>
|
<vn-one>
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
<vn-card margin-large-v>
|
<vn-card margin-large-v>
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
<vn-auto class="descriptor-header pointer" ui-sref="clients">
|
<vn-auto class="descriptor-header pointer" ui-sref="clients">
|
||||||
<i class="material-icons" >person</i>
|
<i class="material-icons">person</i>
|
||||||
</vn-auto>
|
</vn-auto>
|
||||||
<vn-auto pad-medium>
|
<vn-auto pad-medium>
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
<vn-horizontal ng-repeat="(field, title) in ::$ctrl.fieldsToShow" ng-if="$ctrl.client[field]">
|
<vn-horizontal ng-repeat="(field, title) in $ctrl.fieldsToShow" ng-if="$ctrl.client[field]">
|
||||||
<strong vn-auto>{{::title}}:</strong>
|
<strong vn-auto>{{::title}}:</strong>
|
||||||
<vn-auto margin-small-left>
|
<vn-auto margin-small-left>
|
||||||
<span ng-if="field.includes('credit')"> {{::$ctrl.client[field] | number:2}} €</span>
|
<span ng-if="field.includes('credit')">{{::$ctrl.client[field] | number:2}} €</span>
|
||||||
<span ng-if="!field.includes('credit')">{{::$ctrl.client[field]}}</span>
|
<span ng-if="!field.includes('credit')">{{::$ctrl.client[field]}}</span>
|
||||||
</vn-auto>
|
</vn-auto>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
|
|
|
@ -2,33 +2,33 @@ import ngModule from '../module';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
export default class Controller {
|
export default class Controller {
|
||||||
constructor($scope, $http, $translate) {
|
constructor($translate) {
|
||||||
this.$http = $http;
|
this.$translate = $translate;
|
||||||
this.fieldsToShow = {
|
// CLient fields to display
|
||||||
id: 'id',
|
this.fields = ['id', 'name', 'phone', 'credit', 'creditInsurance'];
|
||||||
name: $translate.instant('name'),
|
this.fieldsToShow = {};
|
||||||
phone: $translate.instant('phone'),
|
|
||||||
credit: $translate.instant('credit'),
|
|
||||||
creditInsurance: $translate.instant('creditInsurance')
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
set active(value) {
|
|
||||||
if (this._active !== value && this._active !== undefined)
|
|
||||||
this.$http.put(`/client/api/Clients/${this.client.id}/activate`);
|
|
||||||
|
|
||||||
this._active = value;
|
// concat 2 Arrays without duplicates
|
||||||
|
_concatFields(a, b) {
|
||||||
|
return a.concat(b.filter(item => a.indexOf(item) < 0));
|
||||||
}
|
}
|
||||||
get active() {
|
|
||||||
return this._active;
|
$onInit() {
|
||||||
|
let fields = (this.moreFields && this.moreFields instanceof Array) ? this._concatFields(this.fields, this.moreFields) : this.fields;
|
||||||
|
fields.forEach(field => {
|
||||||
|
this.fieldsToShow[field] = this.$translate.instant(field);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Controller.$inject = ['$scope', '$http', '$translate'];
|
Controller.$inject = [
|
||||||
|
'$translate'];
|
||||||
|
|
||||||
ngModule.component('vnDescriptor', {
|
ngModule.component('vnDescriptor', {
|
||||||
template: require('./descriptor.html'),
|
template: require('./descriptor.html'),
|
||||||
controller: Controller,
|
controller: Controller,
|
||||||
bindings: {
|
bindings: {
|
||||||
client: '<',
|
client: '<',
|
||||||
active: '<'
|
moreFields: '<?'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,30 +3,32 @@ import './descriptor.js';
|
||||||
describe('Client', () => {
|
describe('Client', () => {
|
||||||
describe('Component vnDescriptor', () => {
|
describe('Component vnDescriptor', () => {
|
||||||
let $componentController;
|
let $componentController;
|
||||||
let $scope;
|
let $translate;
|
||||||
let controller;
|
let controller;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
angular.mock.module('client');
|
angular.mock.module('client');
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
|
beforeEach(angular.mock.inject((_$componentController_, _$translate_) => {
|
||||||
$componentController = _$componentController_;
|
$componentController = _$componentController_;
|
||||||
$scope = $rootScope.$new();
|
$translate = _$translate_;
|
||||||
controller = $componentController('vnDescriptor', {$scope: $scope});
|
controller = $componentController('vnDescriptor', {$translate: $translate});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('set active', () => {
|
describe('onInit()', () => {
|
||||||
it('should check if active is defined and diferent from the new value', () => {
|
it('should create Object with basic fields', () => {
|
||||||
controller.client = {id: 1};
|
controller.client = {
|
||||||
|
id: 1,
|
||||||
|
name: "Peter Parker",
|
||||||
|
phone: null,
|
||||||
|
mobile: "666666",
|
||||||
|
credit: 300,
|
||||||
|
creditInsurance: null
|
||||||
|
};
|
||||||
|
controller.$onInit();
|
||||||
|
|
||||||
expect(controller._active).toBe(undefined);
|
expect(controller.fieldsToShow.id).toBe('id');
|
||||||
controller.active = false;
|
|
||||||
|
|
||||||
expect(controller._active).toBe(false);
|
|
||||||
controller.active = true;
|
|
||||||
|
|
||||||
expect(controller._active).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue