From 01291162ef3cb747763202119ecfb6340e2eaba5 Mon Sep 17 00:00:00 2001 From: systimotic Date: Mon, 30 Jan 2017 21:45:51 +0100 Subject: [PATCH] Fix isBeta challenges displaying without title when they should be hidden --- common/app/redux/utils.js | 20 ++++++++++- common/app/redux/utils.test.js | 62 +++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/common/app/redux/utils.js b/common/app/redux/utils.js index ee6eb694ca6..10e152eea8d 100644 --- a/common/app/redux/utils.js +++ b/common/app/redux/utils.js @@ -10,12 +10,30 @@ export function filterComingSoonBetaChallenge( } export function filterComingSoonBetaFromEntities( - { challenge: challengeMap, ...rest }, + { challenge: challengeMap, block: blockMap, ...rest }, isDev = false ) { const filter = filterComingSoonBetaChallenge.bind(null, isDev); return { ...rest, + block: Object.keys(blockMap) + .map(dashedName => { + const block = blockMap[dashedName]; + + const filteredChallenges = block.challenges + .map(dashedName => challengeMap[dashedName]) + .filter(filter) + .map(challenge => challenge.dashedName); + + return { + ...block, + challenges: [ ...filteredChallenges ] + }; + }) + .reduce((blockMap, block) => { + blockMap[block.dashedName] = block; + return blockMap; + }, {}), challenge: Object.keys(challengeMap) .map(dashedName => challengeMap[dashedName]) .filter(filter) diff --git a/common/app/redux/utils.test.js b/common/app/redux/utils.test.js index 08cee9e2ed5..456fc1c55fd 100644 --- a/common/app/redux/utils.test.js +++ b/common/app/redux/utils.test.js @@ -37,7 +37,7 @@ test.test('filterComingSoonBetaChallenge', t => { test.test('filterComingSoonBetaFromEntities', t => { t.plan(2); t.test('should filter isBeta|coming-soon by default', t => { - t.plan(2); + t.plan(4); const normalChallenge = { dashedName: 'normal-challenge' }; const entities = { challenge: { @@ -48,8 +48,23 @@ test.test('filterComingSoonBetaFromEntities', t => { isBeta: true }, [normalChallenge.dashedName]: normalChallenge + }, + block: { + 'coming-soon': { + dashedName: 'coming-soon', + challenges: ['coming-soon'] + }, + 'is-beta': { + dashedName: 'is-beta', + challenges: ['is-beta'] + }, + normal: { + dashedName: 'normal', + challenges: [normalChallenge.dashedName] + } } }; + const actual = filterComingSoonBetaFromEntities(entities); t.isEqual( Object.keys(actual.challenge).length, @@ -61,6 +76,23 @@ test.test('filterComingSoonBetaFromEntities', t => { normalChallenge, 'did not return the correct challenge' ); + + const challengesFromBlocks = []; + Object.keys(actual.block) + .forEach(block => { + const challenges = actual.block[block].challenges; + challenges.forEach(challenge => challengesFromBlocks.push(challenge)); + }); + t.isEqual( + challengesFromBlocks.length, + 1, + 'did not filter the correct amount of challenges from blocks' + ); + t.isEqual( + challengesFromBlocks[0], + normalChallenge.dashedName, + 'did not return the correct challenge from blocks' + ); }); t.test('should not filter isBeta|coming-soon when isDev', t => { t.plan(1); @@ -80,6 +112,24 @@ test.test('filterComingSoonBetaFromEntities', t => { isBeta: true }, [normalChallenge.dashedName]: normalChallenge + }, + block: { + 'coming-soon': { + dashedName: 'coming-soon', + challenges: ['coming-soon'] + }, + 'is-beta': { + dashedName: 'is-beta', + challenges: ['is-beta'] + }, + 'is-both': { + dashedName: 'is-both', + challenges: ['is-both'] + }, + normal: { + dashedName: 'normal', + challenges: [normalChallenge.dashedName] + } } }; const actual = filterComingSoonBetaFromEntities(entities, true); @@ -88,5 +138,15 @@ test.test('filterComingSoonBetaFromEntities', t => { 4, 'filtered challenges' ); + let challengesFromBlocksCount = 0; + Object.keys(actual.block) + .forEach(block => { + challengesFromBlocksCount += actual.block[block].challenges.length; + }); + t.isEqual( + challengesFromBlocksCount, + 4, + 'filtered challenges from blocks' + ); }); });