fix: isInitialized selector depends on unitUrl for course blocks (#1288)

This commit is contained in:
Kristin Aoki
2024-09-16 14:34:56 -04:00
committed by GitHub
parent 6eed6438cb
commit 902853d649
2 changed files with 54 additions and 27 deletions

View File

@@ -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,

View File

@@ -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', () => {