Fix broken column-sort toggles, add unit test coverage for column-sort toggles, #4268 (#4281)

This commit is contained in:
Leigh Johnson
2016-12-08 15:21:52 -05:00
committed by GitHub
parent 26adcf5972
commit c30ac365c3
4 changed files with 113 additions and 11 deletions
@@ -0,0 +1,101 @@
'use strict';
describe('Directive: column-sort', () =>{
let $scope, template, $compile, QuerySet, GetBasePath;
beforeEach(angular.mock.module('templateUrl'));
beforeEach(function(){
this.mock = {
dataset: [
{name: 'zero', idx: 0},
{name: 'one', idx: 1},
{name: 'two', idx: 2}
]
};
this.name_field = angular.element(`<column-sort
collection="mock"
dataset="mock.dataset"
base-path="mock"
column-iterator="mock"
column-field="name"
column-label="Name">
</column-sort>`);
this.idx_field = angular.element(`<column-sort
collection="mock"
dataset="mock.dataset"
base-path="mock"
column-iterator="mock"
column-field="idx"
column-label="Index">
</column-sort>`);
this.$state = {
params: {},
go: jasmine.createSpy('go')
};
angular.mock.module('ColumnSortModule', ($provide) =>{
QuerySet = jasmine.createSpyObj('qs', ['search']);
QuerySet.search.and.callFake(() => { return { then: function(){} } });
GetBasePath = jasmine.createSpy('GetBasePath');
$provide.value('QuerySet', QuerySet);
$provide.value('GetBasePath', GetBasePath);
$provide.value('$state', this.$state);
});
});
beforeEach(angular.mock.inject(($templateCache, _$rootScope_, _$compile_) => {
template = window.__html__['client/src/shared/column-sort/column-sort.partial.html'];
$templateCache.put('/static/partials/shared/column-sort/column-sort.partial.html', template);
$compile = _$compile_;
$scope = _$rootScope_.$new();
}));
it('should be ordered by name', function(){
this.$state.params = {
mock_search: {order_by: 'name'}
};
$compile(this.name_field)($scope);
$compile(this.idx_field)($scope)
$scope.$digest();
expect( $(this.name_field).find('.columnSortIcon').hasClass('fa-sort-up') ).toEqual(true);
expect( $(this.idx_field).find('.columnSortIcon').hasClass('fa-sort') ).toEqual(true);
});
it('should toggle to ascending name order, then ascending idx, then descending idx', function(){
this.$state.params = {
mock_search: {order_by: 'idx'}
};
$compile(this.name_field)($scope);
$compile(this.idx_field)($scope)
$scope.$digest();
$(this.name_field).click();
expect( $(this.name_field).find('.columnSortIcon').hasClass('fa-sort-up') ).toEqual(true);
expect( $(this.idx_field).find('.columnSortIcon').hasClass('fa-sort') ).toEqual(true);
$(this.idx_field).click();
expect( $(this.name_field).find('.columnSortIcon').hasClass('fa-sort') ).toEqual(true);
expect( $(this.idx_field).find('.columnSortIcon').hasClass('fa-sort-up') ).toEqual(true);
$(this.idx_field).click();
expect( $(this.name_field).find('.columnSortIcon').hasClass('fa-sort') ).toEqual(true);
expect( $(this.idx_field).find('.columnSortIcon').hasClass('fa-sort-down') ).toEqual(true)
});
});