Skip to content

Commit

Permalink
Tests: Code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Feb 15, 2023
1 parent 80181a3 commit 7402b6a
Showing 1 changed file with 50 additions and 52 deletions.
102 changes: 50 additions & 52 deletions packages/ckeditor5-mention/tests/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,70 +300,68 @@ describe( 'MentionUI', () => {
} );
} );

describe( 'contextual balloon in rtl', () => {
let contextualBaloonSpy;
describe( 'relation with the UI language direction of the editor', () => {
describe( 'for RTL languages', () => {
let contextualBaloonSpy;

beforeEach( async () => {
await editor.destroy();

return createClassicTestEditor( { ...staticConfig } )
.then( () => {
const contextualBalloon = editor.plugins.get( ContextualBalloon );
setData( model, '<paragraph>foo []</paragraph>' );
editor.locale.uiLanguageDirection = 'rtl';
contextualBaloonSpy = sinon.spy( contextualBalloon, 'add' );
beforeEach( async () => {
await editor.destroy();

model.change( writer => {
writer.insertText( '@', doc.selection.getFirstPosition() );
} );
} )
.then( waitForDebounce );
} );
return createClassicTestEditor( { ...staticConfig } )
.then( () => {
const contextualBalloon = editor.plugins.get( ContextualBalloon );
setData( model, '<paragraph>foo []</paragraph>' );
editor.locale.uiLanguageDirection = 'rtl';
contextualBaloonSpy = sinon.spy( contextualBalloon, 'add' );

it( 'should set proper position list in rtl', () => {
const extractedPositions = contextualBaloonSpy.getCall( 0 ).firstArg.position.positions.map( callback => {
return callback( {}, {} ).name;
model.change( writer => {
writer.insertText( '@', doc.selection.getFirstPosition() );
} );
} )
.then( waitForDebounce );
} );

expect( extractedPositions ).to.have.ordered.members( [
'caret_sw',
'caret_se',
'caret_nw',
'caret_ne'
] );
} );
} );
it( 'should prefer the west position first (to the left of the caret)', () => {
const positionNames = contextualBaloonSpy.firstCall.firstArg.position.positions.map( ( { name } ) => name );

describe( 'contextual balloon in ltr', () => {
let contextualBaloonSpy;
expect( positionNames ).to.have.ordered.members( [
'caret_sw',
'caret_se',
'caret_nw',
'caret_ne'
] );
} );
} );

beforeEach( async () => {
await editor.destroy();
describe( 'for ltr languages', () => {
let contextualBaloonSpy;

return createClassicTestEditor( { ...staticConfig } )
.then( () => {
const contextualBalloon = editor.plugins.get( ContextualBalloon );
setData( model, '<paragraph>foo []</paragraph>' );
contextualBaloonSpy = sinon.spy( contextualBalloon, 'add' );
beforeEach( async () => {
await editor.destroy();

model.change( writer => {
writer.insertText( '@', doc.selection.getFirstPosition() );
} );
} )
.then( waitForDebounce );
} );
return createClassicTestEditor( { ...staticConfig } )
.then( () => {
const contextualBalloon = editor.plugins.get( ContextualBalloon );
setData( model, '<paragraph>foo []</paragraph>' );
contextualBaloonSpy = sinon.spy( contextualBalloon, 'add' );

it( 'should set proper position list in ltr', () => {
const extractedPositions = contextualBaloonSpy.getCall( 0 ).firstArg.position.positions.map( callback => {
return callback( {}, {} ).name;
model.change( writer => {
writer.insertText( '@', doc.selection.getFirstPosition() );
} );
} )
.then( waitForDebounce );
} );

expect( extractedPositions ).to.have.ordered.members( [
'caret_se',
'caret_sw',
'caret_ne',
'caret_nw'
] );
it( 'should prefer the east position first (to the right of the caret)', () => {
const positionNames = contextualBaloonSpy.firstCall.firstArg.position.positions.map( ( { name } ) => name );

expect( positionNames ).to.have.ordered.members( [
'caret_se',
'caret_sw',
'caret_ne',
'caret_nw'
] );
} );
} );
} );
} );
Expand Down

0 comments on commit 7402b6a

Please sign in to comment.