-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from bustlelabs/editor-section-tests
Editor section tests
- Loading branch information
Showing
8 changed files
with
210 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { Editor } from 'content-kit-editor'; | ||
import Helpers from '../test-helpers'; | ||
|
||
const { test, module } = QUnit; | ||
|
||
const newline = '\r\n'; | ||
|
||
let fixture, editor, editorElement; | ||
const mobileDocWith1Section = [ | ||
[], | ||
[ | ||
[1, "P", [ | ||
[[], 0, "only section"] | ||
]] | ||
] | ||
]; | ||
const mobileDocWith2Sections = [ | ||
[], | ||
[ | ||
[1, "P", [ | ||
[[], 0, "first section"] | ||
]], | ||
[1, "P", [ | ||
[[], 0, "second section"] | ||
]] | ||
] | ||
]; | ||
const mobileDocWith3Sections = [ | ||
[], | ||
[ | ||
[1, "P", [ | ||
[[], 0, "first section"] | ||
]], | ||
[1, "P", [ | ||
[[], 0, "second section"] | ||
]], | ||
[1, "P", [ | ||
[[], 0, "third section"] | ||
]] | ||
] | ||
]; | ||
|
||
module('Acceptance: Editor sections', { | ||
beforeEach() { | ||
fixture = document.getElementById('qunit-fixture'); | ||
editorElement = document.createElement('div'); | ||
editorElement.setAttribute('id', 'editor'); | ||
fixture.appendChild(editorElement); | ||
}, | ||
|
||
afterEach() { | ||
editor.destroy(); | ||
} | ||
}); | ||
|
||
test('typing inserts section', (assert) => { | ||
editor = new Editor(editorElement, {mobiledoc: mobileDocWith1Section}); | ||
assert.equal($('#editor p').length, 1, 'has 1 paragraph to start'); | ||
|
||
const text = 'new section'; | ||
|
||
Helpers.dom.moveCursorTo(editorElement); | ||
document.execCommand('insertText', false, text + newline); | ||
|
||
assert.equal($('#editor p').length, 2, 'has 2 paragraphs after typing return'); | ||
assert.hasElement(`#editor p:contains(${text})`, 'has first pargraph with "A"'); | ||
assert.hasElement('#editor p:contains(only section)', 'has correct second paragraph text'); | ||
}); | ||
|
||
test('deleting across 0 sections merges them', (assert) => { | ||
editor = new Editor(editorElement, {mobiledoc: mobileDocWith2Sections}); | ||
assert.equal($('#editor p').length, 2, 'precond - has 2 sections to start'); | ||
|
||
const p0 = $('#editor p:eq(0)')[0], | ||
p1 = $('#editor p:eq(1)')[0]; | ||
|
||
Helpers.dom.selectText('tion', p0, 'sec', p1); | ||
document.execCommand('delete', false); | ||
|
||
assert.equal($('#editor p').length, 1, 'has only 1 paragraph after deletion'); | ||
assert.hasElement('#editor p:contains(first second section)', | ||
'remaining paragraph has correct text'); | ||
}); | ||
|
||
test('deleting across 1 section removes it, joins the 2 boundary sections', (assert) => { | ||
editor = new Editor(editorElement, {mobiledoc: mobileDocWith3Sections}); | ||
assert.equal($('#editor p').length, 3, 'precond - has 3 paragraphs to start'); | ||
|
||
const p0 = $('#editor p:eq(0)')[0], | ||
p1 = $('#editor p:eq(1)')[0], | ||
p2 = $('#editor p:eq(2)')[0]; | ||
assert.ok(p0 && p1 && p2, 'precond - paragraphs exist'); | ||
|
||
Helpers.dom.selectText('section', p0, 'third ', p2); | ||
|
||
document.execCommand('delete', false); | ||
|
||
|
||
assert.equal($('#editor p').length, 1, 'has only 1 paragraph after deletion'); | ||
assert.hasElement('#editor p:contains(first section)', | ||
'remaining paragraph has correct text'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.