forked from kwk/docker-registry-frontend
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change set adds tests for the new tag sorting by date feature. It changed the syntax for the query of tags a bit to use the .then() api vs. passing the handler function as a second parameter to the query() api as that just made writing the test easier and more _promisy_
- Loading branch information
Brad van der Laan
committed
Jun 11, 2018
1 parent
a3dc62b
commit 637e716
Showing
2 changed files
with
90 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict'; | ||
|
||
function buildRoute() { | ||
return { | ||
current: { | ||
params: { | ||
repositoryName: 'nginx', | ||
tagName: 'latest', | ||
tagsPerPage: 10, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
function mockTagService($q) { | ||
var mockTagReturnValue = []; | ||
var mockTag = { query: null }; | ||
spyOn(mockTag, 'query').and.returnValue({$promise: $q.when(mockTagReturnValue)}); | ||
|
||
return mockTag; | ||
} | ||
|
||
function mockAppMode($httpBackend) { | ||
var expectedAppMode = {"browseOnly": true, "defaultRepositoriesPerPage": 20, "defaultTagsPerPage": 10}; | ||
$httpBackend.expectGET('app-mode.json').respond(expectedAppMode); | ||
} | ||
|
||
describe('TagController', function() { | ||
|
||
// load the controller's module | ||
beforeEach(module('tag-controller')); | ||
|
||
var $controller, $httpBackend, $q, $rootScope; | ||
|
||
beforeEach(inject(function(_$controller_, _$httpBackend_, _$q_, _$rootScope_) { | ||
$controller = _$controller_; | ||
$httpBackend = _$httpBackend_; | ||
$q = _$q_; | ||
$rootScope = _$rootScope_; | ||
})); | ||
|
||
describe('Sorting', function() { | ||
it('should sort tags Ascending', function() { | ||
var $scope = $rootScope.$new(); | ||
var route = buildRoute(); | ||
var mockTag = mockTagService($q); | ||
mockAppMode($httpBackend); | ||
|
||
var ctrl = $controller('TagController', {$scope: $scope, $route: route, Tag: mockTag}); | ||
// $httpBackend.flush(); | ||
$scope.displayedTags = [{ | ||
name: 'aaa', | ||
details: { | ||
created: '2015-03-25', | ||
}, | ||
}, { | ||
name: 'bbb', | ||
details: { | ||
created: '2015-03-20', | ||
}, | ||
}]; | ||
expect($scope.orderByCreated).toBeTruthy(); | ||
|
||
$scope.sortTags(); | ||
expect($scope.displayedTags).toEqual([{ | ||
name: 'bbb', | ||
details: { | ||
created: '2015-03-20', | ||
}, | ||
}, { | ||
name: 'aaa', | ||
details: { | ||
created: '2015-03-25', | ||
}, | ||
}]); | ||
expect($scope.orderByCreated).toBeFalsy(); | ||
}); | ||
}); | ||
}); | ||
|