feat: update isLibrary check to include v2 libs (#389)

This commit is contained in:
Kristin Aoki
2023-09-13 13:13:18 -04:00
committed by GitHub
parent 73af4317f6
commit 39aa5aa749
2 changed files with 38 additions and 11 deletions

View File

@@ -86,14 +86,17 @@ export const isRaw = createSelector(
);
export const isLibrary = createSelector(
[module.simpleSelectors.learningContextId],
(learningContextId) => {
if (!learningContextId) {
return null;
}
[
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;
},
);

View File

@@ -153,16 +153,40 @@ describe('app selectors unit tests', () => {
it('is memoized based on studioView', () => {
expect(selectors.isLibrary.preSelectors).toEqual([
simpleSelectors.learningContextId,
simpleSelectors.blockId,
]);
});
it('returns null if blockId is null', () => {
expect(selectors.isLibrary.cb(null)).toEqual(null);
describe('blockId is null', () => {
it('should return false when learningContextId null', () => {
expect(selectors.isLibrary.cb(null, null)).toEqual(false);
});
it('should return false when learningContextId defined', () => {
expect(selectors.isLibrary.cb(learningContextIdCourse, null)).toEqual(false);
});
});
it('returns true if blockId starts with lib', () => {
expect(selectors.isLibrary.cb(learningContextIdLibrary)).toEqual(true);
describe('blockId is a course block', () => {
it('should return false when learningContextId null', () => {
expect(selectors.isLibrary.cb(null, 'block-v1:')).toEqual(false);
});
it('should return false when learningContextId defined', () => {
expect(selectors.isLibrary.cb(learningContextIdCourse, 'block-v1:')).toEqual(false);
});
});
it('returns false if the blockId does not start with lib', () => {
expect(selectors.isLibrary.cb(learningContextIdCourse)).toEqual(false);
describe('blockId is a v2 library block', () => {
it('should return true when learningContextId null', () => {
expect(selectors.isLibrary.cb(null, 'lb:')).toEqual(true);
});
it('should return false when learningContextId is a v1 library', () => {
expect(selectors.isLibrary.cb(learningContextIdLibrary, 'lb:')).toEqual(true);
});
});
describe('blockId is a v1 library block', () => {
it('should return false when learningContextId null', () => {
expect(selectors.isLibrary.cb(null, 'library-v1')).toEqual(false);
});
it('should return true when learningContextId a v1 library', () => {
expect(selectors.isLibrary.cb(learningContextIdLibrary, 'library-v1')).toEqual(true);
});
});
});
});