From bc27d9c759604b6a467af26bc5d3e4f6f4ef83f9 Mon Sep 17 00:00:00 2001 From: Caleb Alldrin Date: Mon, 7 Aug 2023 08:29:08 -0700 Subject: [PATCH] EVENT-822 Change Gender to Sex (#836) Replace Gender with Sex and add tests to Profile Questions --- app/scripts/directives/blockEditor.js | 39 +++++++++++++---------- app/scripts/directives/questionToolbar.js | 4 +-- app/views/components/blockEditor.html | 2 +- languages/ert.pot | 2 +- test/spec/directives/blockEditor.spec.js | 23 +++++++++++++ test/spec/testData.spec.js | 15 ++++++++- 6 files changed, 64 insertions(+), 21 deletions(-) diff --git a/app/scripts/directives/blockEditor.js b/app/scripts/directives/blockEditor.js index 5b4268cfc..860c1f1e8 100644 --- a/app/scripts/directives/blockEditor.js +++ b/app/scripts/directives/blockEditor.js @@ -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, @@ -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) { @@ -325,10 +325,18 @@ angular.module('confRegistrationWebApp').directive('blockEditor', function () { }); }); if (profileCount > 1) { + $scope.pType = + $scope.block.profileType == 'GENDER' + ? 'Sex' + : $scope.block.profileType.charAt(0).toUpperCase() + + $scope.block.profileType + .split('_') + .join(' ') + .slice(1) + .toLowerCase(); modalMessage.error( 'Only one ' + - $scope.block.profileType.charAt(0).toUpperCase() + - $scope.block.profileType.slice(1).toLowerCase() + + $scope.pType + ' profile block can be used per form.', ); $scope.block.profileType = null; @@ -336,7 +344,6 @@ angular.module('confRegistrationWebApp').directive('blockEditor', function () { } } }; - $scope.registrationTypeName = function (id) { if (!id) { return; diff --git a/app/scripts/directives/questionToolbar.js b/app/scripts/directives/questionToolbar.js index 6a72a900d..147d2f793 100644 --- a/app/scripts/directives/questionToolbar.js +++ b/app/scripts/directives/questionToolbar.js @@ -149,10 +149,10 @@ angular }, { id: 'genderQuestion', - defaultTitle: 'Gender', + defaultTitle: 'Sex', defaultProfile: 'GENDER', iconClass: 'fa-male', - name: 'Gender', + name: 'Sex', }, { id: 'yearInSchoolQuestion', diff --git a/app/views/components/blockEditor.html b/app/views/components/blockEditor.html index 1078cbc47..535ede101 100644 --- a/app/views/components/blockEditor.html +++ b/app/views/components/blockEditor.html @@ -450,7 +450,7 @@ Question Rules can depend on questions of these types diff --git a/languages/ert.pot b/languages/ert.pot index 683459bd7..ee7883b8a 100644 --- a/languages/ert.pot +++ b/languages/ert.pot @@ -1392,7 +1392,7 @@ msgid "Move" msgstr "" #: ./app/views/components/blockEditor.html:444 -msgid "Multiple Choice, Dropdown, Number, Date, Gender or Year in School" +msgid "Multiple Choice, Dropdown, Number, Date, Sex or Year in School" msgstr "" #: ./app/scripts/app.config.js:180 diff --git a/test/spec/directives/blockEditor.spec.js b/test/spec/directives/blockEditor.spec.js index b39c0a15d..58127c1de 100644 --- a/test/spec/directives/blockEditor.spec.js +++ b/test/spec/directives/blockEditor.spec.js @@ -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'); + }); }); diff --git a/test/spec/testData.spec.js b/test/spec/testData.spec.js index 48b4ba482..4a6976777 100644 --- a/test/spec/testData.spec.js +++ b/test/spec/testData.spec.js @@ -156,7 +156,7 @@ angular.module('confRegistrationWebApp').service('testData', function () { { id: '9b83eebd-b064-4edf-92d0-7982a330272a', pageId: '7b4c19df-7377-4d37-90fb-5b262bb66d1a', - title: 'Gender', + title: 'Sex', exportFieldTitle: null, type: 'genderQuestion', required: false, @@ -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: {