diff --git a/src/course-outline/CourseOutline.test.jsx b/src/course-outline/CourseOutline.test.jsx index 8242ebe8ee..84e3382a75 100644 --- a/src/course-outline/CourseOutline.test.jsx +++ b/src/course-outline/CourseOutline.test.jsx @@ -408,7 +408,9 @@ describe('', () => { await executeThunk(publishCourseItemQuery(section.id, section.id), store.dispatch); const firstSection = getAllByTestId('section-card')[0]; - expect(firstSection.querySelector('.item-card-header__badge-status')).toHaveTextContent('Published not live'); + expect( + firstSection.querySelector('.item-card-header__badge-status'), + ).toHaveTextContent(cardHeaderMessages.statusBadgePublishedNotLive.defaultMessage); }); it('check configure section when configure query is successful', async () => { diff --git a/src/course-outline/section-card/SectionCard.test.jsx b/src/course-outline/section-card/SectionCard.test.jsx index b1a65402d3..725b219811 100644 --- a/src/course-outline/section-card/SectionCard.test.jsx +++ b/src/course-outline/section-card/SectionCard.test.jsx @@ -8,6 +8,7 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; import initializeStore from '../../store'; import SectionCard from './SectionCard'; +import cardHeaderMessages from '../card-header/messages'; // eslint-disable-next-line no-unused-vars let axiosMock; @@ -25,6 +26,8 @@ const section = { highlights: ['highlight 1', 'highlight 2'], }; +const onEditSectionSubmit = jest.fn(); + const renderComponent = (props) => render( @@ -33,14 +36,11 @@ const renderComponent = (props) => render( onOpenPublishModal={jest.fn()} onOpenHighlightsModal={jest.fn()} onOpenDeleteModal={jest.fn()} - onEditClick={jest.fn()} savingStatus="" - onEditSectionSubmit={jest.fn()} + onEditSectionSubmit={onEditSectionSubmit} onDuplicateSubmit={jest.fn()} - isSectionsExpanded - namePrefix="section" - connectDragSource={(el) => el} - isDragging + isSectionsExpanded={true} + onNewSubsectionSubmit={jest.fn()} {...props} > children @@ -83,4 +83,70 @@ describe('', () => { expect(queryByTestId('section-card__subsections')).toBeInTheDocument(); expect(queryByTestId('new-subsection-button')).toBeInTheDocument(); }); + + it('title only updates if changed', async () => { + const { queryByTestId, findByTestId } = renderComponent(); + + const editButton = await findByTestId('edit-button'); + fireEvent.click(editButton); + expect(queryByTestId('edit field')).toBeInTheDocument(); + + const menu = await findByTestId('section-card-header__menu-button'); + fireEvent.click(menu); + + expect(onEditSectionSubmit).not.toHaveBeenCalled(); + + fireEvent.click(editButton); + const editField = await findByTestId('edit field'); + fireEvent.change(editField, { target: { value: 'some random value' } }); + fireEvent.blur(editField); + expect(onEditSectionSubmit).toHaveBeenCalled(); + }); + + it('renders live status', async () => { + const { findByText } = renderComponent(); + expect(await findByText(cardHeaderMessages.statusBadgeLive.defaultMessage)).toBeInTheDocument(); + }); + + it('renders published but live status', async () => { + const { findByText } = renderComponent({ + section: { + ...section, + published: true, + releasedToStudents: false, + visibleToStaffOnly: false, + visibilityState: 'visible', + staffOnlyMessage: false, + }, + }); + expect(await findByText(cardHeaderMessages.statusBadgePublishedNotLive.defaultMessage)).toBeInTheDocument(); + }); + + it('renders staff status', async () => { + const { findByText } = renderComponent({ + section: { + ...section, + published: false, + releasedToStudents: false, + visibleToStaffOnly: true, + visibilityState: 'staff_only', + staffOnlyMessage: true, + }, + }); + expect(await findByText(cardHeaderMessages.statusBadgeStaffOnly.defaultMessage)).toBeInTheDocument(); + }); + + it('renders draft status', async () => { + const { findByText } = renderComponent({ + section: { + ...section, + published: false, + releasedToStudents: false, + visibleToStaffOnly: false, + visibilityState: 'staff_only', + staffOnlyMessage: false, + }, + }); + expect(await findByText(cardHeaderMessages.statusBadgeDraft.defaultMessage)).toBeInTheDocument(); + }); });