Transfer table should update allocatedIds on allocated change
Transfer table does a one time allocation for allocatedIds and does not watch changes to allocated. As a result, when the allocated list is fetched at a later point, the allocatedIds are not updated resulting in a broken view. Partially-Implements: blueprint ng-flavors Closes-Bug: #1531334 Change-Id: I807c682b69081f90fc3d74675e8ca149bb855521
This commit is contained in:
parent
1178757445
commit
52fc193d0c
|
@ -100,7 +100,17 @@
|
|||
};
|
||||
|
||||
ctrl.allocatedIds = {};
|
||||
angular.forEach(ctrl.allocated.sourceItems, function(item) {
|
||||
markAllocatedItems();
|
||||
|
||||
$scope.$watchCollection(getAllocated, markAllocatedItems);
|
||||
}
|
||||
|
||||
function getAllocated() {
|
||||
return ctrl.allocated.sourceItems;
|
||||
}
|
||||
|
||||
function markAllocatedItems() {
|
||||
angular.forEach(ctrl.allocated.sourceItems, function flag(item) {
|
||||
ctrl.allocatedIds[item.id] = true;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -23,12 +23,10 @@
|
|||
beforeEach(module('smart-table'));
|
||||
beforeEach(module('horizon.framework'));
|
||||
|
||||
var log, params;
|
||||
var log, params, scope;
|
||||
beforeEach(module(function($provide) {
|
||||
|
||||
// we will mock scope and timeout in this test
|
||||
// because we aren't concern with rendering results
|
||||
var scope = { $apply: angular.noop };
|
||||
var timeout = function(fn) { fn(); };
|
||||
|
||||
// we will mock parse and attrs
|
||||
|
@ -41,16 +39,16 @@
|
|||
};
|
||||
};
|
||||
|
||||
$provide.value('$scope', scope);
|
||||
$provide.value('$timeout', timeout);
|
||||
$provide.value('$parse', parse);
|
||||
$provide.value('$attrs', attrs);
|
||||
$provide.value('$log', log);
|
||||
}));
|
||||
|
||||
beforeEach(inject(function($injector) {
|
||||
beforeEach(inject(function($injector, _$rootScope_) {
|
||||
scope = _$rootScope_.$new();
|
||||
params = {
|
||||
'$scope': $injector.get('$scope'),
|
||||
'$scope': scope,
|
||||
'$timeout': $injector.get('$timeout'),
|
||||
'$parse': $injector.get('$parse'),
|
||||
'$attrs': $injector.get('$attrs'),
|
||||
|
@ -118,6 +116,7 @@
|
|||
it('should swap out allocated item if allocation limit is one', testLimitOne);
|
||||
it('should deallocate by moving item from allocated to available list', testDeallocate);
|
||||
it('should update allocated on reorder', testUpdateAllocated);
|
||||
it('should update allocatedIds if allocated change', testAllocatedIds);
|
||||
it('should toggle the views correctly on request', testToggleView);
|
||||
|
||||
//////////
|
||||
|
@ -186,6 +185,15 @@
|
|||
expect(trCtrl.numAvailable()).toEqual(1);
|
||||
}
|
||||
|
||||
function testAllocatedIds() {
|
||||
expect(trCtrl.allocatedIds).toEqual({});
|
||||
|
||||
trCtrl.allocated.sourceItems = [{id: 1}, {id: 2}];
|
||||
scope.$apply();
|
||||
|
||||
expect(trCtrl.allocatedIds).toEqual({1: true, 2: true});
|
||||
}
|
||||
|
||||
function testUpdateAllocated() {
|
||||
var orderedItems = [1,2,3,4];
|
||||
trCtrl.updateAllocated(null, null, orderedItems);
|
||||
|
|
Loading…
Reference in New Issue