mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
Update getPath tests
This commit is contained in:
parent
9b75e26451
commit
1c9dc9ebb5
1 changed files with 70 additions and 0 deletions
|
@ -195,6 +195,76 @@ describe('Squire RTE', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('getPath', function () {
|
||||
var startHTML;
|
||||
beforeEach( function () {
|
||||
startHTML = '<div>one <b>two three</b> four <i>five</i></div>';
|
||||
editor.setHTML(startHTML);
|
||||
|
||||
var range = doc.createRange();
|
||||
range.setStart(doc.body.childNodes.item(0), 0);
|
||||
range.setEnd(doc.body.childNodes.item(0), 1);
|
||||
editor.setSelection(range);
|
||||
});
|
||||
|
||||
it('returns the path to the selection', function () {
|
||||
editor.insertHTML('<b>Bold Text</b>');
|
||||
expect(editor.getPath(), 'to be', 'DIV>B');
|
||||
});
|
||||
|
||||
it('includes id in the path', function () {
|
||||
editor.insertHTML('<div id="spanId">Text</div>');
|
||||
expect(editor.getPath(), 'to be', 'DIV#spanId');
|
||||
});
|
||||
|
||||
it('includes class name in the path', function () {
|
||||
editor.insertHTML('<div class="myClass">Text</div>');
|
||||
expect(editor.getPath(), 'to be', 'DIV.myClass');
|
||||
});
|
||||
|
||||
it('includes all class names in the path', function () {
|
||||
editor.insertHTML('<div class="myClass myClass2 myClass3">Text</div>');
|
||||
expect(editor.getPath(), 'to be', 'DIV.myClass.myClass2.myClass3');
|
||||
});
|
||||
|
||||
it('includes direction in the path', function () {
|
||||
editor.insertHTML('<div dir="rtl">Text</div>');
|
||||
expect(editor.getPath(), 'to be', 'DIV[dir=rtl]');
|
||||
});
|
||||
|
||||
it('includes highlight value in the path', function () {
|
||||
editor.insertHTML('<div class="highlight" style="background-color: rgb(255, 0, 0)">Text</div>');
|
||||
expect(editor.getPath(), 'to be', 'DIV.highlight[backgroundColor=rgb(255,0,0)]');
|
||||
});
|
||||
|
||||
it('includes color value in the path', function () {
|
||||
editor.insertHTML('<div class="colour" style="color: rgb(255, 0, 0)">Text</div>');
|
||||
expect(editor.getPath(), 'to be', 'DIV.colour[color=rgb(255,0,0)]');
|
||||
});
|
||||
|
||||
it('includes font family value in the path', function () {
|
||||
editor.insertHTML('<div class="font" style="font-family: Arial, sans-serif">Text</div>');
|
||||
expect(editor.getPath(), 'to be', 'DIV.font[fontFamily=Arial,sans-serif]');
|
||||
});
|
||||
|
||||
it('includes font size value in the path', function () {
|
||||
editor.insertHTML('<div class="size" style="font-size: 12pt">Text</div>');
|
||||
expect(editor.getPath(), 'to be', 'DIV.size[fontSize=12pt]');
|
||||
});
|
||||
|
||||
it('is (selection) when the selection is a range', function() {
|
||||
var range = doc.createRange();
|
||||
range.setStart(doc.body.childNodes.item(0).childNodes.item(0), 0);
|
||||
range.setEnd(doc.body.childNodes.item(0).childNodes.item(3), 0);
|
||||
editor.setSelection(range);
|
||||
|
||||
//Manually tell it to update the path
|
||||
editor._updatePath(range);
|
||||
|
||||
expect(editor.getPath(), 'to be', '(selection)');
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
editor = null;
|
||||
var iframe = document.getElementById('testFrame');
|
||||
|
|
Loading…
Reference in a new issue