Przeglądaj źródła

Fix mention ui tests.

Maciej Gołaszewski 6 lat temu
rodzic
commit
ce06f8c21b
1 zmienionych plików z 15 dodań i 11 usunięć
  1. 15 11
      packages/ckeditor5-mention/tests/mentionui.js

+ 15 - 11
packages/ckeditor5-mention/tests/mentionui.js

@@ -781,18 +781,12 @@ describe( 'MentionUI', () => {
 
 
 						sinon.assert.calledOnce( spy );
 						sinon.assert.calledOnce( spy );
 
 
-						const commandOptions = spy.getCall( 0 ).args[ 0 ];
-
-						const item = feedItems[ 4 ];
-
-						expect( commandOptions ).to.have.property( 'mention' ).that.deep.equal( item );
-						expect( commandOptions ).to.have.property( 'marker', '@' );
-						expect( commandOptions ).to.have.property( 'range' );
+						assertCommandOptions( spy.getCall( 0 ).args[ 0 ], '@', feedItems[ 4 ] );
 
 
 						const start = model.createPositionAt( doc.getRoot().getChild( 0 ), 4 );
 						const start = model.createPositionAt( doc.getRoot().getChild( 0 ), 4 );
 						const expectedRange = model.createRange( start, start.getShiftedBy( 1 ) );
 						const expectedRange = model.createRange( start, start.getShiftedBy( 1 ) );
 
 
-						expect( commandOptions.range.isEqual( expectedRange ) ).to.be.true;
+						expect( spy.getCall( 0 ).args[ 0 ].range.isEqual( expectedRange ) ).to.be.true;
 					} );
 					} );
 			} );
 			} );
 		}
 		}
@@ -819,9 +813,7 @@ describe( 'MentionUI', () => {
 
 
 					const commandOptions = spy.getCall( 0 ).args[ 0 ];
 					const commandOptions = spy.getCall( 0 ).args[ 0 ];
 
 
-					expect( commandOptions ).to.have.property( 'mention' ).that.deep.equal( { name: 'Barney' } );
-					expect( commandOptions ).to.have.property( 'marker', '@' );
-					expect( commandOptions ).to.have.property( 'range' );
+					assertCommandOptions( commandOptions, '@', { name: 'Barney' } );
 
 
 					const start = model.createPositionAt( doc.getRoot().getChild( 0 ), 4 );
 					const start = model.createPositionAt( doc.getRoot().getChild( 0 ), 4 );
 					const expectedRange = model.createRange( start, start.getShiftedBy( 1 ) );
 					const expectedRange = model.createRange( start, start.getShiftedBy( 1 ) );
@@ -909,4 +901,16 @@ describe( 'MentionUI', () => {
 
 
 		expect( childViews.map( child => child.isOn ) ).to.deep.equal( expectedState );
 		expect( childViews.map( child => child.isOn ) ).to.deep.equal( expectedState );
 	}
 	}
+
+	function assertCommandOptions( commandOptions, marker, item ) {
+		expect( commandOptions ).to.have.property( 'marker', marker );
+		expect( commandOptions ).to.have.property( 'range' );
+		expect( commandOptions ).to.have.property( 'mention' );
+
+		const mentionForCommand = commandOptions.mention;
+
+		for ( const key of Object.keys( item ) ) {
+			expect( mentionForCommand[ key ] ).to.equal( item[ key ] );
+		}
+	}
 } );
 } );