-
Notifications
You must be signed in to change notification settings - Fork 4
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 #4 from alexeckermann/tests
v0.2.0 Change to CSS selectors
- Loading branch information
Showing
8 changed files
with
223 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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,110 @@ | ||
import Emptyness from '../src/emptyness'; | ||
|
||
import ModelText from '@ckeditor/ckeditor5-engine/src/model/text'; | ||
import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range'; | ||
|
||
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; | ||
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; | ||
|
||
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; | ||
import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; | ||
|
||
testUtils.createSinonSandbox(); | ||
|
||
describe( 'Emptyness', () => { | ||
let editor, editorElement; | ||
|
||
const insertContent = () => { | ||
|
||
editor.model.change( writer => { | ||
writer.setSelection( ModelRange.createIn( editor.model.document.getRoot().getChild( 0 ) ) ); | ||
editor.model.insertContent( new ModelText( 'test' ), editor.model.document.selection ); | ||
} ); | ||
|
||
}; | ||
|
||
const removeAllContent = () => { | ||
|
||
editor.model.change( writer => { | ||
writer.setSelection( ModelRange.createIn( editor.model.document.getRoot().getChild( 0 ) ) ); | ||
editor.model.deleteContent( editor.model.document.selection ); | ||
} ); | ||
|
||
}; | ||
|
||
beforeEach( () => { | ||
editorElement = document.createElement( 'div' ); | ||
document.body.appendChild( editorElement ); | ||
|
||
return ClassicTestEditor | ||
.create( editorElement, { | ||
plugins: [ Emptyness, Paragraph ] | ||
} ) | ||
.then( newEditor => { | ||
editor = newEditor; | ||
} ); | ||
} ); | ||
|
||
afterEach( () => { | ||
editorElement.remove(); | ||
|
||
return editor.destroy(); | ||
} ); | ||
|
||
it( 'should be loaded', () => { | ||
expect( editor.plugins.get( Emptyness ) ).to.be.instanceOf( Emptyness ); | ||
} ); | ||
|
||
describe( 'init()', () => { | ||
|
||
it( 'should set the isEmpty property', () => { | ||
expect( editor.isEmpty ).to.be.true; | ||
} ); | ||
|
||
} ); | ||
|
||
describe( 'isEmpty lifecycle', () => { | ||
|
||
it( 'should be false when content is inserted', () => { | ||
const setSpy = testUtils.sinon.spy( editor, 'set' ); | ||
|
||
insertContent(); | ||
|
||
sinon.assert.calledWithExactly( setSpy, 'isEmpty', false ); | ||
} ); | ||
|
||
it( 'should be true when all content is emptied', () => { | ||
setData( editor.model, '<paragraph>test{}</paragraph>' ); | ||
|
||
const setSpy = testUtils.sinon.spy( editor, 'set' ); | ||
|
||
removeAllContent(); | ||
|
||
sinon.assert.calledWithExactly( setSpy, 'isEmpty', true ); | ||
} ); | ||
|
||
} ); | ||
|
||
describe( 'view class lifecycle', () => { | ||
|
||
it( 'should not have the empty class content is inserted', () => { | ||
expect( editor.ui.view.element.classList.contains('ck-editor__is-empty') ).to.be.true; | ||
|
||
insertContent(); | ||
|
||
expect( editor.ui.view.element.classList.contains('ck-editor__is-empty') ).to.be.false; | ||
} ); | ||
|
||
it( 'should add the empty class when all content is emptied', () => { | ||
setData( editor.model, '<paragraph>test{}</paragraph>' ); | ||
|
||
expect( editor.ui.view.element.classList.contains('ck-editor__is-empty') ).to.be.false; | ||
|
||
removeAllContent(); | ||
|
||
expect( editor.ui.view.element.classList.contains('ck-editor__is-empty') ).to.be.true; | ||
} ); | ||
|
||
} ); | ||
|
||
} ); |
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,17 @@ | ||
<head> | ||
<style> | ||
.ck-editor__is-empty .ck-content.ck-editor__editable::before, | ||
.ck-editor__is-empty.ck-content.ck-editor__editable::before { | ||
content: 'The editor is empty'; | ||
position: absolute; | ||
display: block; | ||
|
||
margin: var(--ck-spacing-large) 0; | ||
|
||
color: #aaa; | ||
} | ||
</style> | ||
</head> | ||
|
||
<div id="editor"> | ||
</div> |
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,15 @@ | ||
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; | ||
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials'; | ||
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; | ||
|
||
import Template from '@ckeditor/ckeditor5-ui/src/template'; | ||
import Emptyness from '../../src/emptyness'; | ||
|
||
ClassicEditor | ||
.create( document.querySelector( '#editor' ), { | ||
plugins: [ Essentials, Paragraph, Emptyness ], | ||
toolbar: [ ] | ||
} ) | ||
.then( editor => { | ||
window.editor = editor; | ||
} ); |
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,5 @@ | ||
1. Upon loading the page the editor should contain the placeholder text: `The editor is empty`. | ||
|
||
2. Type something and notice that the placeholder text disappears as expected. | ||
|
||
3. Remove all contentent in the editor and see the placeholder reappear. |