Skip to content

Commit

Permalink
Add test for hierarchy task list combination
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolleromero committed Jul 6, 2023
1 parent ac211f0 commit b456e32
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/drafts/MarkdownViewer/MarkdownViewer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ text before list
- [x] item 1
- [ ] item 2
text after list`
const hierarchyBeforeTaskListNoItemsChecked = `
text before list
\`\`\`[tasklist]
- [ ] item A
- [ ] item B
\`\`\`
- [ ] item 1
- [ ] item 2
text after list`
const hierarchyBeforeTaskListOneItemChecked = `
text before list
\`\`\`[tasklist]
- [ ] item A
- [ ] item B
\`\`\`
- [x] item 1
- [ ] item 2
text after list`

it('enables checklists by default', () => {
Expand Down Expand Up @@ -75,6 +99,21 @@ text after list`
await waitFor(() => expect(onChangeMock).toHaveBeenCalledWith(firstItemCheckedMarkdown))
})

it('calls `onChange` with the updated Markdown when a task is checked and hierarchy is present', async () => {
const onChangeMock = jest.fn()
const {getAllByRole} = render(
<MarkdownViewer
dangerousRenderedHTML={htmlObject}
markdownValue={hierarchyBeforeTaskListNoItemsChecked}
onChange={onChangeMock}
disabled
/>
)
const items = getAllByRole('checkbox')
fireEvent.change(items[0])
await waitFor(() => expect(onChangeMock).toHaveBeenCalledWith(hierarchyBeforeTaskListOneItemChecked))
})

it('calls `onChange` with the updated Markdown when a task is unchecked', async () => {
const onChangeMock = jest.fn()
const {getAllByRole} = render(
Expand Down

0 comments on commit b456e32

Please sign in to comment.