Skip to content

Commit 0c37a18

Browse files
committed
test: fix some failing tests
1 parent 35f9676 commit 0c37a18

3 files changed

Lines changed: 40 additions & 46 deletions

File tree

src/course-unit/CourseUnit.test.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import messages from './messages';
7979
let axiosMock;
8080
let store;
8181
const courseId = '123';
82-
const blockId = '567890';
82+
const blockId = 'block-v1:edX+DemoX+Demo_Course+type@vertical+block@123';
8383
const sequenceId = 'block-v1:edX+DemoX+Demo_Course+type@sequential+block@19a30717eff543078a5d94ae9d6c18a5';
8484
const unitDisplayName = courseSectionVerticalMock.xblock_info.display_name;
8585
const mockedUsedNavigate = jest.fn();
@@ -102,8 +102,8 @@ const postXBlockBody = {
102102
staged_content: 'clipboard',
103103
};
104104

105-
jest.mock('react-router-dom', () => ({
106-
...jest.requireActual('react-router-dom'),
105+
jest.mock('react-router', () => ({
106+
...jest.requireActual('react-router'),
107107
useParams: () => ({ blockId, sequenceId }),
108108
useNavigate: () => mockedUsedNavigate,
109109
}));
@@ -376,19 +376,17 @@ describe('<CourseUnit />', () => {
376376
await user.click(publishBtn);
377377

378378
// check if the sidebar status is Published and Live
379-
waitFor(() => {
380-
expect(screen.getByText(
381-
legacySidebarMessages.sidebarTitlePublishedAndLive.defaultMessage,
382-
)).toBeInTheDocument();
383-
});
379+
expect(await screen.findByText(
380+
legacySidebarMessages.sidebarTitlePublishedAndLive.defaultMessage,
381+
)).toBeInTheDocument();
384382
expect(await screen.findByText(
385383
unitInfoMessages.publishLastPublished.defaultMessage
386384
.replace('{publishedOn}', courseSectionVerticalMock.xblock_info.published_on)
387385
.replace('{publishedBy}', userName),
388386
)).toBeInTheDocument();
389-
waitFor(() => {
390-
expect(screen.queryByRole('button', { name: legacySidebarMessages.actionButtonPublishTitle.defaultMessage })).not.toBeInTheDocument();
391-
});
387+
expect(screen.queryByRole('button', {
388+
name: legacySidebarMessages.actionButtonPublishTitle.defaultMessage,
389+
})).not.toBeInTheDocument();
392390
expect(await screen.findByText(unitDisplayName)).toBeInTheDocument();
393391

394392
axiosMock
@@ -572,11 +570,9 @@ describe('<CourseUnit />', () => {
572570
);
573571

574572
// after duplicate the xblock, the sidebar status changes to Draft (unpublished changes)
575-
await waitFor(async () => {
576-
expect(await screen.findByText(
577-
legacySidebarMessages.sidebarTitleDraftUnpublishedChanges.defaultMessage,
578-
)).toBeInTheDocument();
579-
});
573+
expect(await screen.findByText(
574+
legacySidebarMessages.sidebarTitleDraftUnpublishedChanges.defaultMessage,
575+
)).toBeInTheDocument();
580576
expect(await screen.findByText(legacySidebarMessages.releaseStatusTitle.defaultMessage)).toBeInTheDocument();
581577
expect(await screen.findByText(unitInfoMessages.visibilityVisibleToTitle.defaultMessage)).toBeInTheDocument();
582578
expect(await screen.findByText(unitInfoMessages.visibilityCheckboxTitle.defaultMessage)).toBeInTheDocument();

src/course-unit/legacy-sidebar/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const LegacySidebar = ({
3939
const { blockId } = useParams();
4040
const { courseId } = useCourseAuthoringContext();
4141

42+
if (!blockId) {
43+
return null;
44+
}
45+
4246
return (
4347
<Stack gap={3} className="px-4 mw-sm">
4448
{isUnitVerticalType && (

src/course-unit/unit-sidebar/unit-info/PublishControls.tsx

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import messages from './messages';
1414
import UnitVisibilityInfo from './UnitVisibilityInfo';
1515

1616
interface PublishControlsProps {
17-
blockId?: string,
17+
blockId: string,
1818
hideCopyButton?: boolean,
1919
}
2020

@@ -48,42 +48,36 @@ const PublishControls = ({
4848

4949
const handleCourseUnitVisibility = () => {
5050
closeVisibleModal();
51-
if (blockId) {
52-
publishMutation.mutate({
53-
unitId: blockId,
54-
type: PUBLISH_TYPES.republish,
55-
isVisibleToStaffOnly: false,
56-
groupAccess: null,
57-
});
58-
}
51+
publishMutation.mutate({
52+
unitId: blockId,
53+
type: PUBLISH_TYPES.republish,
54+
isVisibleToStaffOnly: false,
55+
groupAccess: null,
56+
});
5957
};
6058

6159
const handleCourseUnitDiscardChanges = () => {
6260
closeDiscardModal();
63-
if (blockId) {
64-
publishMutation.mutate(
65-
{
66-
unitId: blockId,
67-
type: PUBLISH_TYPES.discardChanges,
68-
isVisibleToStaffOnly: false,
69-
groupAccess: null,
70-
},
71-
{
72-
onSuccess: () => sendMessageToIframe(messageTypes.refreshXBlock, null),
73-
},
74-
);
75-
}
76-
};
77-
78-
const handleCourseUnitPublish = () => {
79-
if (blockId) {
80-
publishMutation.mutate({
61+
publishMutation.mutate(
62+
{
8163
unitId: blockId,
82-
type: PUBLISH_TYPES.makePublic,
64+
type: PUBLISH_TYPES.discardChanges,
8365
isVisibleToStaffOnly: false,
8466
groupAccess: null,
85-
});
86-
}
67+
},
68+
{
69+
onSuccess: () => sendMessageToIframe(messageTypes.refreshXBlock, null),
70+
},
71+
);
72+
};
73+
74+
const handleCourseUnitPublish = () => {
75+
publishMutation.mutate({
76+
unitId: blockId,
77+
type: PUBLISH_TYPES.makePublic,
78+
isVisibleToStaffOnly: false,
79+
groupAccess: null,
80+
});
8781
};
8882

8983
return (

0 commit comments

Comments
 (0)