Skip to content

Commit 902853d

Browse files
authored
fix: isInitialized selector depends on unitUrl for course blocks (#1288)
1 parent 6eed643 commit 902853d

File tree

2 files changed

+54
-27
lines changed

2 files changed

+54
-27
lines changed

src/editors/data/redux/app/selectors.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,35 @@ export const returnUrl = createSelector(
4040
),
4141
);
4242

43+
export const isLibrary = createSelector(
44+
[
45+
module.simpleSelectors.learningContextId,
46+
module.simpleSelectors.blockId,
47+
],
48+
(learningContextId, blockId) => {
49+
if (learningContextId && learningContextId.startsWith('library-v1')) {
50+
return true;
51+
}
52+
if (blockId && blockId.startsWith('lb:')) {
53+
return true;
54+
}
55+
return false;
56+
},
57+
);
58+
4359
export const isInitialized = createSelector(
4460
[
61+
module.simpleSelectors.unitUrl,
4562
module.simpleSelectors.blockValue,
63+
module.isLibrary,
4664
],
47-
(blockValue) => !!(blockValue),
65+
(unitUrl, blockValue, isLibraryBlock) => {
66+
if (isLibraryBlock) {
67+
return !!blockValue;
68+
}
69+
70+
return !!blockValue && !!unitUrl;
71+
},
4872
);
4973

5074
export const displayTitle = createSelector(
@@ -76,22 +100,6 @@ export const analytics = createSelector(
76100
),
77101
);
78102

79-
export const isLibrary = createSelector(
80-
[
81-
module.simpleSelectors.learningContextId,
82-
module.simpleSelectors.blockId,
83-
],
84-
(learningContextId, blockId) => {
85-
if (learningContextId && learningContextId.startsWith('library-v1')) {
86-
return true;
87-
}
88-
if (blockId && blockId.startsWith('lb:')) {
89-
return true;
90-
}
91-
return false;
92-
},
93-
);
94-
95103
export default {
96104
...simpleSelectors,
97105
isInitialized,

src/editors/data/redux/app/selectors.test.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,40 @@ describe('app selectors unit tests', () => {
7878
});
7979
});
8080
describe('isInitialized selector', () => {
81-
it('is memoized based on editorInitialized and blockValue', () => {
81+
it('is memoized based on editorInitialized, unitUrl, isLibrary and blockValue', () => {
8282
expect(selectors.isInitialized.preSelectors).toEqual([
83+
simpleSelectors.unitUrl,
8384
simpleSelectors.blockValue,
85+
selectors.isLibrary,
8486
]);
8587
});
86-
it('returns true iff blockValue and editorInitialized are truthy', () => {
87-
const { cb } = selectors.isInitialized;
88-
const truthy = {
89-
blockValue: { block: 'value' },
90-
};
88+
describe('for library blocks', () => {
89+
it('returns true if blockValue, and editorInitialized are truthy', () => {
90+
const { cb } = selectors.isInitialized;
91+
const truthy = {
92+
blockValue: { block: 'value' },
93+
};
9194

92-
[
93-
[[truthy.blockValue], true],
94-
[[null], false],
95-
].map(([args, expected]) => expect(cb(...args)).toEqual(expected));
95+
[
96+
[[null, truthy.blockValue, true], true],
97+
[[null, null, true], false],
98+
].map(([args, expected]) => expect(cb(...args)).toEqual(expected));
99+
});
100+
});
101+
describe('for course blocks', () => {
102+
it('returns true if blockValue, unitUrl, and editorInitialized are truthy', () => {
103+
const { cb } = selectors.isInitialized;
104+
const truthy = {
105+
blockValue: { block: 'value' },
106+
unitUrl: { url: 'data' },
107+
};
108+
109+
[
110+
[[null, truthy.blockValue, false], false],
111+
[[truthy.unitUrl, null, false], false],
112+
[[truthy.unitUrl, truthy.blockValue, false], true],
113+
].map(([args, expected]) => expect(cb(...args)).toEqual(expected));
114+
});
96115
});
97116
});
98117
describe('displayTitle', () => {

0 commit comments

Comments
 (0)