Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Cleanup the 'should scroll mention panel to the selected item' test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Apr 19, 2019
1 parent b48c1ec commit 24b0f4c
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions tests/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ describe( 'MentionUI', () => {
} );
} );

it( 'should scroll mention panel to the selected item', function() {
it( 'should scroll mention panel to the selected item', () => {
setData( model, '<paragraph>foo []</paragraph>' );

model.change( writer => {
Expand All @@ -357,8 +357,6 @@ describe( 'MentionUI', () => {
stopPropagation: sinon.spy()
};

const elementSpies = [];

const mentionElementSpy = testUtils.sinon.spy( mentionsView.element, 'scrollTop', [ 'set' ] );

return waitForDebounce()
Expand All @@ -375,8 +373,6 @@ describe( 'MentionUI', () => {
const listItemElement = item.children.get( 0 ).element;

listItemElement.style = `min-height:unset;height:25px;max-height:25px;${ reset };min-width:12em;`;

elementSpies.push( testUtils.sinon.spy( listItemElement, 'offsetTop', [ 'get' ] ) );
} );

// ...so after those changes it is safe to assume that:
Expand All @@ -385,7 +381,6 @@ describe( 'MentionUI', () => {
// - if scrolled to the last element scrollTop will be set to 150px. The 150px is the offset of the 7th item in the
// list as last four (7, 8, 9 & 10) will be visible.
expect( panelView.isVisible ).to.be.true;

expectChildViewsIsOnState( [ true, false, false, false, false, false, false, false, false, false ] );

// Edge browser always tries to scroll in tests environment: See ckeditor5-utils#282.
Expand All @@ -396,7 +391,6 @@ describe( 'MentionUI', () => {
fireKeyDownEvent( arrowDownEvtData );

expectChildViewsIsOnState( [ false, true, false, false, false, false, false, false, false, false ] );

// Edge browser always tries to scroll in tests environment: See ckeditor5-utils#282.
if ( !env.isEdge ) {
expect( mentionsView.element.scrollTop ).to.equal( 0 );
Expand All @@ -406,21 +400,22 @@ describe( 'MentionUI', () => {
fireKeyDownEvent( arrowUpEvtData );

expectChildViewsIsOnState( [ true, false, false, false, false, false, false, false, false, false ] );
expect( mentionsView.element.scrollTop ).to.equal( 0 );

// Edge browser always tries to scroll in tests environment: See ckeditor5-utils#282.
if ( !env.isEdge ) {
expect( mentionsView.element.scrollTop ).to.equal( 0 );
sinon.assert.callCount( mentionElementSpy.set, 0 );
}

fireKeyDownEvent( arrowUpEvtData );

expectChildViewsIsOnState( [ false, false, false, false, false, false, false, false, false, true ] );

// We want 150, but sometimes we get e.g. 151.
expect( mentionsView.element.scrollTop ).to.be.within( 140, 160, 'last item highlighted' );

// Edge browser always tries to scroll in tests environment: See ckeditor5-utils#282.
if ( !env.isEdge ) {
// We want 150, but sometimes we get e.g. 151.
expect( mentionsView.element.scrollTop ).to.be.within( 140, 160, 'last item highlighted' );
sinon.assert.callCount( mentionElementSpy.set, 1 );
}

Expand Down

0 comments on commit 24b0f4c

Please sign in to comment.