-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic test for pressing a letter in the editor
- Loading branch information
Showing
4 changed files
with
57 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* global QUnit */ | ||
|
||
import { Editor } from 'content-kit-editor'; | ||
import { moveCursorTo } from '../test-helpers'; | ||
|
||
const { test, module } = QUnit; | ||
|
||
let fixture, editor, editorElement; | ||
|
||
module('acceptance: basic editor', { | ||
beforeEach() { | ||
fixture = document.getElementById('qunit-fixture'); | ||
editorElement = document.createElement('div'); | ||
editorElement.setAttribute('id', 'editor'); | ||
fixture.appendChild(editorElement); | ||
}, | ||
afterEach() { | ||
} | ||
}); | ||
|
||
test('sets element as contenteditable', (assert) => { | ||
let innerHTML = `<p>Hello</p>`; | ||
editorElement.innerHTML = innerHTML; | ||
editor = new Editor('#editor'); | ||
|
||
assert.equal(editorElement.getAttribute('contenteditable'), | ||
'true', | ||
'element is contenteditable'); | ||
assert.equal(editorElement.firstChild.tagName, 'SECTION', | ||
`editor element has a section as its first child`); | ||
}); | ||
|
||
test('editing element changes editor post model', (assert) => { | ||
let innerHTML = `<p>Hello</p>`; | ||
editorElement.innerHTML = innerHTML; | ||
editor = new Editor('#editor'); | ||
|
||
let p = editorElement.querySelector('p'); | ||
let textElement = p.firstChild; | ||
|
||
moveCursorTo(textElement, 0); | ||
|
||
document.execCommand('insertText', false, 'A'); | ||
assert.equal(p.textContent, 'AHello'); | ||
}); |
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,9 @@ | ||
export function moveCursorTo(element, offset) { | ||
let range = document.createRange(); | ||
range.setStart(element, offset); | ||
range.setEnd(element, offset); | ||
|
||
let selection = window.getSelection(); | ||
selection.removeAllRanges(); | ||
selection.addRange(range); | ||
} |
File renamed without changes.