fix(client): filter challenge nodes by certification to fix progress bar (#67052)

This commit is contained in:
Ragini Pandey
2026-04-23 18:46:37 +05:30
committed by GitHub
parent 49bd5729bf
commit ac3901c983
3 changed files with 57 additions and 1 deletions
@@ -33,6 +33,7 @@ export function useFetchAllCurriculumData(): void {
nodes { nodes {
challenge { challenge {
block block
certification
id id
} }
} }
@@ -274,5 +274,56 @@ describe('get-completion-percentage', () => {
expect(result).toEqual([]); 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<ChallengeNode> as ChallengeNode,
{
challenge: {
id: 'challenge-2',
block: 'workshop-greeting-bot',
certification: Certification.JsV9
}
} as Partial<ChallengeNode> 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<ChallengeNode> as ChallengeNode,
{
challenge: {
id: 'challenge-2',
block: 'workshop-greeting-bot',
certification: Certification.RespWebDesignV9
}
} as Partial<ChallengeNode> as ChallengeNode
],
certificateNodes: []
};
const result = getCurrentBlockIds(
allChallengesInfo,
'workshop-greeting-bot',
Certification.JsV9,
challengeTypes.step
);
expect(result).toEqual(['challenge-1', 'challenge-2']);
});
}); });
}); });
@@ -46,7 +46,11 @@ export const getCurrentBlockIds = (
.filter(node => node.challenge.certification === certification)[0] .filter(node => node.challenge.certification === certification)[0]
?.challenge.tests.map(test => test.id) ?? []; ?.challenge.tests.map(test => test.id) ?? [];
const currentBlockIds = challengeNodes const currentBlockIds = challengeNodes
.filter(node => node.challenge.block === block) .filter(
node =>
node.challenge.block === block &&
node.challenge.certification === certification
)
.map(node => node.challenge.id); .map(node => node.challenge.id);
if (isProjectBased(challengeType)) { if (isProjectBased(challengeType)) {