From 3d485371cfeba72a8b7f814a70d5f1dac8db4e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kup=C5=9B?= Date: Wed, 11 Oct 2017 14:47:35 +0200 Subject: [PATCH] Changed how removeHighlight is handled according do changes in engine. --- src/highlightstack.js | 12 ++++++------ src/utils.js | 2 +- tests/highlightstack.js | 6 +++--- tests/utils.js | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/highlightstack.js b/src/highlightstack.js index d139f140..3be940f0 100644 --- a/src/highlightstack.js +++ b/src/highlightstack.js @@ -54,13 +54,13 @@ export default class HighlightStack { * Removes highlight descriptor from the stack. * * @fires change:top - * @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} descriptor + * @param {String} id Id of the descriptor to remove. */ - remove( descriptor ) { + remove( id ) { const stack = this._stack; const oldTop = stack[ 0 ]; - this._removeDescriptor( descriptor ); + this._removeDescriptor( id ); const newTop = stack[ 0 ]; // When new object is at the top and stores different information. @@ -108,11 +108,11 @@ export default class HighlightStack { * Removes descriptor with given id from the stack. * * @private - * @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} descriptor + * @param {String} id Descriptor's id. */ - _removeDescriptor( descriptor ) { + _removeDescriptor( id ) { const stack = this._stack; - const index = stack.findIndex( item => item.id === descriptor.id ); + const index = stack.findIndex( item => item.id === id ); // If descriptor with same id is on the list - remove it. if ( index > -1 ) { diff --git a/src/utils.js b/src/utils.js index 0c482417..770e9d21 100644 --- a/src/utils.js +++ b/src/utils.js @@ -96,7 +96,7 @@ export function setHighlightHandling( element, add, remove ) { } ); element.setCustomProperty( 'addHighlight', ( element, descriptor ) => stack.add( descriptor ) ); - element.setCustomProperty( 'removeHighlight', ( element, descriptor ) => stack.remove( descriptor ) ); + element.setCustomProperty( 'removeHighlight', ( element, id ) => stack.remove( id ) ); } /** diff --git a/tests/highlightstack.js b/tests/highlightstack.js index 765026dc..bd65c267 100644 --- a/tests/highlightstack.js +++ b/tests/highlightstack.js @@ -79,7 +79,7 @@ describe( 'HighlightStack', () => { stack.on( 'change:top', spy ); - stack.remove( secondDescriptor ); + stack.remove( secondDescriptor.id ); sinon.assert.calledOnce( spy ); expect( spy.firstCall.args[ 1 ].oldDescriptor ).to.equal( secondDescriptor ); @@ -143,7 +143,7 @@ describe( 'HighlightStack', () => { stack.add( descriptor ); stack.on( 'change:top', spy ); - stack.remove( descriptor ); + stack.remove( descriptor.id ); sinon.assert.calledOnce( spy ); expect( spy.firstCall.args[ 1 ].newDescriptor ).to.be.undefined; @@ -158,7 +158,7 @@ describe( 'HighlightStack', () => { stack.add( descriptor ); stack.add( secondDescriptor ); stack.on( 'change:top', spy ); - stack.remove( secondDescriptor ); + stack.remove( secondDescriptor.id ); sinon.assert.notCalled( spy ); } ); diff --git a/tests/utils.js b/tests/utils.js index d43770eb..5cd70645 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -62,7 +62,7 @@ describe( 'widget utils', () => { set( element, { priority: 1, class: 'highlight', id: 'highlight' } ); expect( element.hasClass( 'highlight' ) ).to.be.true; - remove( element, { priority: 1, class: 'highlight', id: 'highlight' } ); + remove( element, 'highlight' ); expect( element.hasClass( 'highlight' ) ).to.be.false; } ); @@ -79,7 +79,7 @@ describe( 'widget utils', () => { expect( element.hasClass( 'highlight' ) ).to.be.true; expect( element.hasClass( 'foo' ) ).to.be.true; - remove( element, { priority: 1, class: [ 'foo', 'highlight' ], id: 'highlight' } ); + remove( element, 'highlight' ); expect( element.hasClass( 'highlight' ) ).to.be.false; expect( element.hasClass( 'foo' ) ).to.be.false; } ); @@ -177,7 +177,7 @@ describe( 'widget utils', () => { const descriptor = { priority: 10, class: 'highlight', id: 'highlight' }; set( element, descriptor ); - remove( element, descriptor ); + remove( element, descriptor.id ); sinon.assert.calledOnce( addSpy ); sinon.assert.calledWithExactly( addSpy, element, descriptor ); @@ -215,7 +215,7 @@ describe( 'widget utils', () => { set( element, descriptor ); set( element, secondDescriptor ); - remove( element, secondDescriptor ); + remove( element, secondDescriptor.id ); sinon.assert.calledThrice( addSpy ); expect( addSpy.firstCall.args[ 1 ] ).to.equal( descriptor );