Skip to content

Commit

Permalink
test: additional tests for sections
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Dec 19, 2023
1 parent d649b46 commit 62a7fb2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/course-outline/CourseOutline.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ describe('<CourseOutline />', () => {
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 () => {
Expand Down
76 changes: 71 additions & 5 deletions src/course-outline/section-card/SectionCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,8 @@ const section = {
highlights: ['highlight 1', 'highlight 2'],
};

const onEditSectionSubmit = jest.fn();

const renderComponent = (props) => render(
<AppProvider store={store}>
<IntlProvider locale="en">
Expand All @@ -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
onNewSubsectionSubmit={jest.fn()}
{...props}
>
<span>children</span>
Expand Down Expand Up @@ -83,4 +83,70 @@ describe('<SectionCard />', () => {
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();
});
});

0 comments on commit 62a7fb2

Please sign in to comment.