Skip to content

Importing multiple thoughts overwrites siblings #832

@raineorshine

Description

@raineorshine

Steps to Reproduce

  • a
    • b [cursor]

Paste two or more thoughts at once:

- x
- y

Current Behavior

  • a
    • x
    • y

(b is still in thoughtIndex)

Expected Behavior

  • a
    • b
    • x
    • y

Tests

Write a failing unit test (recommend doing this first for TDD). Test that both contextIndex and thoughtIndex are correct after pasting.

This is a rough draft of a unit test for importHtml.js but it is failing differently than I expected. You will have to fix this or write your own.

it('paste multiple thoughts after the cursor', () => {

  /** Import HTML and merge into state. */
  const importHtmlReducer = (state, insertionPath, html) => {
    const { contextIndexUpdates, thoughtIndexUpdates } = importHtml(state, insertionPath, html)
    return {
      ...state,
      thoughts: {
        contextIndex: contextIndexUpdates,
        thoughtIndex: thoughtIndexUpdates,
      }
    }
  }

  const initialHtml = `
<li>a<ul>
  <li>b</li>
</ul></li>
`

  const importedHtml = `
<li>x</li>
<li>y</li>
`

  const state1 = importHtmlReducer(initialState, RANKED_ROOT, initialHtml)
  const state2 = importHtmlReducer(state1, [{ value: 'a', rank: 0 }, { value: 'b', rank: 1 }], importedHtml)

  const exported = exportContext(state2, [ROOT_TOKEN], 'text/plaintext')

  expect(exported).toBe(`- __ROOT__
  - a
    - b
    - x
    - y`)
})

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions