From 0e4742b99d6e09f4728b7d5c58dd629a594a217a Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Mon, 25 Sep 2023 17:11:23 +0200 Subject: [PATCH] TextareaView should throw if misconfigured. --- .../ckeditor5-ui/src/textarea/textareaview.ts | 10 ++++-- .../tests/textarea/textareaview.js | 34 ++++++++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/packages/ckeditor5-ui/src/textarea/textareaview.ts b/packages/ckeditor5-ui/src/textarea/textareaview.ts index 7129fb9d89f..4dbc4f3bdda 100644 --- a/packages/ckeditor5-ui/src/textarea/textareaview.ts +++ b/packages/ckeditor5-ui/src/textarea/textareaview.ts @@ -7,7 +7,7 @@ * @module ui/textarea/textareaview */ -import { Rect, type Locale, toUnit, getBorderWidths, global } from '@ckeditor/ckeditor5-utils'; +import { Rect, type Locale, toUnit, getBorderWidths, global, CKEditorError } from '@ckeditor/ckeditor5-utils'; import InputBase from '../input/inputbase'; import '../../theme/components/input/input.css'; @@ -176,8 +176,14 @@ export default class TextareaView extends InputBase { * * @error ui-textarea-view-min-rows-greater-than-max-rows * @param textareaView The misconfigured textarea view instance. + * @param minRows The value of `minRows` property. + * @param maxRows The value of `maxRows` property. */ - console.warn( 'ui-textarea-view-min-rows-greater-than-max-rows', { textareaView: this } ); + throw new CKEditorError( 'ui-textarea-view-min-rows-greater-than-max-rows', { + textareaView: this, + minRows: this.minRows, + maxRows: this.maxRows + } ); } } } diff --git a/packages/ckeditor5-ui/tests/textarea/textareaview.js b/packages/ckeditor5-ui/tests/textarea/textareaview.js index 69bd79aa2b7..8340f90a6ee 100644 --- a/packages/ckeditor5-ui/tests/textarea/textareaview.js +++ b/packages/ckeditor5-ui/tests/textarea/textareaview.js @@ -3,11 +3,12 @@ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ -/* global console, document */ +/* global document */ import { global } from '@ckeditor/ckeditor5-utils'; import TextareaView from '../../src/textarea/textareaview'; import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; +import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'; describe( 'TextareaView', () => { let wrapper, view; @@ -43,21 +44,30 @@ describe( 'TextareaView', () => { expect( view.element.style.resize ).to.equal( 'none' ); } ); - it( 'should warn if #minHeight is greater than #maxHeight', () => { - const warnSpy = testUtils.sinon.stub( console, 'warn' ); - + it( 'should throw if #minHeight is greater than #maxHeight', () => { view.minRows = 2; view.maxRows = 3; - sinon.assert.notCalled( warnSpy ); - view.minRows = view.maxRows; - sinon.assert.notCalled( warnSpy ); - - view.minRows = 4; - sinon.assert.calledOnceWithMatch( warnSpy, 'ui-textarea-view-min-rows-greater-than-max-rows' ); - view.maxRows = 5; - sinon.assert.calledOnceWithMatch( warnSpy, 'ui-textarea-view-min-rows-greater-than-max-rows' ); + expectToThrowCKEditorError( + () => { view.minRows = 4; }, + 'ui-textarea-view-min-rows-greater-than-max-rows', + { + view, + minRows: 4, + maxRows: 3 + } + ); + + expectToThrowCKEditorError( + () => { view.minRows = 5; }, + 'ui-textarea-view-min-rows-greater-than-max-rows', + { + view, + minRows: 5, + maxRows: 3 + } + ); } ); } );