Skip to content

Commit

Permalink
Add tests for searchCampuses()
Browse files Browse the repository at this point in the history
  • Loading branch information
caleballdrin committed Aug 5, 2023
1 parent 0504c3f commit d7a1708
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/scripts/directives/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ angular
restrict: 'E',
controller: function ($scope, $http) {
$scope.searchCampuses = function (val) {
let params = {
$scope.params = {
limit: 15,
};
params = $scope.block.content.showInternationalCampuses
? Object.assign(params, { includeInternational: true })
: params;
$scope.params = $scope.block.content.showInternationalCampuses
? Object.assign($scope.params, { includeInternational: true })
: $scope.params;
return $http
.get('campuses/' + val, { params: params })
.get('campuses/' + val, { params: $scope.params })
.then(function (campusNames) {
return campusNames.data;
});
Expand Down
28 changes: 28 additions & 0 deletions test/spec/directives/block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,32 @@ describe('Directive: blocks', () => {
expect($scope.answer.value).toBe('Option 1');
});
});

describe('campusQuestion', () => {
let $compile, $rootScope, $scope;
beforeEach(inject((
_$compile_,
_$rootScope_,
_$timeout_,
$templateCache,
) => {
$compile = _$compile_;
$rootScope = _$rootScope_;

$scope = $rootScope.$new();
$templateCache.put('views/blocks/campusQuestion.html', '');
}));

it('searchCampuses params are formed correctly', () => {
$compile('<campus-question></campus-question>')($scope);
$scope.$digest();

$scope.block.content.showInternationalCampuses = true;
$scope.searchCampuses('San');

expect($scope.params.limit).toBeDefined();

expect($scope.params.includeInternational).toBeDefined();
});
});
});

0 comments on commit d7a1708

Please sign in to comment.