Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no-Jira] Improve test coverage #851

Merged
merged 5 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
function (
$rootScope,
$scope,
$uibModal,
modalMessage,
$location,
$anchorScroll,
Expand Down Expand Up @@ -46,14 +45,13 @@
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 @@
});
};

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 @@

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 @@
return;
}

var previousBlockPositions = makeBlockPositionMap();

Check warning on line 332 in app/scripts/controllers/eventForm.js

View check run for this annotation

Codecov / codecov/patch

app/scripts/controllers/eventForm.js#L332

Added line #L332 was not covered by tests
if (growl) {
var t = makePositionArray();
var block =
$scope.conference.registrationPages[t[blockId].page].blocks[
t[blockId].block
];
$scope.conference.registrationPages[

Check warning on line 335 in app/scripts/controllers/eventForm.js

View check run for this annotation

Codecov / codecov/patch

app/scripts/controllers/eventForm.js#L335

Added line #L335 was not covered by tests
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
Loading