Skip to content
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
5 changes: 4 additions & 1 deletion src/composables/useGoalData.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ export default function useGoalData({ apollo } = {}) {
const string = `Support ${remaining} more ${categoryHeader} to reach your goal`;
const encodedHeader = encodeURIComponent(string);
const loanFindingUrl = getLoanFindingUrl(categoryId, router.currentRoute.value);
return `${loanFindingUrl}?header=${encodedHeader}`;
if (remaining > 0) {
return `${loanFindingUrl}?header=${encodedHeader}`;
}
return `${loanFindingUrl}`;
}

/**
Expand Down
36 changes: 5 additions & 31 deletions test/unit/specs/composables/useGoalData.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1920,32 +1920,6 @@ describe('useGoalData', () => {
expect(href).toBe(expectedHref);
});

it('should return 0 remaining when currentLoanCount exceeds target', () => {
const selectedGoalNumber = 5;
const categoryId = ID_WOMENS_EQUALITY;
const router = { currentRoute: { value: {} } };
const currentLoanCount = 10; // More than target, should clamp to 0

const href = composable.getCtaHref(selectedGoalNumber, categoryId, router, currentLoanCount);
const expectedString = 'Support 0 more women to reach your goal';
const expectedHref = `/lend/${categoryId}?header=${encodeURIComponent(expectedString)}`;

expect(href).toBe(expectedHref);
});

it('should return 0 remaining when currentLoanCount equals target', () => {
const selectedGoalNumber = 5;
const categoryId = ID_WOMENS_EQUALITY;
const router = { currentRoute: { value: {} } };
const currentLoanCount = 5; // Equals target

const href = composable.getCtaHref(selectedGoalNumber, categoryId, router, currentLoanCount);
const expectedString = 'Support 0 more women to reach your goal';
const expectedHref = `/lend/${categoryId}?header=${encodeURIComponent(expectedString)}`;

expect(href).toBe(expectedHref);
});

it('should handle undefined selectedGoalNumber', () => {
const categoryId = ID_WOMENS_EQUALITY;
const router = { currentRoute: { value: {} } };
Expand All @@ -1956,15 +1930,15 @@ describe('useGoalData', () => {
expect(href).toContain('/lend/');
});

it('should handle zero selectedGoalNumber', () => {
it('should return href without query parameter when remaining is 0', () => {
const selectedGoalNumber = 5;
const categoryId = ID_WOMENS_EQUALITY;
const router = { currentRoute: { value: {} } };
const currentLoanCount = 5; // Equals target

const href = composable.getCtaHref(0, categoryId, router, 0);
const expectedString = 'Support 0 more women to reach your goal';
const expectedHref = `/lend/${categoryId}?header=${encodeURIComponent(expectedString)}`;
const href = composable.getCtaHref(selectedGoalNumber, categoryId, router, currentLoanCount);

expect(href).toBe(expectedHref);
expect(href).toBe(`/lend/${categoryId}`);
});
});

Expand Down
Loading