Skip to content

Commit

Permalink
feat: Unit page - make Video button functional
Browse files Browse the repository at this point in the history
  • Loading branch information
ihor-romaniuk committed Feb 8, 2024
1 parent f07a7a9 commit a4959b2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,22 @@ describe('<CourseUnit />', () => {
expect(mockedUsedNavigate).toHaveBeenCalledWith(`/course/${courseKey}/editor/problem/${locator}`);
});
});

it('handles creating Video xblock and navigates to editor page', async () => {
const { courseKey, locator } = courseCreateXblockMock;
axiosMock
.onPost(postXBlockBaseApiUrl({ type: 'video', category: 'video', parentLocator: blockId }))
.reply(200, courseCreateXblockMock);
const { getByRole } = render(<RootWrapper />);

await waitFor(() => {
const discussionButton = getByRole('button', {
name: new RegExp(`${messages.buttonText.defaultMessage} Video`, 'i'),
});

userEvent.click(discussionButton);
expect(mockedUsedNavigate).toHaveBeenCalled();
expect(mockedUsedNavigate).toHaveBeenCalledWith(`/course/${courseKey}/editor/video/${locator}`);
});
});
});
3 changes: 2 additions & 1 deletion src/course-unit/add-component/AddComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ const AddComponent = ({ blockId, handleCreateNewCourseXblock }) => {
handleCreateNewCourseXblock({ type, parentLocator: blockId });
break;
case COMPONENT_ICON_TYPES.problem:
case COMPONENT_ICON_TYPES.video:
handleCreateNewCourseXblock({ type, parentLocator: blockId }, ({ courseKey, locator }) => {
navigate(`/course/${courseKey}/editor/problem/${locator}`);
navigate(`/course/${courseKey}/editor/${type}/${locator}`);
});
break;
default:

Check warning on line 29 in src/course-unit/add-component/AddComponent.jsx

View check run for this annotation

Codecov / codecov/patch

src/course-unit/add-component/AddComponent.jsx#L29

Added line #L29 was not covered by tests
Expand Down
17 changes: 16 additions & 1 deletion src/course-unit/add-component/AddComponent.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('<AddComponent />', () => {
});
});

it('create new "Problem" xblock on click', () => {
it('calls handleCreateNewCourseXblock with correct parameters when Problem xblock create button is clicked', () => {
const { getByRole } = renderComponent();

const discussionButton = getByRole('button', {
Expand All @@ -107,4 +107,19 @@ describe('<AddComponent />', () => {
type: 'problem',
}, expect.any(Function));
});

it('calls handleCreateNewCourseXblock with correct parameters when Video xblock create button is clicked', () => {
const { getByRole } = renderComponent();

const discussionButton = getByRole('button', {
name: new RegExp(`${messages.buttonText.defaultMessage} Video`, 'i'),
});

userEvent.click(discussionButton);
expect(handleCreateNewCourseXblockMock).toHaveBeenCalled();
expect(handleCreateNewCourseXblockMock).toHaveBeenCalledWith({
parentLocator: '123',
type: 'video',
}, expect.any(Function));
});
});

0 comments on commit a4959b2

Please sign in to comment.