arreglado teste del nuevo descriptor para client

This commit is contained in:
Daniel Herrero 2017-12-14 12:43:28 +01:00
parent 3ec5594e71
commit 34953e3a71
4 changed files with 36 additions and 40 deletions

View File

@ -7,14 +7,8 @@
<vn-auto style="min-width: 18em; padding-left: 1em; padding-bottom: 1em;">
<vn-descriptor
client="$ctrl.client"
active="$ctrl.client.active"
class="display-block" >
</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-auto>
<vn-one>

View File

@ -1,14 +1,14 @@
<vn-card margin-large-v>
<vn-vertical>
<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 pad-medium>
<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>
<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>
</vn-auto>
</vn-horizontal>

View File

@ -2,33 +2,33 @@ import ngModule from '../module';
import './style.scss';
export default class Controller {
constructor($scope, $http, $translate) {
this.$http = $http;
this.fieldsToShow = {
id: 'id',
name: $translate.instant('name'),
phone: $translate.instant('phone'),
credit: $translate.instant('credit'),
creditInsurance: $translate.instant('creditInsurance')
};
constructor($translate) {
this.$translate = $translate;
// CLient fields to display
this.fields = ['id', 'name', 'phone', 'credit', 'creditInsurance'];
this.fieldsToShow = {};
}
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', {
template: require('./descriptor.html'),
controller: Controller,
bindings: {
client: '<',
active: '<'
moreFields: '<?'
}
});

View File

@ -3,30 +3,32 @@ import './descriptor.js';
describe('Client', () => {
describe('Component vnDescriptor', () => {
let $componentController;
let $scope;
let $translate;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
beforeEach(angular.mock.inject((_$componentController_, _$translate_) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
controller = $componentController('vnDescriptor', {$scope: $scope});
$translate = _$translate_;
controller = $componentController('vnDescriptor', {$translate: $translate});
}));
describe('set active', () => {
it('should check if active is defined and diferent from the new value', () => {
controller.client = {id: 1};
describe('onInit()', () => {
it('should create Object with basic fields', () => {
controller.client = {
id: 1,
name: "Peter Parker",
phone: null,
mobile: "666666",
credit: 300,
creditInsurance: null
};
controller.$onInit();
expect(controller._active).toBe(undefined);
controller.active = false;
expect(controller._active).toBe(false);
controller.active = true;
expect(controller._active).toBe(true);
expect(controller.fieldsToShow.id).toBe('id');
});
});
});