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

Commit

Permalink
Merge pull request #296 from ckeditor/t/ckeditor5/383
Browse files Browse the repository at this point in the history
Internal: Removed usage of the CKEditor 5 logger. Part of ckeditor/ckeditor5#383.
  • Loading branch information
Piotr Jasiun authored Jul 12, 2019
2 parents a1fe97f + 0d298d1 commit ea10eb6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 41 deletions.
7 changes: 4 additions & 3 deletions src/imagestyle/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
* @module image/imagestyle/utils
*/

import log from '@ckeditor/ckeditor5-utils/src/log';
/* globals console */

import fullWidthIcon from '@ckeditor/ckeditor5-core/theme/icons/object-full-width.svg';
import leftIcon from '@ckeditor/ckeditor5-core/theme/icons/object-left.svg';
import centerIcon from '@ckeditor/ckeditor5-core/theme/icons/object-center.svg';
import rightIcon from '@ckeditor/ckeditor5-core/theme/icons/object-right.svg';
import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

/**
* Default image styles provided by the plugin that can be referred in the
Expand Down Expand Up @@ -115,8 +116,8 @@ function _normalizeStyle( style ) {
}
// If it's just a name but none of the defaults, warn because probably it's a mistake.
else {
log.warn(
'image-style-not-found: There is no such image style of given name.',
console.warn(
attachLinkToDocumentation( 'image-style-not-found: There is no such image style of given name.' ),
{ name: styleName }
);

Expand Down
8 changes: 4 additions & 4 deletions tests/imagestyle/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

import log from '@ckeditor/ckeditor5-utils/src/log';
/* globals console */

import fullWidthIcon from '@ckeditor/ckeditor5-core/theme/icons/object-full-width.svg';
import leftIcon from '@ckeditor/ckeditor5-core/theme/icons/object-left.svg';
Expand Down Expand Up @@ -100,14 +100,14 @@ describe( 'ImageStyle utils', () => {
} );

it( 'should warn if a #name not found in default styles', () => {
testUtils.sinon.stub( log, 'warn' );
testUtils.sinon.stub( console, 'warn' );

expect( normalizeImageStyles( [ 'foo' ] ) ).to.deep.equal( [ {
name: 'foo'
} ] );

sinon.assert.calledOnce( log.warn );
sinon.assert.calledWithExactly( log.warn,
sinon.assert.calledOnce( console.warn );
sinon.assert.calledWithExactly( console.warn,
sinon.match( /^image-style-not-found/ ),
{ name: 'foo' }
);
Expand Down
14 changes: 6 additions & 8 deletions tests/imageupload/imageuploadcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* globals console */

import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
Expand All @@ -15,15 +17,9 @@ import { setData as setModelData, getData as getModelData } from '@ckeditor/cked
import Image from '../../src/image/imageediting';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';

import log from '@ckeditor/ckeditor5-utils/src/log';

import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

describe( 'ImageUploadCommand', () => {
let editor, command, model, fileRepository;

testUtils.createSinonSandbox();

class UploadAdapterPluginMock extends Plugin {
init() {
fileRepository = this.editor.plugins.get( FileRepository );
Expand All @@ -50,6 +46,8 @@ describe( 'ImageUploadCommand', () => {
} );

afterEach( () => {
sinon.restore();

return editor.destroy();
} );

Expand Down Expand Up @@ -185,7 +183,7 @@ describe( 'ImageUploadCommand', () => {

fileRepository.createUploadAdapter = undefined;

const logStub = testUtils.sinon.stub( log, 'error' );
const consoleErrorStub = sinon.stub( console, 'error' );

setModelData( model, '<paragraph>fo[]o</paragraph>' );

Expand All @@ -194,7 +192,7 @@ describe( 'ImageUploadCommand', () => {
} ).to.not.throw();

expect( getModelData( model ) ).to.equal( '<paragraph>fo[]o</paragraph>' );
expect( logStub.calledOnce ).to.be.true;
sinon.assert.calledOnce( consoleErrorStub );
} );
} );
} );
49 changes: 23 additions & 26 deletions tests/imageupload/imageuploadediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* globals window, setTimeout, atob, URL, Blob */
/* globals window, setTimeout, atob, URL, Blob, console */

import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';

Expand All @@ -23,9 +23,7 @@ import { UploadAdapterMock, createNativeFileMock, NativeFileReaderMock } from '@
import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { getData as getViewData, stringify as stringifyView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';

import log from '@ckeditor/ckeditor5-utils/src/log';
import env from '@ckeditor/ckeditor5-utils/src/env';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';

describe( 'ImageUploadEditing', () => {
Expand All @@ -36,8 +34,6 @@ describe( 'ImageUploadEditing', () => {
let adapterMocks = [];
let editor, model, view, doc, fileRepository, viewDocument, nativeReaderMock, loader;

testUtils.createSinonSandbox();

class UploadAdapterPluginMock extends Plugin {
init() {
fileRepository = this.editor.plugins.get( FileRepository );
Expand All @@ -54,15 +50,15 @@ describe( 'ImageUploadEditing', () => {

beforeEach( () => {
if ( isEdgeEnv ) {
testUtils.sinon.stub( window, 'File' ).callsFake( () => {
sinon.stub( window, 'File' ).callsFake( () => {
return { name: 'file.jpg' };
} );
}

// Most tests assume non-edge environment but we do not set `contenteditable=false` on Edge so stub `env.isEdge`.
testUtils.sinon.stub( env, 'isEdge' ).get( () => false );
sinon.stub( env, 'isEdge' ).get( () => false );

testUtils.sinon.stub( window, 'FileReader' ).callsFake( () => {
sinon.stub( window, 'FileReader' ).callsFake( () => {
nativeReaderMock = new NativeFileReaderMock();

return nativeReaderMock;
Expand All @@ -80,11 +76,12 @@ describe( 'ImageUploadEditing', () => {
viewDocument = view.document;

// Stub `view.scrollToTheSelection` as it will fail on VirtualTestEditor without DOM.
testUtils.sinon.stub( view, 'scrollToTheSelection' ).callsFake( () => {} );
sinon.stub( view, 'scrollToTheSelection' ).callsFake( () => {} );
} );
} );

afterEach( () => {
sinon.restore();
adapterMocks = [];

return editor.destroy();
Expand Down Expand Up @@ -285,7 +282,7 @@ describe( 'ImageUploadEditing', () => {
it( 'should not throw when upload adapter is not set (FileRepository will log an error anyway) when image is pasted', () => {
const fileMock = createNativeFileMock();
const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
const logStub = testUtils.sinon.stub( log, 'error' );
const consoleErrorStub = sinon.stub( console, 'error' );

setModelData( model, '<paragraph>[]foo</paragraph>' );

Expand All @@ -299,7 +296,7 @@ describe( 'ImageUploadEditing', () => {
} ).to.not.throw();

expect( getModelData( model ) ).to.equal( '<paragraph>foo[]</paragraph>' );
sinon.assert.calledOnce( logStub );
sinon.assert.calledOnce( consoleErrorStub );
} );

// https://github.com/ckeditor/ckeditor5-upload/issues/70
Expand Down Expand Up @@ -402,7 +399,7 @@ describe( 'ImageUploadEditing', () => {
it( 'should not fire notification on abort', done => {
const notification = editor.plugins.get( Notification );
const file = createNativeFileMock();
const spy = testUtils.sinon.spy();
const spy = sinon.spy();

notification.on( 'show:warning', evt => {
spy();
Expand Down Expand Up @@ -467,7 +464,7 @@ describe( 'ImageUploadEditing', () => {

it( 'should remove image in case of upload error', done => {
const file = createNativeFileMock();
const spy = testUtils.sinon.spy();
const spy = sinon.spy();
const notification = editor.plugins.get( Notification );
setModelData( model, '<paragraph>{}foo bar</paragraph>' );

Expand Down Expand Up @@ -495,7 +492,7 @@ describe( 'ImageUploadEditing', () => {
setModelData( model, '<paragraph>{}foo bar</paragraph>' );
editor.execute( 'imageUpload', { file } );

const abortSpy = testUtils.sinon.spy( loader, 'abort' );
const abortSpy = sinon.spy( loader, 'abort' );

expect( loader.status ).to.equal( 'reading' );

Expand All @@ -517,8 +514,8 @@ describe( 'ImageUploadEditing', () => {
setModelData( model, '<paragraph>{}foo bar</paragraph>' );
editor.execute( 'imageUpload', { file } );

const abortSpy = testUtils.sinon.spy( loader, 'abort' );
const loadSpy = testUtils.sinon.spy( loader, 'read' );
const abortSpy = sinon.spy( loader, 'abort' );
const loadSpy = sinon.spy( loader, 'read' );

const image = doc.getRoot().getChild( 0 );

Expand Down Expand Up @@ -589,7 +586,7 @@ describe( 'ImageUploadEditing', () => {
} );

it( 'should prevent from browser redirecting when an image is dropped on another image', () => {
const spy = testUtils.sinon.spy();
const spy = sinon.spy();

editor.editing.view.document.fire( 'dragover', {
preventDefault: spy
Expand Down Expand Up @@ -646,7 +643,7 @@ describe( 'ImageUploadEditing', () => {
expectModel( done, getModelData( model ), expected );
}, { priority: 'low' } );

testUtils.sinon.stub( fileRepository, 'createLoader' ).callsFake( () => null );
sinon.stub( fileRepository, 'createLoader' ).callsFake( () => null );

setModelData( model, '<paragraph>[]foo</paragraph>' );

Expand Down Expand Up @@ -684,7 +681,7 @@ describe( 'ImageUploadEditing', () => {
const targetViewRange = editor.editing.mapper.toViewRange( targetRange );

// Stub `fetch` so it can be rejected.
testUtils.sinon.stub( window, 'fetch' ).callsFake( () => {
sinon.stub( window, 'fetch' ).callsFake( () => {
return new Promise( ( res, rej ) => rej() );
} );

Expand Down Expand Up @@ -728,7 +725,7 @@ describe( 'ImageUploadEditing', () => {
// Stub `fetch` in a way that 2 first calls are successful and 3rd fails.
let counter = 0;
const fetch = window.fetch;
testUtils.sinon.stub( window, 'fetch' ).callsFake( src => {
sinon.stub( window, 'fetch' ).callsFake( src => {
counter++;
if ( counter < 3 ) {
return fetch( src );
Expand Down Expand Up @@ -777,11 +774,11 @@ describe( 'ImageUploadEditing', () => {
it( 'should not upload and remove image when `File` constructor is not supported', done => {
if ( isEdgeEnv ) {
// Since on Edge `File` is already stubbed, restore it to it native form so that exception will be thrown.
testUtils.sinon.restore();
sinon.restore();
// Since all stubs were restored, re-stub `scrollToTheSelection`.
testUtils.sinon.stub( editor.editing.view, 'scrollToTheSelection' ).callsFake( () => {} );
sinon.stub( editor.editing.view, 'scrollToTheSelection' ).callsFake( () => {} );
} else {
testUtils.sinon.stub( window, 'File' ).throws( 'Function expected.' );
sinon.stub( window, 'File' ).throws( 'Function expected.' );
}

const notification = editor.plugins.get( Notification );
Expand Down Expand Up @@ -827,7 +824,7 @@ describe( 'ImageUploadEditing', () => {
const targetViewRange = editor.editing.mapper.toViewRange( targetRange );

// Stub `fetch` to return custom blob without type.
testUtils.sinon.stub( window, 'fetch' ).callsFake( () => {
sinon.stub( window, 'fetch' ).callsFake( () => {
return new Promise( res => res( {
blob() {
return new Promise( res => res( new Blob( [ 'foo', 'bar' ] ) ) );
Expand Down Expand Up @@ -855,7 +852,7 @@ describe( 'ImageUploadEditing', () => {
const targetViewRange = editor.editing.mapper.toViewRange( targetRange );

// Stub `fetch` to return custom blob without type.
testUtils.sinon.stub( window, 'fetch' ).callsFake( () => {
sinon.stub( window, 'fetch' ).callsFake( () => {
return new Promise( res => res( {
blob() {
return new Promise( res => res( new Blob( [ 'foo', 'bar' ] ) ) );
Expand Down Expand Up @@ -898,7 +895,7 @@ describe( 'ImageUploadEditing', () => {
const targetViewRange = editor.editing.mapper.toViewRange( targetRange );

// Stub `fetch` in a way that it always fails.
testUtils.sinon.stub( window, 'fetch' ).callsFake( () => Promise.reject() );
sinon.stub( window, 'fetch' ).callsFake( () => Promise.reject() );

viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
} );
Expand Down

0 comments on commit ea10eb6

Please sign in to comment.