Skip to content

Commit

Permalink
test: additional tests for subsections
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Dec 19, 2023
1 parent 62a7fb2 commit fac196d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/course-outline/section-card/SectionCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ describe('<SectionCard />', () => {
it('title only updates if changed', async () => {
const { queryByTestId, findByTestId } = renderComponent();

const editButton = await findByTestId('edit-button');
let editButton = await findByTestId('edit-button');
fireEvent.click(editButton);
let editField = await findByTestId('edit field');
expect(queryByTestId('edit field')).toBeInTheDocument();

const menu = await findByTestId('section-card-header__menu-button');
fireEvent.click(menu);
fireEvent.blur(editField);

expect(onEditSectionSubmit).not.toHaveBeenCalled();

editButton = await findByTestId('edit-button');
fireEvent.click(editButton);
const editField = await findByTestId('edit field');
editField = await findByTestId('edit field');
fireEvent.change(editField, { target: { value: 'some random value' } });
fireEvent.blur(editField);
expect(onEditSectionSubmit).toHaveBeenCalled();
Expand Down
33 changes: 32 additions & 1 deletion src/course-outline/subsection-card/SubsectionCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const subsection = {
hasChanges: false,
};

const onEditSubectionSubmit = jest.fn();

const renderComponent = (props) => render(
<AppProvider store={store}>
<IntlProvider locale="en">
Expand All @@ -47,7 +49,7 @@ const renderComponent = (props) => render(
onOpenDeleteModal={jest.fn()}
onEditClick={jest.fn()}
savingStatus=""
onEditSubmit={jest.fn()}
onEditSubmit={onEditSubectionSubmit}
onDuplicateSubmit={jest.fn()}
namePrefix="subsection"
{...props}
Expand Down Expand Up @@ -91,4 +93,33 @@ describe('<SubsectionCard />', () => {
expect(queryByTestId('subsection-card__units')).not.toBeInTheDocument();
expect(queryByTestId('new-unit-button')).not.toBeInTheDocument();
});

it('updates current section, subsection and item', async () => {
const { findByTestId } = renderComponent();

const menu = await findByTestId('subsection-card-header__menu');
fireEvent.click(menu);
const { currentSection, currentSubsection, currentItem } = store.getState().courseOutline;
expect(currentSection).toEqual(section);
expect(currentSubsection).toEqual(subsection);
expect(currentItem).toEqual(subsection);
});

it('title only updates if changed', async () => {
const { findByTestId } = renderComponent();

let editButton = await findByTestId('edit-button');
fireEvent.click(editButton);
let editField = await findByTestId('edit field');
fireEvent.blur(editField);

expect(onEditSubectionSubmit).not.toHaveBeenCalled();

editButton = await findByTestId('edit-button');
fireEvent.click(editButton);
editField = await findByTestId('edit field');
fireEvent.change(editField, { target: { value: 'some random value' } });
fireEvent.keyDown(editField, { key: 'Enter', keyCode: 13 });
expect(onEditSubectionSubmit).toHaveBeenCalled();
});
});

0 comments on commit fac196d

Please sign in to comment.