Skip to content

Commit

Permalink
TextareaView should throw if misconfigured.
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Sep 25, 2023
1 parent ace53a8 commit 0e4742b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
10 changes: 8 additions & 2 deletions packages/ckeditor5-ui/src/textarea/textareaview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -176,8 +176,14 @@ export default class TextareaView extends InputBase<HTMLTextAreaElement> {
*
* @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
} );
}
}
}
Expand Down
34 changes: 22 additions & 12 deletions packages/ckeditor5-ui/tests/textarea/textareaview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
);
} );
} );

Expand Down

0 comments on commit 0e4742b

Please sign in to comment.