diff --git a/src/editors/data/redux/app/selectors.js b/src/editors/data/redux/app/selectors.js index d1c7ffd66..43e7d6861 100644 --- a/src/editors/data/redux/app/selectors.js +++ b/src/editors/data/redux/app/selectors.js @@ -40,11 +40,35 @@ export const returnUrl = createSelector( ), ); +export const isLibrary = createSelector( + [ + module.simpleSelectors.learningContextId, + module.simpleSelectors.blockId, + ], + (learningContextId, blockId) => { + if (learningContextId && learningContextId.startsWith('library-v1')) { + return true; + } + if (blockId && blockId.startsWith('lb:')) { + return true; + } + return false; + }, +); + export const isInitialized = createSelector( [ + module.simpleSelectors.unitUrl, module.simpleSelectors.blockValue, + module.isLibrary, ], - (blockValue) => !!(blockValue), + (unitUrl, blockValue, isLibraryBlock) => { + if (isLibraryBlock) { + return !!blockValue; + } + + return !!blockValue && !!unitUrl; + }, ); export const displayTitle = createSelector( @@ -76,22 +100,6 @@ export const analytics = createSelector( ), ); -export const isLibrary = createSelector( - [ - module.simpleSelectors.learningContextId, - module.simpleSelectors.blockId, - ], - (learningContextId, blockId) => { - if (learningContextId && learningContextId.startsWith('library-v1')) { - return true; - } - if (blockId && blockId.startsWith('lb:')) { - return true; - } - return false; - }, -); - export default { ...simpleSelectors, isInitialized, diff --git a/src/editors/data/redux/app/selectors.test.js b/src/editors/data/redux/app/selectors.test.js index 6a9fd2c94..061a0b5dd 100644 --- a/src/editors/data/redux/app/selectors.test.js +++ b/src/editors/data/redux/app/selectors.test.js @@ -78,21 +78,40 @@ describe('app selectors unit tests', () => { }); }); describe('isInitialized selector', () => { - it('is memoized based on editorInitialized and blockValue', () => { + it('is memoized based on editorInitialized, unitUrl, isLibrary and blockValue', () => { expect(selectors.isInitialized.preSelectors).toEqual([ + simpleSelectors.unitUrl, simpleSelectors.blockValue, + selectors.isLibrary, ]); }); - it('returns true iff blockValue and editorInitialized are truthy', () => { - const { cb } = selectors.isInitialized; - const truthy = { - blockValue: { block: 'value' }, - }; + describe('for library blocks', () => { + it('returns true if blockValue, and editorInitialized are truthy', () => { + const { cb } = selectors.isInitialized; + const truthy = { + blockValue: { block: 'value' }, + }; - [ - [[truthy.blockValue], true], - [[null], false], - ].map(([args, expected]) => expect(cb(...args)).toEqual(expected)); + [ + [[null, truthy.blockValue, true], true], + [[null, null, true], false], + ].map(([args, expected]) => expect(cb(...args)).toEqual(expected)); + }); + }); + describe('for course blocks', () => { + it('returns true if blockValue, unitUrl, and editorInitialized are truthy', () => { + const { cb } = selectors.isInitialized; + const truthy = { + blockValue: { block: 'value' }, + unitUrl: { url: 'data' }, + }; + + [ + [[null, truthy.blockValue, false], false], + [[truthy.unitUrl, null, false], false], + [[truthy.unitUrl, truthy.blockValue, false], true], + ].map(([args, expected]) => expect(cb(...args)).toEqual(expected)); + }); }); }); describe('displayTitle', () => {