Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Unit tests for new editor #3247

Merged
merged 15 commits into from
Jul 30, 2019
Merged

Unit tests for new editor #3247

merged 15 commits into from
Jul 30, 2019

Conversation

bwindels
Copy link
Contributor

@bwindels bwindels commented Jul 25, 2019

For element-hq/element-web#9868

Added 69 tests
  editor/caret: DOM position for caret
    basic text handling
      ✓ at end of single line (1ms)
      ✓ at start of single line (1ms)
      ✓ at middle of single line (0ms)
    handling line breaks
      ✓ at end of last line (0ms)
      ✓ at start of last line (1ms)
      ✓ in empty line (0ms)
      ✓ after empty line (0ms)
    handling non-editable parts and caret nodes
      ✓ at start of non-editable part (with plain text around) (1ms)
      ✓ in middle of non-editable part (with plain text around) (0ms)
      ✓ at start of non-editable part (without plain text around) (1ms)
      ✓ in middle of non-editable part (without plain text around) (0ms)
      ✓ in middle of a first non-editable part, with another one following (0ms)
      ✓ in start of a second non-editable part, with another one before it (1ms)
      ✓ in middle of a second non-editable part, with another one before it (0ms)

editor/deserialize
text messages
✓ test with newlines (1ms)
✓ @room pill (0ms)
✓ emote (0ms)
html messages
✓ inline styling (1ms)
✓ hyperlink (1ms)
✓ multiple lines with paragraphs (1ms)
✓ multiple lines with line breaks (1ms)
✓ multiple lines mixing paragraphs and line breaks (1ms)
✓ quote (1ms)
✓ user pill (0ms)
✓ room pill (0ms)
✓ @room pill (1ms)
✓ inline code (0ms)
✓ code block with no trailing text (1ms)
- code block with no trailing text and no newlines (0ms)
✓ unordered lists (1ms)
✓ ordered lists (1ms)
✓ mx-reply is stripped (0ms)
✓ emote (1ms)

editor/diff
diffDeletion
✓ at start of string (0ms)
✓ removing whole string (0ms)
✓ in middle of string (0ms)
✓ in middle of string with duplicate character (0ms)
✓ at end of string (7ms)
diffAtCaret
✓ insert at start (0ms)
✓ insert at end (1ms)
✓ insert in middle (0ms)
✓ replace at start (1ms)
✓ replace at end (0ms)
✓ replace in middle (1ms)
✓ remove at start of string (0ms)
✓ removing whole string (1ms)
✓ remove in middle of string (0ms)
✓ forwards remove in middle of string (0ms)
✓ forwards remove in middle of string with duplicate character (0ms)
✓ remove at end of string (0ms)

editor/model
plain text manipulation
✓ insert text into empty document (2ms)
✓ append text to existing document (1ms)
✓ prepend text to existing document (0ms)
handling line breaks
✓ insert new line into existing document (1ms)
✓ insert multiple new lines into existing document (1ms)
✓ type in empty line (1ms)
non-editable part manipulation
✓ typing at start of non-editable part prepends (1ms)
✓ typing in middle of non-editable part appends (0ms)
✓ remove non-editable part with backspace (1ms)
✓ remove non-editable part with delete (0ms)
auto-complete
✓ insert user pill (2ms)
✓ insert room pill (1ms)
✓ type after inserting pill (1ms)
✓ pasting text does not trigger auto-complete (0ms)
✓ dropping text does not trigger auto-complete (0ms)

editor/serialize
✓ user pill turns message into html (4ms)
✓ room pill turns message into html (1ms)
✓ @room pill turns message into html (0ms)
✓ any markdown turns message into html (1ms)

@bwindels bwindels requested a review from a team July 25, 2019 16:48
@turt2live turt2live requested review from turt2live and removed request for a team July 29, 2019 15:22
Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't verified that the tests test the behaviour we want, but they do seem to do the right thing and you're probably the person who knows best anyways.

import {diffDeletion} from "../../src/editor/diff";

describe('editor/diff', function() {
describe('diffDeletion', function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be good to have tests for multiple characters as well, just in case we've over-engineered it to work with single character diffs

* @param {String} oldValue the previous value
* @param {String} newValue the new value
* @param {Number} caretPosition the position of the caret after `newValue` was applied.
* @return {object}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have a description

@bwindels bwindels requested a review from turt2live July 30, 2019 10:35
Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, I think. Still haven't checked the test cases themselves, just that they look like code.

* @return {object}
* @return {object} an object with `at` as the offset where characters were removed and/or added,
* `added` with the added string (if any), and
* `removed` with the removed string (if any)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we seem inconsistent in our jsdoc: sometimes we put newlines directly against the * but other times we indent like this. I'm indifferent, but just something I think we should consider in the future.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants