From bec59e5bbe5965590bf6c382b9a701d881a050c1 Mon Sep 17 00:00:00 2001 From: Ihor Romaniuk Date: Tue, 12 Mar 2024 16:48:11 +0100 Subject: [PATCH] feat: [FC-0044] Unit page - display xblock components (#857) --- src/course-unit/CourseUnit.test.jsx | 27 +++++++++++++------- src/course-unit/course-xblock/messages.js | 2 +- src/course-unit/header-title/HeaderTitle.jsx | 5 ++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/course-unit/CourseUnit.test.jsx b/src/course-unit/CourseUnit.test.jsx index 233bb63cc1..a4d4337bb5 100644 --- a/src/course-unit/CourseUnit.test.jsx +++ b/src/course-unit/CourseUnit.test.jsx @@ -95,14 +95,15 @@ describe('', () => { }); it('render CourseUnit component correctly', async () => { - const { getByText, getByRole } = render(); + const { getByText, getByRole, getByTestId } = render(); const currentSectionName = courseUnitIndexMock.ancestor_info.ancestors[1].display_name; const currentSubSectionName = courseUnitIndexMock.ancestor_info.ancestors[1].display_name; await waitFor(() => { + const unitHeaderTitle = getByTestId('unit-header-title'); expect(getByText(unitDisplayName)).toBeInTheDocument(); - expect(getByRole('button', { name: headerTitleMessages.altButtonEdit.defaultMessage })).toBeInTheDocument(); - expect(getByRole('button', { name: headerTitleMessages.altButtonSettings.defaultMessage })).toBeInTheDocument(); + expect(within(unitHeaderTitle).getByRole('button', { name: headerTitleMessages.altButtonEdit.defaultMessage })).toBeInTheDocument(); + expect(within(unitHeaderTitle).getByRole('button', { name: headerTitleMessages.altButtonSettings.defaultMessage })).toBeInTheDocument(); expect(getByRole('button', { name: headerNavigationsMessages.viewLiveButton.defaultMessage })).toBeInTheDocument(); expect(getByRole('button', { name: headerNavigationsMessages.previewButton.defaultMessage })).toBeInTheDocument(); expect(getByRole('button', { name: currentSectionName })).toBeInTheDocument(); @@ -136,7 +137,10 @@ describe('', () => { it('checks courseUnit title changing when edit query is successfully', async () => { const { - findByText, queryByRole, getByRole, + findByText, + queryByRole, + getByRole, + getByTestId, } = render(); let editTitleButton = null; let titleEditField = null; @@ -160,8 +164,11 @@ describe('', () => { }); await waitFor(() => { - editTitleButton = getByRole('button', { name: headerTitleMessages.altButtonEdit.defaultMessage }); - titleEditField = queryByRole('textbox', { name: headerTitleMessages.ariaLabelButtonEdit.defaultMessage }); + const unitHeaderTitle = getByTestId('unit-header-title'); + editTitleButton = within(unitHeaderTitle) + .getByRole('button', { name: headerTitleMessages.altButtonEdit.defaultMessage }); + titleEditField = within(unitHeaderTitle) + .queryByRole('textbox', { name: headerTitleMessages.ariaLabelButtonEdit.defaultMessage }); }); expect(titleEditField).not.toBeInTheDocument(); fireEvent.click(editTitleButton); @@ -299,7 +306,7 @@ describe('', () => { }); it('the sequence unit is updated after changing the unit header', async () => { - const { getAllByTestId, getByRole } = render(); + const { getAllByTestId, getByTestId } = render(); const updatedCourseSectionVerticalData = cloneDeep(courseSectionVerticalMock); const updatedAncestorsChild = updatedCourseSectionVerticalData.xblock_info.ancestor_info.ancestors[0]; set(updatedCourseSectionVerticalData, 'xblock_info.ancestor_info.ancestors[0].child_info.children', [ @@ -331,10 +338,12 @@ describe('', () => { await executeThunk(fetchCourseSectionVerticalData(blockId), store.dispatch); - const editTitleButton = getByRole('button', { name: headerTitleMessages.altButtonEdit.defaultMessage }); + const unitHeaderTitle = getByTestId('unit-header-title'); + + const editTitleButton = within(unitHeaderTitle).getByRole('button', { name: headerTitleMessages.altButtonEdit.defaultMessage }); fireEvent.click(editTitleButton); - const titleEditField = getByRole('textbox', { name: headerTitleMessages.ariaLabelButtonEdit.defaultMessage }); + const titleEditField = within(unitHeaderTitle).getByRole('textbox', { name: headerTitleMessages.ariaLabelButtonEdit.defaultMessage }); fireEvent.change(titleEditField, { target: { value: newDisplayName } }); await act(async () => fireEvent.blur(titleEditField)); diff --git a/src/course-unit/course-xblock/messages.js b/src/course-unit/course-xblock/messages.js index 80e25dac13..e4b6365424 100644 --- a/src/course-unit/course-xblock/messages.js +++ b/src/course-unit/course-xblock/messages.js @@ -3,7 +3,7 @@ import { defineMessages } from '@edx/frontend-platform/i18n'; const messages = defineMessages({ blockAltButtonEdit: { id: 'course-authoring.course-unit.xblock.button.edit.alt', - defaultMessage: 'Edit Item', + defaultMessage: 'Edit', }, blockActionsDropdownAlt: { id: 'course-authoring.course-unit.xblock.button.actions.alt', diff --git a/src/course-unit/header-title/HeaderTitle.jsx b/src/course-unit/header-title/HeaderTitle.jsx index 9afdd60f1e..4fc5739225 100644 --- a/src/course-unit/header-title/HeaderTitle.jsx +++ b/src/course-unit/header-title/HeaderTitle.jsx @@ -27,7 +27,7 @@ const HeaderTitle = ({ }, [unitTitle]); return ( -
+
{isTitleEditFormOpen ? ( {}} + onClick={() => { + }} />
);