diff --git a/src/course-outline/section-card/SectionCard.test.jsx b/src/course-outline/section-card/SectionCard.test.jsx index 458d6ce6d0..1ffda7b738 100644 --- a/src/course-outline/section-card/SectionCard.test.jsx +++ b/src/course-outline/section-card/SectionCard.test.jsx @@ -87,17 +87,17 @@ describe('', () => { 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(); diff --git a/src/course-outline/subsection-card/SubsectionCard.test.jsx b/src/course-outline/subsection-card/SubsectionCard.test.jsx index a0f8c688cf..c0e6cd9498 100644 --- a/src/course-outline/subsection-card/SubsectionCard.test.jsx +++ b/src/course-outline/subsection-card/SubsectionCard.test.jsx @@ -36,6 +36,8 @@ const subsection = { hasChanges: false, }; +const onEditSubectionSubmit = jest.fn(); + const renderComponent = (props) => render( @@ -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} @@ -91,4 +93,33 @@ describe('', () => { 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(); + }); });