Преглед на файлове

Tests: Used getComputedStyle mock instead of setting styles.

Oskar Wróbel преди 7 години
родител
ревизия
59466f876f
променени са 2 файла, в които са добавени 16 реда и са изтрити 17 реда
  1. 2 2
      packages/ckeditor5-ui/src/toolbar/block/blocktoolbar.js
  2. 14 15
      packages/ckeditor5-ui/tests/toolbar/block/blocktoolbar.js

+ 2 - 2
packages/ckeditor5-ui/src/toolbar/block/blocktoolbar.js

@@ -329,8 +329,8 @@ export default class BlockToolbar extends Plugin {
 		const contentComputedStyles = window.getComputedStyle( targetElement );
 
 		const editableRect = new Rect( this.editor.ui.view.editableElement );
-		const contentPaddingTop = parseInt( contentComputedStyles.paddingTop );
-		const contentLineHeight = parseInt( contentComputedStyles.lineHeight ) || parseInt( contentComputedStyles.fontSize );
+		const contentPaddingTop = parseInt( contentComputedStyles.paddingTop, 10 );
+		const contentLineHeight = parseInt( contentComputedStyles.lineHeight, 10 ) || parseInt( contentComputedStyles.fontSize, 10 );
 
 		const position = getOptimalPosition( {
 			element: this.buttonView.element,

+ 14 - 15
packages/ckeditor5-ui/tests/toolbar/block/blocktoolbar.js

@@ -273,18 +273,17 @@ describe( 'BlockToolbar', () => {
 
 	describe( 'attaching button to the content', () => {
 		it( 'should attach button to the left side of selected content and center with the first line on view#render #1', () => {
-			// Mock window dimensions.
-			testUtils.sinon.stub( window, 'innerWidth' ).value( 500 );
-			testUtils.sinon.stub( window, 'innerHeight' ).value( 500 );
-			testUtils.sinon.stub( window, 'scrollX' ).value( 0 );
-			testUtils.sinon.stub( window, 'scrollY' ).value( 0 );
-
 			setData( editor.model, '<paragraph>foo[]bar</paragraph>' );
 
 			const target = editor.ui.view.editableElement.querySelector( 'p' );
+			const styleMock = testUtils.sinon.stub( window, 'getComputedStyle' );
+
+			styleMock.withArgs( target ).returns( {
+				lineHeight: '20px',
+				paddingTop: '10px'
+			} );
 
-			target.style.lineHeight = '20px';
-			target.style.paddingTop = '10px';
+			styleMock.callThrough();
 
 			testUtils.sinon.stub( editor.ui.view.editableElement, 'getBoundingClientRect' ).returns( {
 				left: 100
@@ -307,17 +306,17 @@ describe( 'BlockToolbar', () => {
 		} );
 
 		it( 'should attach button to the left side of selected content and center with the first line on view#render #2', () => {
-			testUtils.sinon.stub( window, 'innerWidth' ).value( 500 );
-			testUtils.sinon.stub( window, 'innerHeight' ).value( 500 );
-			testUtils.sinon.stub( window, 'scrollX' ).value( 0 );
-			testUtils.sinon.stub( window, 'scrollY' ).value( 0 );
-
 			setData( editor.model, '<paragraph>foo[]bar</paragraph>' );
 
 			const target = editor.ui.view.editableElement.querySelector( 'p' );
+			const styleMock = testUtils.sinon.stub( window, 'getComputedStyle' );
+
+			styleMock.withArgs( target ).returns( {
+				fontSize: '20px',
+				paddingTop: '10px'
+			} );
 
-			target.style.fontSize = '20px';
-			target.style.paddingTop = '10px';
+			styleMock.callThrough();
 
 			testUtils.sinon.stub( editor.ui.view.editableElement, 'getBoundingClientRect' ).returns( {
 				left: 100