From e6822770ed3b63d1e546d1e7977b2b856b4a58f4 Mon Sep 17 00:00:00 2001 From: Mateusz Samsel Date: Mon, 20 Nov 2017 12:56:17 +0100 Subject: [PATCH] Review fixes: extract helpers method, remove tools modifications from history. --- .../plugins/inlinetoolbar/_helpers/default.js | 19 +++++++++++++++++++ tests/plugins/inlinetoolbar/cssdefault.js | 14 ++++---------- tests/plugins/inlinetoolbar/cssskin.js | 6 ++++-- .../inlinetoolbar/manual/fallbackstyles.html | 8 +------- .../inlinetoolbar/manual/fallbackstyles.md | 3 ++- 5 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 tests/plugins/inlinetoolbar/_helpers/default.js diff --git a/tests/plugins/inlinetoolbar/_helpers/default.js b/tests/plugins/inlinetoolbar/_helpers/default.js new file mode 100644 index 00000000000..07d80c3935e --- /dev/null +++ b/tests/plugins/inlinetoolbar/_helpers/default.js @@ -0,0 +1,19 @@ +/* exported replaceAppendStyleSheet, convertRgbaToRgb */ + +'use strict'; + +function replaceAppendStyleSheet() { + // Overwrite prototype to simulate missing css file. + var oldFn = CKEDITOR.dom.document.prototype.appendStyleSheet; + CKEDITOR.dom.document.prototype.appendStyleSheet = function( cssFileUrl ) { + // Simulate missing css in skin. + if ( !cssFileUrl.match( /(inlinetoolbar|balloonpanel)\.css/ ) ) { + oldFn.call( CKEDITOR.document, cssFileUrl ); + } + }; +} + +function convertRgbaToRgb( input ) { + var re = /^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/gi; + return re.test( input ) ? input.replace( /,\s*?\d+?\s*?\)$/, ')' ).replace( 'rgba(', 'rgb(' ) : input; +} diff --git a/tests/plugins/inlinetoolbar/cssdefault.js b/tests/plugins/inlinetoolbar/cssdefault.js index 0bba47f76ed..25db8cbeb1c 100644 --- a/tests/plugins/inlinetoolbar/cssdefault.js +++ b/tests/plugins/inlinetoolbar/cssdefault.js @@ -1,5 +1,7 @@ /* bender-tags: inlinetoolbar */ /* bender-ckeditor-plugins: toolbar,inlinetoolbar,basicstyles */ +/* bender-include: ./_helpers/default.js */ +/* global replaceAppendStyleSheet */ ( function() { 'use strict'; @@ -32,17 +34,9 @@ } }; - // We need to set up skin at the very beginning before files start to load. + // We need to set up skin at the very beginning before loading files. CKEDITOR.skinName = 'moono'; - - // Overwrite prototype to simulate missing css file. - var oldFn = CKEDITOR.dom.document.prototype.appendStyleSheet; - CKEDITOR.dom.document.prototype.appendStyleSheet = function( cssFileUrl ) { - // Simulate missing css in skin. - if ( !cssFileUrl.match( /(inlinetoolbar|balloonpanel)\.css/ ) ) { - oldFn.call( CKEDITOR.document, cssFileUrl ); - } - }; + replaceAppendStyleSheet(); var tests = { 'test check default.css file usage when skin miss adequate css': function( editor ) { diff --git a/tests/plugins/inlinetoolbar/cssskin.js b/tests/plugins/inlinetoolbar/cssskin.js index 239c93a35ac..3d0208880c9 100644 --- a/tests/plugins/inlinetoolbar/cssskin.js +++ b/tests/plugins/inlinetoolbar/cssskin.js @@ -1,5 +1,7 @@ /* bender-tags: inlinetoolbar */ /* bender-ckeditor-plugins: toolbar,inlinetoolbar,basicstyles */ +/* bender-include: ./_helpers/default.js */ +/* global convertRgbaToRgb */ ( function() { 'use strict'; @@ -32,7 +34,7 @@ } }; - // We need to set up skin at the very beginning befor files start to load. + // We need to set up skin at the very beginning before loading files. CKEDITOR.skinName = 'moono'; var tests = { @@ -51,7 +53,7 @@ panel.attach( editor.editable().findOne( 'p' ) ); // IE use cke_reset styles, that' why there is transparent. assert.areSame( CKEDITOR.env.ie ? 'background-color:transparent;' : 'background-color:#000000;', - CKEDITOR.tools.normalizeCssText( 'background-color:' + panel._view.parts.panel.getComputedStyle( 'background-color' ) + ';' ), + CKEDITOR.tools.normalizeCssText( 'background-color:' + convertRgbaToRgb( panel._view.parts.panel.getComputedStyle( 'background-color' ) ) + ';' ), 'Background color is incorrect.' ); } }; diff --git a/tests/plugins/inlinetoolbar/manual/fallbackstyles.html b/tests/plugins/inlinetoolbar/manual/fallbackstyles.html index 0ff238945d6..4bfd793e5d6 100644 --- a/tests/plugins/inlinetoolbar/manual/fallbackstyles.html +++ b/tests/plugins/inlinetoolbar/manual/fallbackstyles.html @@ -61,13 +61,7 @@ } // Overwrite prototype to simulate missing css file. - var oldFn = CKEDITOR.dom.document.prototype.appendStyleSheet; - CKEDITOR.dom.document.prototype.appendStyleSheet = function( cssFileUrl ) { - // Simulate missing css in skin. - if ( !cssFileUrl.match( /(inlinetoolbar|balloonpanel)\.css/ ) ) { - oldFn.call( CKEDITOR.document, cssFileUrl ); - } - }; + replaceAppendStyleSheet() CKEDITOR.replace( 'editor1', { skin: 'moono', diff --git a/tests/plugins/inlinetoolbar/manual/fallbackstyles.md b/tests/plugins/inlinetoolbar/manual/fallbackstyles.md index 1b888969681..d61c99a292b 100644 --- a/tests/plugins/inlinetoolbar/manual/fallbackstyles.md +++ b/tests/plugins/inlinetoolbar/manual/fallbackstyles.md @@ -1,6 +1,7 @@ @bender-ui: collapsed @bender-tags: 4.8.0, bug, inlinetoolbar @bender-ckeditor-plugins: wysiwygarea,toolbar,basicstyles,floatingspace,inlinetoolbar,link,image,resize,language,stylescombo +@bender-include: ../_helpers/default.js Perform below steps in both editors: 1. Click image. @@ -8,6 +9,6 @@ Perform below steps in both editors: _Note:_ Please be aware that buttons in inline toolbar use main skin. -**Expected:** Inline toolbar background should be different from used skin (fallback css should be load). +**Expected:** Inline toolbar background should be different from used skin (fallback `default.css` should be loaded). **Unexpected:** Inline toolbar is not visible. Inline toolbar has the same skin as editor (grey gradient at ballon background).