|
|
@@ -16,7 +16,7 @@ import TableEditing from '../../src/tableediting';
|
|
|
import { viewTable } from '../_utils/utils';
|
|
|
|
|
|
describe( 'Table cell refresh post-fixer', () => {
|
|
|
- let editor, model, doc, root, view, refreshItemSpy, element;
|
|
|
+ let editor, model, doc, root, view, element;
|
|
|
|
|
|
testUtils.createSinonSandbox();
|
|
|
|
|
|
@@ -40,8 +40,6 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
model.schema.extend( '$block', { allowAttributes: [ 'foo', 'bar' ] } );
|
|
|
editor.conversion.attributeToAttribute( { model: 'foo', view: 'foo' } );
|
|
|
editor.conversion.attributeToAttribute( { model: 'bar', view: 'bar' } );
|
|
|
-
|
|
|
- refreshItemSpy = sinon.spy( model.document.differ, 'refreshItem' );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
@@ -50,10 +48,15 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
return editor.destroy();
|
|
|
} );
|
|
|
|
|
|
- it( 'should rename <span> to <p> when adding <paragraph> element to the same table cell', () => {
|
|
|
+ function getViewForParagraph( table ) {
|
|
|
+ return editor.editing.mapper.toViewElement( table.getNodeByPath( [ 0, 0, 0 ] ) );
|
|
|
+ }
|
|
|
+
|
|
|
+ it( 'should rename <span> to <p> when adding <paragraph> element to the same table cell (append)', () => {
|
|
|
editor.setData( viewTable( [ [ '<p>00</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
const nodeByPath = table.getNodeByPath( [ 0, 0, 0 ] );
|
|
|
@@ -66,13 +69,33 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<p>00</p><p></p>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should rename <span> to <p> when adding <paragraph> element to the same table cell (prepend)', () => {
|
|
|
+ editor.setData( viewTable( [ [ '<p>00</p>' ] ] ) );
|
|
|
+
|
|
|
+ const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ const nodeByPath = table.getNodeByPath( [ 0, 0, 0 ] );
|
|
|
+ const paragraph = writer.createElement( 'paragraph' );
|
|
|
+
|
|
|
+ writer.insert( paragraph, nodeByPath, 'before' );
|
|
|
+ } );
|
|
|
+
|
|
|
+ assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
+ [ '<p></p><p>00</p>' ]
|
|
|
+ ], { asWidget: true } ) );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should rename <span> to <p> when adding more <paragraph> elements to the same table cell', () => {
|
|
|
editor.setData( viewTable( [ [ '<p>00</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
const nodeByPath = table.getNodeByPath( [ 0, 0, 0 ] );
|
|
|
@@ -87,13 +110,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<p>00</p><p></p><p></p>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should rename <span> to <p> on adding other block element to the same table cell', () => {
|
|
|
editor.setData( viewTable( [ [ '<p>00</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
const nodeByPath = table.getNodeByPath( [ 0, 0, 0 ] );
|
|
|
@@ -106,13 +130,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<p>00</p><div></div>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should rename <span> to <p> on adding multiple other block elements to the same table cell', () => {
|
|
|
editor.setData( viewTable( [ [ '<p>00</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
const nodeByPath = table.getNodeByPath( [ 0, 0, 0 ] );
|
|
|
@@ -127,13 +152,34 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<p>00</p><div></div><div></div>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should not rename <span> to <p> when adding and removing <paragraph>', () => {
|
|
|
+ editor.setData( '<table><tr><td><p>00</p></td></tr></table>' );
|
|
|
+
|
|
|
+ const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
+
|
|
|
+ model.change( writer => {
|
|
|
+ const nodeByPath = table.getNodeByPath( [ 0, 0, 0 ] );
|
|
|
+ const paragraph = writer.createElement( 'paragraph' );
|
|
|
+
|
|
|
+ writer.insert( paragraph, nodeByPath, 'after' );
|
|
|
+ writer.remove( table.getNodeByPath( [ 0, 0, 1 ] ) );
|
|
|
+ } );
|
|
|
+
|
|
|
+ assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
+ [ '00' ]
|
|
|
+ ], { asWidget: true } ) );
|
|
|
+ expect( getViewForParagraph( table ) ).to.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should properly rename the same element on consecutive changes', () => {
|
|
|
editor.setData( viewTable( [ [ '<p>00</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
const nodeByPath = table.getNodeByPath( [ 0, 0, 0 ] );
|
|
|
@@ -146,7 +192,6 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<p>00</p><p></p>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.remove( table.getNodeByPath( [ 0, 0, 1 ] ) );
|
|
|
@@ -155,13 +200,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '00' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.calledTwice( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should rename <span> to <p> when setting attribute on <paragraph>', () => {
|
|
|
editor.setData( '<table><tr><td><p>00</p></td></tr></table>' );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.setAttribute( 'foo', 'bar', table.getNodeByPath( [ 0, 0, 0 ] ) );
|
|
|
@@ -170,13 +216,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<p foo="bar">00</p>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should rename <p> to <span> when removing one of two paragraphs inside table cell', () => {
|
|
|
editor.setData( viewTable( [ [ '<p>00</p><p>foo</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.remove( table.getNodeByPath( [ 0, 0, 1 ] ) );
|
|
|
@@ -185,13 +232,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '00' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should rename <p> to <span> when removing all but one paragraph inside table cell', () => {
|
|
|
editor.setData( viewTable( [ [ '<p>00</p><p>foo</p><p>bar</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.remove( table.getNodeByPath( [ 0, 0, 1 ] ) );
|
|
|
@@ -201,13 +249,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '00' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should rename <p> to <span> when removing attribute from <paragraph>', () => {
|
|
|
editor.setData( '<table><tr><td><p foo="bar">00</p></td></tr></table>' );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.removeAttribute( 'foo', table.getNodeByPath( [ 0, 0, 0 ] ) );
|
|
|
@@ -216,13 +265,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<span style="display:inline-block">00</span>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should keep <p> in the view when <paragraph> attribute value is changed', () => {
|
|
|
editor.setData( viewTable( [ [ '<p foo="bar">00</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.setAttribute( 'foo', 'baz', table.getNodeByPath( [ 0, 0, 0 ] ) );
|
|
|
@@ -231,14 +281,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<p foo="baz">00</p>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- // False positive: should not be called.
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should keep <p> in the view when adding another attribute to a <paragraph> with other attributes', () => {
|
|
|
editor.setData( viewTable( [ [ '<p foo="bar">00</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.setAttribute( 'bar', 'bar', table.getNodeByPath( [ 0, 0, 0 ] ) );
|
|
|
@@ -247,15 +297,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<p bar="bar" foo="bar">00</p>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
-
|
|
|
- // False positive
|
|
|
- sinon.assert.notCalled( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should keep <p> in the view when adding another attribute to a <paragraph> and removing attribute that is already set', () => {
|
|
|
editor.setData( viewTable( [ [ '<p foo="bar">00</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.setAttribute( 'bar', 'bar', table.getNodeByPath( [ 0, 0, 0 ] ) );
|
|
|
@@ -265,14 +314,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<p bar="bar">00</p>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- // False positive: should not be called.
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should keep <p> in the view when <paragraph> attribute value is changed (table cell with multiple blocks)', () => {
|
|
|
editor.setData( viewTable( [ [ '<p foo="bar">00</p><p>00</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.setAttribute( 'foo', 'baz', table.getNodeByPath( [ 0, 0, 0 ] ) );
|
|
|
@@ -281,13 +330,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<p foo="baz">00</p><p>00</p>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.notCalled( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should do nothing on rename <paragraph> to other block', () => {
|
|
|
editor.setData( viewTable( [ [ '<p>00</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.rename( table.getNodeByPath( [ 0, 0, 0 ] ), 'block' );
|
|
|
@@ -296,13 +346,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<div>00</div>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.notCalled( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should do nothing on adding <paragraph> to existing paragraphs', () => {
|
|
|
editor.setData( viewTable( [ [ '<p>a</p><p>b</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.insertElement( 'paragraph', table.getNodeByPath( [ 0, 0, 1 ] ), 'after' );
|
|
|
@@ -311,13 +362,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<p>a</p><p>b</p><p></p>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.notCalled( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should do nothing when setting attribute on block item other then <paragraph>', () => {
|
|
|
editor.setData( viewTable( [ [ '<div>foo</div>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.setAttribute( 'foo', 'bar', table.getNodeByPath( [ 0, 0, 0 ] ) );
|
|
|
@@ -326,13 +378,14 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<div foo="bar">foo</div>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.notCalled( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should rename <p> in to <span> when removing <paragraph> (table cell with 2 paragraphs)', () => {
|
|
|
editor.setData( viewTable( [ [ '<p>00</p><p>00</p>' ] ] ) );
|
|
|
|
|
|
const table = root.getChild( 0 );
|
|
|
+ const previousView = getViewForParagraph( table );
|
|
|
|
|
|
model.change( writer => {
|
|
|
writer.remove( writer.createRangeOn( table.getNodeByPath( [ 0, 0, 1 ] ) ) );
|
|
|
@@ -341,7 +394,7 @@ describe( 'Table cell refresh post-fixer', () => {
|
|
|
assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
|
|
|
[ '<span style="display:inline-block">00</span>' ]
|
|
|
], { asWidget: true } ) );
|
|
|
- sinon.assert.calledOnce( refreshItemSpy );
|
|
|
+ expect( getViewForParagraph( table ) ).to.not.equal( previousView );
|
|
|
} );
|
|
|
|
|
|
it( 'should update view selection after deleting content', () => {
|