Skip to content

Commit

Permalink
Merge pull request #851 from CruGlobal/test-coverage
Browse files Browse the repository at this point in the history
[no-Jira] Improve test coverage
  • Loading branch information
canac authored Jan 11, 2024
2 parents 6498e2e + 6479121 commit 9fc9ce2
Show file tree
Hide file tree
Showing 7 changed files with 1,183 additions and 100 deletions.
40 changes: 20 additions & 20 deletions app/scripts/controllers/eventForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ angular
function (
$rootScope,
$scope,
$uibModal,
modalMessage,
$location,
$anchorScroll,
Expand Down Expand Up @@ -46,14 +45,13 @@ angular
var formSavingNotifyTimeout;

function saveForm() {
$timeout.cancel(formSavingTimeout);
if (formSaving) {
$timeout.cancel(formSavingTimeout);
formSavingTimeout = $timeout(function () {
saveForm();
}, 600);
return;
}
$timeout.cancel(formSavingTimeout);

formSaving = true;
let conferenceWithoutImage = angular.copy($scope.conference);
Expand Down Expand Up @@ -210,28 +208,29 @@ angular
});
};

var makePositionArray = function () {
var tempPositionArray = [];
// Generate a map of blockIds to their page and index within the page
var makeBlockPositionMap = function () {
var positionMap = {};
$scope.conference.registrationPages.forEach(function (page, pageIndex) {
page.blocks.forEach(function (block, blockIndex) {
tempPositionArray[block.id] = {
page: pageIndex,
block: blockIndex,
positionMap[block.id] = {
pageIndex,
blockIndex,
};
});
});
return tempPositionArray;
return positionMap;
};

$scope.copyBlock = function (blockId) {
var tempPositionArray = makePositionArray();
var origPageIndex = tempPositionArray[blockId].page;
var previousBlockPositions = makeBlockPositionMap();
var origPageIndex = previousBlockPositions[blockId].pageIndex;
var newBlock = angular.copy(
$scope.conference.registrationPages[origPageIndex].blocks[
tempPositionArray[blockId].block
previousBlockPositions[blockId].blockIndex
],
);
var newPosition = tempPositionArray[blockId].block + 1;
var newPosition = previousBlockPositions[blockId].blockIndex + 1;
newBlock.id = uuid();
newBlock.profileType = null;
newBlock.position = newPosition;
Expand Down Expand Up @@ -264,6 +263,7 @@ angular

var profileType = null;
if (angular.isDefined(defaultProfile)) {
// Check whether a block with this profile type exists already on any page
var profileCount = 0;
$scope.conference.registrationPages.forEach(function (page) {
page.blocks.forEach(function (block) {
Expand Down Expand Up @@ -329,20 +329,20 @@ angular
return;
}

var previousBlockPositions = makeBlockPositionMap();
if (growl) {
var t = makePositionArray();
var block =
$scope.conference.registrationPages[t[blockId].page].blocks[
t[blockId].block
];
$scope.conference.registrationPages[
previousBlockPositions[blockId].pageIndex
].blocks[previousBlockPositions[blockId].blockIndex];
var message = '"' + block.title + '" has been deleted.';
GrowlService.growl($scope, 'conference', $scope.conference, message);
}

var tempPositionArray = makePositionArray();
_.remove(
$scope.conference.registrationPages[tempPositionArray[blockId].page]
.blocks,
$scope.conference.registrationPages[
previousBlockPositions[blockId].pageIndex
].blocks,
{ id: blockId },
);
};
Expand Down
8 changes: 4 additions & 4 deletions app/scripts/controllers/eventRegistrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ angular
});

//turn on visible blocks
var visibleBlocks = localStorage.getItem(
var visibleBlocks = $window.localStorage.getItem(
'visibleBlocks:' + conference.id,
);
if (!_.isNull(visibleBlocks)) {
Expand All @@ -121,15 +121,15 @@ angular
$scope.toggleColumn = function (block) {
$scope.blocks[block].visible = !$scope.blocks[block].visible;
visibleBlocks = _.map(_.filter($scope.blocks, { visible: true }), 'id');
localStorage.setItem(
$window.localStorage.setItem(
'visibleBlocks:' + conference.id,
JSON.stringify(visibleBlocks),
);
$scope.queryParameters.block = visibleBlocks;
};

//turn on visible built in columns
var builtInColumnsVisibleInStorage = localStorage.getItem(
var builtInColumnsVisibleInStorage = $window.localStorage.getItem(
'builtInColumnsVisibleStorage',
);
if (
Expand All @@ -154,7 +154,7 @@ angular
$scope.toggleBuiltInColumn = function (columnName) {
$scope.builtInColumnsVisible[columnName] =
!$scope.builtInColumnsVisible[columnName];
localStorage.setItem(
$window.localStorage.setItem(
'builtInColumnsVisibleStorage',
JSON.stringify($scope.builtInColumnsVisible),
);
Expand Down
49 changes: 20 additions & 29 deletions app/scripts/controllers/reviewRegistration.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,21 @@ angular
);

$scope.blocks = [];
$scope.regValidate = [];
$scope.regValidate = {};

$scope.getRegistrantType = function (id) {
return _.find(conference.registrantTypes, { id });
};

//check if group registration is allowed based on registrants already in registration
if (!_.isEmpty(currentRegistration.registrants)) {
$scope.allowGroupRegistration = false;
angular.forEach(currentRegistration.registrants, function (r) {
if ($scope.allowGroupRegistration) {
return;
}
var regType = getRegistrantType(r.registrantTypeId);
$scope.allowGroupRegistration = regType.allowGroupRegistrations;
});
}
$scope.allowGroupRegistration = currentRegistration.registrants.some(
(registrant) =>
$scope.getRegistrantType(registrant.registrantTypeId)
.allowGroupRegistrations,
);

// TODO: $scope.currentPayment is always undefined and conference.accept* is also undefined
// We need to need to use $scope.acceptedPaymentMethods() to calculate the initial payment type
if (angular.isUndefined($scope.currentPayment)) {
var paymentType;
if (conference.acceptCreditCards) {
Expand Down Expand Up @@ -107,10 +108,10 @@ angular

// Return a boolean indicating whether the register button(s) should be disabled
$scope.registerDisabled = function () {
return (
return Boolean(
$scope.registerMode === 'preview' ||
!$scope.allRegistrantsValid() ||
$scope.submittingRegistration
!$scope.allRegistrantsValid() ||
$scope.submittingRegistration,
);
};

Expand All @@ -128,17 +129,11 @@ angular
});
}

function getRegistrantType(typeId) {
return _.find(conference.registrantTypes, {
id: typeId,
});
}

function primaryRegType(currentRegistration) {
let primaryRegistrant = _.find(currentRegistration.registrants, {
id: currentRegistration.primaryRegistrantId,
});
return getRegistrantType(primaryRegistrant.registrantTypeId);
return $scope.getRegistrantType(primaryRegistrant.registrantTypeId);
}

// Navigate to the correct page after completing a registration
Expand Down Expand Up @@ -204,12 +199,12 @@ angular
};

$scope.pageIsVisible = (page, registrantId) =>
page.blocks.filter((block) =>
page.blocks.some((block) =>
validateRegistrant.blockVisible(
block,
currentRegistration.registrants.find((r) => r.id === registrantId),
),
).length > 0;
);

$scope.removeRegistrant = function (id) {
modalMessage
Expand All @@ -236,10 +231,6 @@ angular
});
};

$scope.getRegistrantType = function (id) {
return _.find(conference.registrantTypes, { id: id });
};

$scope.isBlockInvalid = function (rId, bId) {
return _.includes($scope.regValidate[rId], bId);
};
Expand Down Expand Up @@ -301,15 +292,15 @@ angular
var groupRegistrants = 0,
noGroupRegistrants = 0;
angular.forEach(currentRegistration.registrants, function (r) {
var regType = getRegistrantType(r.registrantTypeId);
var regType = $scope.getRegistrantType(r.registrantTypeId);
if (regType.allowGroupRegistrations) {
groupRegistrants++;
} else {
noGroupRegistrants++;
}
});

var regType = getRegistrantType(r.registrantTypeId);
var regType = $scope.getRegistrantType(r.registrantTypeId);
if (
regType.allowGroupRegistrations &&
groupRegistrants === 1 &&
Expand Down
Loading

0 comments on commit 9fc9ce2

Please sign in to comment.