diff --git a/client/src/templates/Challenges/utils/fetch-all-curriculum-data.tsx b/client/src/templates/Challenges/utils/fetch-all-curriculum-data.tsx index ae60bc57e7c..9022f8cd9c5 100644 --- a/client/src/templates/Challenges/utils/fetch-all-curriculum-data.tsx +++ b/client/src/templates/Challenges/utils/fetch-all-curriculum-data.tsx @@ -33,6 +33,7 @@ export function useFetchAllCurriculumData(): void { nodes { challenge { block + certification id } } diff --git a/client/src/utils/get-completion-percentage.test.ts b/client/src/utils/get-completion-percentage.test.ts index 52de58a8b05..cd6520a165d 100644 --- a/client/src/utils/get-completion-percentage.test.ts +++ b/client/src/utils/get-completion-percentage.test.ts @@ -274,5 +274,56 @@ describe('get-completion-percentage', () => { expect(result).toEqual([]); }); + + it('only counts challenges from the current superblock when a block is shared across superblocks', () => { + // This tests the fix for the bug where blocks shared between superblocks + // (e.g. javascript-v9 and introduction-to-variables-and-strings-in-javascript) + // caused currentBlockIds.length to be doubled, making the progress bar + // show 7% instead of 14% for 1/7 challenges. + const allChallengesInfo: AllChallengesInfo = { + challengeNodes: [ + // Challenges from the current superblock (javascript-v9) + { + challenge: { + id: 'challenge-1', + block: 'workshop-greeting-bot', + certification: Certification.JsV9 + } + } as Partial as ChallengeNode, + { + challenge: { + id: 'challenge-2', + block: 'workshop-greeting-bot', + certification: Certification.JsV9 + } + } as Partial as ChallengeNode, + // Same block, but from a different superblock — should be excluded + { + challenge: { + id: 'challenge-1', + block: 'workshop-greeting-bot', + certification: Certification.RespWebDesignV9 + } + } as Partial as ChallengeNode, + { + challenge: { + id: 'challenge-2', + block: 'workshop-greeting-bot', + certification: Certification.RespWebDesignV9 + } + } as Partial as ChallengeNode + ], + certificateNodes: [] + }; + + const result = getCurrentBlockIds( + allChallengesInfo, + 'workshop-greeting-bot', + Certification.JsV9, + challengeTypes.step + ); + + expect(result).toEqual(['challenge-1', 'challenge-2']); + }); }); }); diff --git a/client/src/utils/get-completion-percentage.ts b/client/src/utils/get-completion-percentage.ts index f6210449063..a9a8e47d534 100644 --- a/client/src/utils/get-completion-percentage.ts +++ b/client/src/utils/get-completion-percentage.ts @@ -46,7 +46,11 @@ export const getCurrentBlockIds = ( .filter(node => node.challenge.certification === certification)[0] ?.challenge.tests.map(test => test.id) ?? []; const currentBlockIds = challengeNodes - .filter(node => node.challenge.block === block) + .filter( + node => + node.challenge.block === block && + node.challenge.certification === certification + ) .map(node => node.challenge.id); if (isProjectBased(challengeType)) {