fix: don't get returnUrl for v2 blocks. (#380)

This commit is contained in:
kenclary
2023-08-21 16:57:08 -07:00
committed by GitHub
parent e691df9cb5
commit 259b9f3d1f
4 changed files with 26 additions and 8 deletions

View File

@@ -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 '';

View File

@@ -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('');