fix: don't get returnUrl for v2 blocks. (#380)
This commit is contained in:
@@ -6,7 +6,9 @@ export const unit = ({ studioEndpointUrl, unitUrl }) => (
|
||||
`${studioEndpointUrl}/container/${unitUrl.data.ancestors[0]?.id}`
|
||||
);
|
||||
|
||||
export const returnUrl = ({ studioEndpointUrl, unitUrl, learningContextId }) => {
|
||||
export const returnUrl = ({
|
||||
studioEndpointUrl, unitUrl, learningContextId, blockId,
|
||||
}) => {
|
||||
if (learningContextId && learningContextId.startsWith('library-v1')) {
|
||||
// when the learning context is a v1 library, return to the library page
|
||||
return libraryV1({ studioEndpointUrl, learningContextId });
|
||||
@@ -19,7 +21,8 @@ export const returnUrl = ({ studioEndpointUrl, unitUrl, learningContextId }) =>
|
||||
return '';
|
||||
}
|
||||
// when the learning context is a course, return to the unit page
|
||||
if (unitUrl) {
|
||||
// only do this for v1 blocks
|
||||
if (unitUrl && blockId.includes('block-v1')) {
|
||||
return unit({ studioEndpointUrl, unitUrl });
|
||||
}
|
||||
return '';
|
||||
|
||||
@@ -56,9 +56,17 @@ describe('cms url methods', () => {
|
||||
.toEqual('');
|
||||
});
|
||||
it('returns url with studioEndpointUrl and unitUrl', () => {
|
||||
expect(returnUrl({ studioEndpointUrl, unitUrl, learningContextId: courseId }))
|
||||
expect(returnUrl({
|
||||
studioEndpointUrl, unitUrl, learningContextId: courseId, blockId,
|
||||
}))
|
||||
.toEqual(`${studioEndpointUrl}/container/${unitUrl.data.ancestors[0].id}`);
|
||||
});
|
||||
it('returns blank url for v2 block', () => {
|
||||
expect(returnUrl({
|
||||
studioEndpointUrl, unitUrl, learningContextId: courseId, blockId: v2BlockId,
|
||||
}))
|
||||
.toEqual('');
|
||||
});
|
||||
it('throws error if no unit url', () => {
|
||||
expect(returnUrl({ studioEndpointUrl, unitUrl: null, learningContextId: courseId }))
|
||||
.toEqual('');
|
||||
|
||||
Reference in New Issue
Block a user