Skip to content

Commit

Permalink
Add tests for when multiple question types are set as Cru Profile
Browse files Browse the repository at this point in the history
  • Loading branch information
caleballdrin committed Aug 7, 2023
1 parent 9069950 commit c59e3d0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
32 changes: 17 additions & 15 deletions app/scripts/directives/blockEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,19 @@ angular.module('confRegistrationWebApp').directive('blockEditor', function () {
true,
);

var typeToProfile = [];
//typeToProfile['emailQuestion'] = 'EMAIL';
//typeToProfile['nameQuestion'] = 'NAME';
typeToProfile.phoneQuestion = 'PHONE';
typeToProfile.addressQuestion = 'ADDRESS';
typeToProfile.genderQuestion = 'GENDER';
typeToProfile.yearInSchoolQuestion = 'YEAR_IN_SCHOOL';
typeToProfile.birthDateQuestion = 'BIRTH_DATE';
typeToProfile.campusQuestion = 'CAMPUS';
typeToProfile.dormitoryQuestion = 'DORMITORY';
$scope.typeToProfile = [];
//$scope.typeToProfile['emailQuestion'] = 'EMAIL';
//$scope.typeToProfile['nameQuestion'] = 'NAME';
$scope.typeToProfile.phoneQuestion = 'PHONE';
$scope.typeToProfile.addressQuestion = 'ADDRESS';
$scope.typeToProfile.genderQuestion = 'GENDER';
$scope.typeToProfile.yearInSchoolQuestion = 'YEAR_IN_SCHOOL';
$scope.typeToProfile.birthDateQuestion = 'BIRTH_DATE';
$scope.typeToProfile.campusQuestion = 'CAMPUS';
$scope.typeToProfile.dormitoryQuestion = 'DORMITORY';

$scope.profileCheck = !_.isNull($scope.block.profileType);
$scope.profileOption = _.has(typeToProfile, $scope.block.type);
$scope.profileOption = _.has($scope.typeToProfile, $scope.block.type);
$scope.requiredOption = !_.includes(
['paragraphContent'],
$scope.block.type,
Expand Down Expand Up @@ -315,8 +315,8 @@ angular.module('confRegistrationWebApp').directive('blockEditor', function () {
if (!value) {
$scope.block.profileType = null;
} else {
$scope.block.profileType = typeToProfile[$scope.block.type];
var profileCount = 0;
$scope.block.profileType = $scope.typeToProfile[$scope.block.type];
let profileCount = 0;
$scope.conference.registrationPages.forEach(function (page) {
page.blocks.forEach(function (block) {
if ($scope.block.profileType === block.profileType) {
Expand All @@ -325,7 +325,7 @@ angular.module('confRegistrationWebApp').directive('blockEditor', function () {
});
});
if (profileCount > 1) {
const pType =
$scope.pType =
$scope.block.profileType == 'GENDER'
? 'Sex'
: $scope.block.profileType.charAt(0).toUpperCase() +
Expand All @@ -335,7 +335,9 @@ angular.module('confRegistrationWebApp').directive('blockEditor', function () {
.slice(1)
.toLowerCase();
modalMessage.error(
'Only one ' + pType + ' profile block can be used per form.',
'Only one ' +
$scope.pType +
' profile block can be used per form.',
);
$scope.block.profileType = null;
$scope.profileCheck = false;
Expand Down
23 changes: 23 additions & 0 deletions test/spec/directives/blockEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,27 @@ describe('Directive: blockEditor', function () {

expect(scope.block.content.choices[4].operand).toBe('OR');
});

it('should not create an error message if there are not multiple questions with the same Cru Profile type', function () {
const block = _.find(testData.conference.registrationPages[1].blocks, {
id: '9b83eebd-b064-4edf-92d0-7982a330272b',
});
scope.block = block;
scope.block.profileType = null;

scope.toggleProfileType(true);

expect(scope.pType).toBeUndefined();
});

it('Duplicate Cru Profile Gender Question: Changes gender to sex in error message', function () {
const block = _.find(testData.conference.registrationPages[1].blocks, {
id: '9b83eebd-b064-4edf-92d0-7982a330272a',
});
scope.block = block;

scope.toggleProfileType(true);

expect(scope.pType).toBe('Sex');
});
});
13 changes: 13 additions & 0 deletions test/spec/testData.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,19 @@ angular.module('confRegistrationWebApp').service('testData', function () {
},
],
},
{
id: '9b83eebd-b064-4edf-92d0-7982a330272b',
pageId: '7b4c19df-7377-4d37-90fb-5b262bb66d1a',
title: 'Sex',
exportFieldTitle: null,
type: 'genderQuestion',
required: false,
position: 9,
content: '',
profileType: 'GENDER',
registrantTypes: [],
rules: [],
},
{
adminOnly: 'false',
content: {
Expand Down

0 comments on commit c59e3d0

Please sign in to comment.