Skip to content

Commit

Permalink
Campus question tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caleballdrin committed Nov 9, 2023
1 parent 5c78bdc commit 3fd15e2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
1 change: 0 additions & 1 deletion app/scripts/directives/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ angular
});
};
if ($scope.answer.value) {
$scope.searchingCampuses = true;
$scope.searchCampuses($scope.answer.value).then((data) => {
if (!data.length) {
$scope.answer.value = '';
Expand Down
1 change: 1 addition & 0 deletions app/views/blocks/campusQuestion.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
type="text"
ng-model="answer.value"
placeholder=""
name="campus"
autocomplete="off"
aria-autocomplete="none"
class="form-control"
Expand Down
15 changes: 11 additions & 4 deletions test/spec/directives/block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,18 @@ describe('Directive: blocks', () => {
});

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

$scope = $rootScope.$new();
$templateCache.put('views/blocks/campusQuestion.html', '');
Expand Down Expand Up @@ -201,13 +203,18 @@ describe('Directive: blocks', () => {
});

it('checks the campus database if a answer is present on page load', () => {
expect($scope.searchingCampuses).toBe(undefined);
$httpBackend
.whenGET('campuses/SFSU?includeInternational=true&limit=15')
.respond(() => [200, []]);

$scope.answer = { value: 'SFSU' };
$compile('<campus-question></campus-question>')($scope);
$scope.$digest();

expect($scope.searchingCampuses).toBe(true);
$httpBackend.flush();
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();

expect($scope.answer.value).toBe('');
});
});

Expand Down
12 changes: 11 additions & 1 deletion test/spec/services/validateRegistrant.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('Service: validateRegistrant', function () {
expect(validateRegistrant.validate(conference, registrant).length).toBe(1);
});

it('empty campus name should not be valid', function () {
it('marks an empty campus name as invalid', function () {
const conference = angular.copy(testData.conference);
conference.registrationPages[1].blocks[13].required = true;

Expand All @@ -101,6 +101,16 @@ describe('Service: validateRegistrant', function () {
expect(validateRegistrant.validate(conference, registrant).length).toBe(1);
});

it('doesnt mark as invalid a campusQuestion field that is filled in', function () {
const conference = angular.copy(testData.conference);
conference.registrationPages[1].blocks[13].required = true;

const registrant = angular.copy(testData.registration.registrants[0]);
registrant.answers[12].value = 'San Francisco State University';

expect(validateRegistrant.validate(conference, registrant).length).toBe(0);
});

it('empty address fields should not be valid when missing address1, state, zip or city', function () {
var conference = angular.copy(testData.conference);
conference.registrationPages[1].blocks[7].required = true;
Expand Down

0 comments on commit 3fd15e2

Please sign in to comment.