Skip to content

Commit

Permalink
ref(angular-dashboard-framework#294) readColumns() return wrong colum…
Browse files Browse the repository at this point in the history
…n size when a column has rows

Details:
- Fixed the readColumns function by filtering out columns with structuring purpose
- Expose readColumns in the scope in order to be testable
- New test case
  • Loading branch information
samuelwang48 committed Dec 8, 2016
1 parent 86714bb commit d884dc9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/scripts/directives/adf-dashboard.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ angular.module('adf')
if (angular.isDefined(root.rows)) {
angular.forEach(root.rows, function (row) {
angular.forEach(row.columns, function (col) {
columns.push(col);
if (!col.hasOwnProperty('rows')) {
columns.push(col);
}
// keep reading columns until we can't any more
readColumns(col, columns);
});
Expand Down Expand Up @@ -330,6 +332,9 @@ angular.module('adf')
$scope.editMode = false;
$scope.editClass = '';

// expose readColumns function in $scope in order to test the interface
$scope.readColumns = readColumns;

//passs translate function from dashboard so we can translate labels inside html templates
$scope.translate = dashboard.translate;

Expand Down
32 changes: 32 additions & 0 deletions test/unit/directives/adf-dashboard.directive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,28 @@ describe('Dashboard Directive tests', function () {
}]
}]
};

dashboard.structures['3-9 (12/6-6)'] = {
rows: [{
columns: [{
styleClass: 'col-md-3'
}, {
styleClass: 'col-md-9',
rows: [{
columns: [{
styleClass: 'col-md-12'
}]
}, {
columns: [{
styleClass: 'col-md-6'
}, {
styleClass: 'col-md-6'
}]
}]
}]
}]
};

});

it('should change the dashboard structure', function(){
Expand All @@ -439,6 +461,16 @@ describe('Dashboard Directive tests', function () {
expect($scope.model.rows[0].columns.length).toBe(1);
});

it('should read the correct number of columns in a structure', function(){
var element = compileTemplate(directive);
var isolatedScope = element.isolateScope();

isolatedScope.editDashboardDialog();
$uibModal.opts.scope.changeStructure('3-9 (12/6-6)', dashboard.structures['3-9 (12/6-6)']);

expect(isolatedScope.readColumns($scope.model).length).toBe(4);
});

it('should change the dashboard structure and move widgets', function(){
$scope.model.rows[0].columns[0].widgets.push({
type: 'one'
Expand Down

0 comments on commit d884dc9

Please sign in to comment.