2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-22 18:17:07 +00:00
vinyldns/modules/portal/public/lib/controllers/controller.zones.spec.js

114 lines
4.2 KiB
JavaScript
Raw Normal View History

2018-07-27 10:18:29 -04:00
/*
* Copyright 2018 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
describe('Controller: ZonesController', function () {
beforeEach(function () {
module('ngMock'),
module('service.groups'),
module('service.profile'),
module('service.records'),
module('service.zones'),
module('service.utility'),
module('service.paging'),
module('controller.zones')
});
beforeEach(inject(function ($rootScope, $controller, $q, groupsService, profileService, recordsService, zonesService, utilityService, pagingService) {
this.scope = $rootScope.$new();
this.groupsService = groupsService;
this.zonesService = zonesService;
this.zonesService.q = $q;
this.pagingService = pagingService;
this.scope.myGroups = {};
2022-05-17 13:53:33 -04:00
this.scope.allGroups = {};
2018-07-27 10:18:29 -04:00
this.scope.zones = {};
profileService.getAuthenticatedUserData = function() {
2022-05-20 09:23:37 -04:00
return $q.when({data: {id: "userId"}});
2018-07-27 10:18:29 -04:00
};
2022-06-01 15:01:01 +05:30
groupsService.getGroups = function () {
2018-07-27 10:18:29 -04:00
return $q.when({
data: {
2022-05-20 09:23:37 -04:00
groups: [{id: "all my groups", members: [{id: "userId"}]}]
2018-07-27 10:18:29 -04:00
}
});
};
2022-05-17 13:53:33 -04:00
2018-07-27 10:18:29 -04:00
zonesService.getZones = function() {
return $q.when({
data: {
zones: ["all my zones"]
}
});
};
zonesService.getBackendIds = function() {
return $q.when({
data: ['backend-1', 'backend-2']
});
};
2018-07-27 10:18:29 -04:00
this.controller = $controller('ZonesController', {'$scope': this.scope});
}));
it('test that we properly get users groups when loading ZonesController', function(){
this.scope.$digest();
2022-05-20 09:23:37 -04:00
expect(this.scope.myGroups).toEqual([{id: "all my groups", members: [{id: "userId"}]}]);
2018-07-27 10:18:29 -04:00
});
2019-06-24 17:19:59 -04:00
it('nextPageMyZones should call getZones with the correct parameters', function () {
2018-07-27 10:18:29 -04:00
var getZoneSets = spyOn(this.zonesService, 'getZones')
.and.stub()
.and.returnValue(this.zonesService.q.when(mockZone));
var expectedMaxItems = 100;
var expectedStartFrom = undefined;
var expectedQuery = this.scope.query;
2022-05-12 12:39:29 +05:30
var expectedSearchByAdminGroup = this.scope.searchByAdminGroup;
var expectedignoreAccess = false;
2018-07-27 10:18:29 -04:00
2019-06-24 17:19:59 -04:00
this.scope.nextPageMyZones();
2018-07-27 10:18:29 -04:00
expect(getZoneSets.calls.count()).toBe(1);
expect(getZoneSets.calls.mostRecent().args).toEqual(
2022-05-12 12:39:29 +05:30
[expectedMaxItems, expectedStartFrom, expectedQuery, expectedSearchByAdminGroup, expectedignoreAccess]);
2018-07-27 10:18:29 -04:00
});
2019-06-24 17:19:59 -04:00
it('prevPageMyZones should call getZones with the correct parameters', function () {
2018-07-27 10:18:29 -04:00
var getZoneSets = spyOn(this.zonesService, 'getZones')
.and.stub()
.and.returnValue(this.zonesService.q.when(mockZone));
var expectedMaxItems = 100;
var expectedStartFrom = undefined;
var expectedQuery = this.scope.query;
2022-05-12 12:39:29 +05:30
var expectedSearchByAdminGroup = this.scope.searchByAdminGroup;
var expectedignoreAccess = false;
2018-07-27 10:18:29 -04:00
2019-06-24 17:19:59 -04:00
this.scope.prevPageMyZones();
2018-07-27 10:18:29 -04:00
expect(getZoneSets.calls.count()).toBe(1);
expect(getZoneSets.calls.mostRecent().args).toEqual(
2022-05-12 12:39:29 +05:30
[expectedMaxItems, expectedStartFrom, expectedQuery, expectedSearchByAdminGroup, expectedignoreAccess]);
2018-07-27 10:18:29 -04:00
2019-06-24 17:19:59 -04:00
this.scope.nextPageMyZones();
this.scope.prevPageMyZones();
2018-07-27 10:18:29 -04:00
expect(getZoneSets.calls.count()).toBe(3);
expect(getZoneSets.calls.mostRecent().args).toEqual(
2022-05-12 12:39:29 +05:30
[expectedMaxItems, expectedStartFrom, expectedQuery, expectedSearchByAdminGroup, expectedignoreAccess]);
2018-07-27 10:18:29 -04:00
});
});