worker descriptor refactor

This commit is contained in:
Carlos Jimenez Ruiz 2019-04-25 08:28:23 +02:00
parent 4e5c6ff882
commit e11d33eb27
2 changed files with 15 additions and 15 deletions

View File

@ -11,16 +11,16 @@ class Controller extends Component {
this.worker = null;
}
set userId(id) {
if (id == this._userId) return;
set workerFk(workerFk) {
if (workerFk == this._workerFk) return;
this._userId = id;
this._workerFk = workerFk;
this.worker = null;
this.loadData();
}
get userId() {
return this._userId;
get workerFk() {
return this._workerFk;
}
set quicklinks(value = {}) {
@ -40,7 +40,7 @@ class Controller extends Component {
let query = `api/Workers/findOne`;
let filter = {
where: {
userFk: this._userId
id: this._workerFk
},
include: [
{
@ -88,7 +88,7 @@ ngModule.component('vnWorkerDescriptorPopover', {
template: require('./index.html'),
controller: Controller,
bindings: {
userId: '<',
workerFk: '<',
quicklinks: '<'
}
});

View File

@ -21,23 +21,23 @@ describe('worker Component vnWorkerDescriptorPopover', () => {
describe('workerFk()', () => {
it(`should not apply any changes if the received id is the same stored in _workerFk`, () => {
controller.worker = 'I exist!';
controller._userId = 1;
controller._workerFk = 1;
spyOn(controller, 'loadData');
controller.userId = 1;
controller.workerFk = 1;
expect(controller.worker).toEqual('I exist!');
expect(controller._userId).toEqual(1);
expect(controller._workerFk).toEqual(1);
expect(controller.loadData).not.toHaveBeenCalled();
});
it(`should set the received id into _workerFk, set the worker to null and then call loadData()`, () => {
controller.worker = `Please don't`;
controller._userId = 1;
controller._workerFk = 1;
spyOn(controller, 'loadData');
controller.userId = 999;
controller.workerFk = 999;
expect(controller.worker).toBeNull();
expect(controller._userId).toEqual(999);
expect(controller._workerFk).toEqual(999);
expect(controller.loadData).toHaveBeenCalledWith();
});
});
@ -53,14 +53,14 @@ describe('worker Component vnWorkerDescriptorPopover', () => {
describe('loadData()', () => {
it(`should perform a get query to store the worker data into the controller`, () => {
controller.userId = 1;
controller.workerFk = 1;
controller.canceler = null;
let response = {};
let config = {
filter: {
where: {
userFk: controller.userId
id: controller.workerFk
},
include: [
{