docker-registry-frontend/app/app.spec.js
Marc Abramowitz 3ad864b388 Handle images with no user properly (#147)
* Uncomment test for no repositoryUser

in `app/app.spec.js`, so I can work on getting this case working.

* Add $log to repository-detail-controller

* Set $scope.repository properly even if no user

Check if `$scope.repositoryUser` is defined and if it's not, set
`$scope.repository` simply to `$scope.repositoryName`.

* Add route for repo with no repositoryUser

* Make tagsPerPage dropdown use query string vars

instead of putting `tagsPerPage` in the route part of the URL, which
makes it difficult to distinguish between `repositoryName` and
`tagsPerPage`, because the routes are too similar.

* Make first/next links use query string vars

instead of putting `tagsPerPage` in the route part of the URL, which
makes it difficult to distinguish between `repositoryName` and
`tagsPerPage`, because the routes are too similar.

* Move defaultTagsPerPage

from `RepositoryListController` to `TagController`.

I think it makes more sense to read `defaultTagsPerPage` in
`TagController` than to do it in `RepositoryListController` and have to
pass it in URLs.

* Fix "Details for repository" for repo w/ no user

* Fix breadcrumb when no repositoryUser

* Remove tagsPerPage/tagPage from repo detail routes

* Update unit tests to use tagsPerPage qs param

Updated the unit tests to page `tagsPerPage` as a query string parameter
rather than in the route.

* Uncomment assertions about scope.reposPerPage

an make them work by casting string to an int with `parseInt`.

* Make /tag work for image with no repositoryUser

* repository-detail.html: Fix breadcrumb link

for case when there is no `repositoryUser`.

* tag-detail.html: Fix breadcrumb link

when image has no `repositoryUser`.

* tag-detail.html: Fix shown docker pull command

when image has no `repositoryUser`.

* tag-detail.html: Show docker pull cmd in code font

I think it looks better.
2016-08-04 17:16:32 +02:00

170 lines
7.3 KiB
JavaScript

'use strict';
describe('docker-registry-frontend', function() {
var $route, $location, $rootScope, $httpBackend, $controller;
beforeEach(module('docker-registry-frontend'));
beforeEach(inject(function(_$route_, _$location_, _$rootScope_, _$httpBackend_, _$controller_) {
$route = _$route_;
$location = _$location_;
$rootScope = _$rootScope_;
$httpBackend = _$httpBackend_;
$controller = _$controller_;
}));
it('/home should display home page', function() {
$httpBackend.expectGET('home.html').respond(200);
$location.path('/home');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('home.html');
expect($route.current.controller).toBe('HomeController');
var scope = {};
var expectedAppMode = {
"browseOnly": true,
"defaultRepositoriesPerPage": 20,
"defaultTagsPerPage": 10
}
$controller('HomeController', {$scope: scope});
$httpBackend.expectGET('/app-mode.json').respond(expectedAppMode);
$httpBackend.flush();
jasmine.addCustomEqualityTester(angular.equals);
expect(scope.appMode).toEqual(expectedAppMode);
});
it('/repositories should display repository list page', function() {
$httpBackend.expectGET('repository/repository-list.html').respond(200);
$location.path('/repositories');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('repository/repository-list.html');
expect($route.current.controller).toBe('RepositoryListController');
var scope = {};
$controller('RepositoryListController', {$scope: scope});
expect(scope.reposPerPage).toBeUndefined();
});
it('/repositories/10 should display repository list page', function() {
$httpBackend.expectGET('repository/repository-list.html').respond(200);
$location.path('/repositories/10');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('repository/repository-list.html');
expect($route.current.controller).toBe('RepositoryListController');
var scope = {};
$controller('RepositoryListController', {$scope: scope});
expect(scope.reposPerPage).toBe(10);
});
it('/repositories/20 should display repository list page', function() {
$httpBackend.expectGET('repository/repository-list.html').respond(200);
$location.path('/repositories/20');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('repository/repository-list.html');
expect($route.current.controller).toBe('RepositoryListController');
var scope = {};
$controller('RepositoryListController', {$scope: scope});
expect(scope.reposPerPage).toBe(20);
});
it('URL with repositoryUser and repositoryName and no tagsPerPage should display repository detail page', function() {
$httpBackend.expectGET('repository/repository-detail.html').respond(200);
$location.path('/repository/owner/name');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('repository/repository-detail.html');
expect($route.current.controller).toBe('RepositoryDetailController');
var scope = {};
$controller('RepositoryDetailController', {$scope: scope});
expect(scope.repositoryUser).toBe('owner');
expect(scope.repositoryName).toBe('name');
expect(scope.repository).toBe('owner/name');
expect(scope.maxTagsPage).toBeUndefined();
});
it('URL with repositoryUser and repositoryName and tagsPerPage should display repository detail page', function() {
$httpBackend.expectGET('repository/repository-detail.html').respond(200);
$location.path('/repository/owner/name');
$location.search('tagsPerPage', 10)
$rootScope.$digest();
expect($route.current.templateUrl).toBe('repository/repository-detail.html');
expect($route.current.controller).toBe('RepositoryDetailController');
var scope = {};
$controller('RepositoryDetailController', {$scope: scope});
expect(scope.repositoryUser).toBe('owner');
expect(scope.repositoryName).toBe('name');
expect(scope.repository).toBe('owner/name');
});
it('URL with repositoryName but no repositoryUser and no tagsPerPage should display repository detail page', function() {
$httpBackend.expectGET('repository/repository-detail.html').respond(200);
$location.path('/repository/cx');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('repository/repository-detail.html');
expect($route.current.controller).toBe('RepositoryDetailController');
});
it('URL with repositoryName but no repositoryUser and tagsPerPage should display repository detail page', function() {
$httpBackend.expectGET('repository/repository-detail.html').respond(200);
$location.path('/repository/cx');
$location.search('tagsPerPage', 10)
$rootScope.$digest();
expect($route.current.templateUrl).toBe('repository/repository-detail.html');
expect($route.current.controller).toBe('RepositoryDetailController');
var scope = {};
$controller('RepositoryDetailController', {$scope: scope});
expect(scope.repositoryUser).toBeUndefined();
expect(scope.repositoryName).toBe('cx');
expect(scope.repository).toBe('cx');
});
it('/about should display about page', function() {
$httpBackend.expectGET('about.html').respond(200);
$location.path('/about');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('about.html');
});
it('/tag/repositoryUser/repositoryName/latest should display tag detail page', function() {
$httpBackend.expectGET('tag/tag-detail.html').respond(200);
$location.path('/tag/repositoryUser/repositoryName/latest');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('tag/tag-detail.html');
expect($route.current.controller).toBe('TagController');
var scope = {};
$controller('TagController', {$scope: scope});
expect(scope.repositoryUser).toBe('repositoryUser');
expect(scope.repositoryName).toBe('repositoryName');
expect(scope.repository).toBe('repositoryUser/repositoryName');
expect(scope.tagName).toBe('latest');
});
it('/tag/repositoryName/latest should display tag detail page', function() {
$httpBackend.expectGET('tag/tag-detail.html').respond(200);
$location.path('/tag/repositoryName/latest');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('tag/tag-detail.html');
expect($route.current.controller).toBe('TagController');
});
it('/image/88e37c7099fa should display image detail page', function() {
$httpBackend.expectGET('tag/image-detail.html').respond(200);
$location.path('/image/88e37c7099fa');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('tag/image-detail.html');
expect($route.current.controller).toBe('ImageController');
});
it('/image/88e37c7099fa/tag should display create tag page', function() {
$httpBackend.expectGET('tag/create-tag.html').respond(200);
$location.path('/image/88e37c7099fa/tag');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('tag/create-tag.html');
expect($route.current.controller).toBe('CreateTagController');
});
it('/unknown-url should display home page', function() {
$httpBackend.expectGET('home.html').respond(200);
$location.path('/unknown-url');
$rootScope.$digest();
expect($route.current.templateUrl).toBe('home.html');
expect($route.current.controller).toBe('HomeController');
});
});