@@ -17,7 +17,7 @@ import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictest
1717import Delete from '@ckeditor/ckeditor5-typing/src/delete' ;
1818
1919describe ( 'Table cell refresh post-fixer' , ( ) => {
20- let editor , model , doc , root , view ;
20+ let editor , model , doc , root , view , refreshItemSpy ;
2121
2222 testUtils . createSinonSandbox ( ) ;
2323
@@ -44,10 +44,12 @@ describe( 'Table cell refresh post-fixer', () => {
4444 } ) ;
4545 editor . conversion . elementToElement ( { model : 'block' , view : 'div' } ) ;
4646
47- model . schema . extend ( '$block' , { allowAttributes : 'foo' } ) ;
47+ model . schema . extend ( '$block' , { allowAttributes : [ 'foo' , 'bar' ] } ) ;
4848 editor . conversion . attributeToAttribute ( { model : 'foo' , view : 'foo' } ) ;
49+ editor . conversion . attributeToAttribute ( { model : 'bar' , view : 'bar' } ) ;
4950
5051 injectTableCellRefreshPostFixer ( model ) ;
52+ refreshItemSpy = sinon . spy ( model . document . differ , 'refreshItem' ) ;
5153 } ) ;
5254 } ) ;
5355
@@ -69,6 +71,7 @@ describe( 'Table cell refresh post-fixer', () => {
6971 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
7072 [ '<p>00</p><p></p>' ]
7173 ] , { asWidget : true } ) ) ;
74+ sinon . assert . calledOnce ( refreshItemSpy ) ;
7275 } ) ;
7376
7477 it ( 'should rename <span> to <p> on adding other block element to the same table cell' , ( ) => {
@@ -89,6 +92,7 @@ describe( 'Table cell refresh post-fixer', () => {
8992 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
9093 [ '<p>00</p><div></div>' ]
9194 ] , { asWidget : true } ) ) ;
95+ sinon . assert . calledOnce ( refreshItemSpy ) ;
9296 } ) ;
9397
9498 it ( 'should properly rename the same element on consecutive changes' , ( ) => {
@@ -107,6 +111,7 @@ describe( 'Table cell refresh post-fixer', () => {
107111 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
108112 [ '<p>00</p><p></p>' ]
109113 ] , { asWidget : true } ) ) ;
114+ sinon . assert . calledOnce ( refreshItemSpy ) ;
110115
111116 model . change ( writer => {
112117 writer . remove ( table . getNodeByPath ( [ 0 , 0 , 1 ] ) ) ;
@@ -115,6 +120,7 @@ describe( 'Table cell refresh post-fixer', () => {
115120 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
116121 [ '00' ]
117122 ] , { asWidget : true } ) ) ;
123+ sinon . assert . calledTwice ( refreshItemSpy ) ;
118124 } ) ;
119125
120126 it ( 'should rename <span> to <p> when setting attribute on <paragraph>' , ( ) => {
@@ -129,6 +135,7 @@ describe( 'Table cell refresh post-fixer', () => {
129135 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
130136 [ '<p foo="bar">00</p>' ]
131137 ] , { asWidget : true } ) ) ;
138+ sinon . assert . calledOnce ( refreshItemSpy ) ;
132139 } ) ;
133140
134141 it ( 'should rename <p> to <span> when removing all but one paragraph inside table cell' , ( ) => {
@@ -143,6 +150,7 @@ describe( 'Table cell refresh post-fixer', () => {
143150 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
144151 [ '00' ]
145152 ] , { asWidget : true } ) ) ;
153+ sinon . assert . calledOnce ( refreshItemSpy ) ;
146154 } ) ;
147155
148156 it ( 'should rename <p> to <span> when removing attribute from <paragraph>' , ( ) => {
@@ -157,6 +165,7 @@ describe( 'Table cell refresh post-fixer', () => {
157165 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
158166 [ '<span>00</span>' ]
159167 ] , { asWidget : true } ) ) ;
168+ sinon . assert . calledOnce ( refreshItemSpy ) ;
160169 } ) ;
161170
162171 it ( 'should keep <p> in the view when <paragraph> attribute value is changed' , ( ) => {
@@ -171,6 +180,42 @@ describe( 'Table cell refresh post-fixer', () => {
171180 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
172181 [ '<p foo="baz">00</p>' ]
173182 ] , { asWidget : true } ) ) ;
183+ // False positive: should not be called.
184+ sinon . assert . calledOnce ( refreshItemSpy ) ;
185+ } ) ;
186+
187+ it ( 'should keep <p> in the view when adding another attribute to a <paragraph> with other attributes' , ( ) => {
188+ editor . setData ( viewTable ( [ [ '<p foo="bar">00</p>' ] ] ) ) ;
189+
190+ const table = root . getChild ( 0 ) ;
191+
192+ model . change ( writer => {
193+ writer . setAttribute ( 'bar' , 'bar' , table . getNodeByPath ( [ 0 , 0 , 0 ] ) ) ;
194+ } ) ;
195+
196+ expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
197+ [ '<p bar="bar" foo="bar">00</p>' ]
198+ ] , { asWidget : true } ) ) ;
199+
200+ // False positive
201+ sinon . assert . notCalled ( refreshItemSpy ) ;
202+ } ) ;
203+
204+ it ( 'should keep <p> in the view when adding another attribute to a <paragraph> and removing attribute that is already set' , ( ) => {
205+ editor . setData ( viewTable ( [ [ '<p foo="bar">00</p>' ] ] ) ) ;
206+
207+ const table = root . getChild ( 0 ) ;
208+
209+ model . change ( writer => {
210+ writer . setAttribute ( 'bar' , 'bar' , table . getNodeByPath ( [ 0 , 0 , 0 ] ) ) ;
211+ writer . removeAttribute ( 'foo' , table . getNodeByPath ( [ 0 , 0 , 0 ] ) ) ;
212+ } ) ;
213+
214+ expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
215+ [ '<p bar="bar">00</p>' ]
216+ ] , { asWidget : true } ) ) ;
217+ // False positive: should not be called.
218+ sinon . assert . calledOnce ( refreshItemSpy ) ;
174219 } ) ;
175220
176221 it ( 'should keep <p> in the view when <paragraph> attribute value is changed (table cell with multiple blocks)' , ( ) => {
@@ -185,6 +230,7 @@ describe( 'Table cell refresh post-fixer', () => {
185230 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
186231 [ '<p foo="baz">00</p><p>00</p>' ]
187232 ] , { asWidget : true } ) ) ;
233+ sinon . assert . notCalled ( refreshItemSpy ) ;
188234 } ) ;
189235
190236 it ( 'should do nothing on rename <paragraph> to other block' , ( ) => {
@@ -199,6 +245,7 @@ describe( 'Table cell refresh post-fixer', () => {
199245 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
200246 [ '<div>00</div>' ]
201247 ] , { asWidget : true } ) ) ;
248+ sinon . assert . notCalled ( refreshItemSpy ) ;
202249 } ) ;
203250
204251 it ( 'should do nothing when setting attribute on block item other then <paragraph>' , ( ) => {
@@ -213,9 +260,10 @@ describe( 'Table cell refresh post-fixer', () => {
213260 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
214261 [ '<div foo="bar">foo</div>' ]
215262 ] , { asWidget : true } ) ) ;
263+ sinon . assert . notCalled ( refreshItemSpy ) ;
216264 } ) ;
217265
218- it ( 'should keep <p> in the view when <paragraph> attribute value is changed (table cell with multiple blocks )' , ( ) => {
266+ it ( 'should rename <p> in to <span> when removing <paragraph> (table cell with 2 paragraphs )' , ( ) => {
219267 editor . setData ( viewTable ( [ [ '<p>00</p><p>00</p>' ] ] ) ) ;
220268
221269 const table = root . getChild ( 0 ) ;
@@ -227,6 +275,7 @@ describe( 'Table cell refresh post-fixer', () => {
227275 expect ( formatTable ( getViewData ( view , { withoutSelection : true } ) ) ) . to . equal ( formattedViewTable ( [
228276 [ '<span>00</span>' ]
229277 ] , { asWidget : true } ) ) ;
278+ sinon . assert . calledOnce ( refreshItemSpy ) ;
230279 } ) ;
231280
232281 it ( 'should update view selection after deleting content' , ( ) => {
0 commit comments