Skip to content

Commit

Permalink
CPS-356: Refactor refresh roles
Browse files Browse the repository at this point in the history
  • Loading branch information
deb1990 committed Feb 25, 2021
1 parent caa75de commit e284964
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 228 deletions.
83 changes: 0 additions & 83 deletions ang/civicase-base/directives/send-to-api-on-change.directive.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ <h3>{{ ts('%1 Contacts', {1: roles.getCountOfAssignedRoles()}) }}</h3>
class="form-control"
civicase-inline-datepicker
data-max-date="{{role.relationship.end_date}}"
civicase-send-to-api-on-change
data-api-data="roleDatesUpdater.getApiCallsForStartDate(role, item.id)"
data-on-api-data-sent="roleDatesUpdater.updatePreviousValue(role, 'start_date', refresh)"
ng-change="refresh(roleDatesUpdater.getApiCallsForStartDate(role, item.id))"
name="role_start_date"
ng-disabled="roleForm.role_start_date.isSaving"
ng-if="!!role.relationship"
Expand All @@ -175,9 +173,7 @@ <h3>{{ ts('%1 Contacts', {1: roles.getCountOfAssignedRoles()}) }}</h3>
class="form-control"
civicase-inline-datepicker
data-min-date="{{role.relationship.start_date}}"
civicase-send-to-api-on-change
data-api-data="roleDatesUpdater.getApiCallsForEndDate(role, item.id)"
data-on-api-data-sent="roleDatesUpdater.updatePreviousValue(role, 'end_date', refresh)"
ng-change="refresh(roleDatesUpdater.getApiCallsForEndDate(role, item.id))"
name="role_end_date"
ng-disabled="roleForm.role_end_date.isSaving"
ng-if="!!role.relationship"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

this.getApiCallsForEndDate = getApiCallsForEndDate;
this.getApiCallsForStartDate = getApiCallsForStartDate;
this.updatePreviousValue = updatePreviousValue;

/**
* @param {string} dateString A date in a year-month-day format.
Expand Down Expand Up @@ -130,20 +129,6 @@
.value();
}

/**
* Stores the current value of the role's relationship in the previous
* values object. Useful for storing the relationship date changes.
*
* @param {object} role A role object as provided by the roles service.
* @param {string} fieldName The name of the field to store.
* @param {Function} callbackFn call back function to be called.
*/
function updatePreviousValue (role, fieldName, callbackFn) {
role.previousValues[fieldName] = role.relationship[fieldName];

callbackFn && callbackFn();
}

/**
* @typedef {object} RoleDateChangeParams
* @param {string} activityTypeId Name of the activity type that will
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -147,43 +147,5 @@
]));
});
});

describe('when updating the previous end date value', () => {
var callbackFn;

beforeEach(() => {
callbackFn = jasmine.createSpy('callbackFn');
roleData.relationship.end_date = '2000-12-31';

roleDatesUpdater.updatePreviousValue(roleData, 'end_date', callbackFn);
});

it('updates the previous end date value', () => {
expect(roleData.previousValues.end_date).toBe('2000-12-31');
});

it('calls the callback function', () => {
expect(callbackFn).toHaveBeenCalled();
});
});

describe('when updating the previous start date value', () => {
var callbackFn;

beforeEach(() => {
callbackFn = jasmine.createSpy('callbackFn');
roleData.relationship.start_date = '2000-01-31';

roleDatesUpdater.updatePreviousValue(roleData, 'start_date', callbackFn);
});

it('updates the previous start date value', () => {
expect(roleData.previousValues.start_date).toBe('2000-01-31');
});

it('calls the callback function', () => {
expect(callbackFn).toHaveBeenCalled();
});
});
});
})(CRM._);

0 comments on commit e284964

Please sign in to comment.