| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- /**
- * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- import {
- createLabeledInputText,
- createLabeledDropdown
- } from '../../src/labeledview/utils';
- import LabeledView from '../../src/labeledview/labeledview';
- import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
- import InputTextView from '../../src/inputtext/inputtextview';
- import DropdownView from '../../src/dropdown/dropdownview';
- describe( 'LabeledView utils', () => {
- let locale;
- testUtils.createSinonSandbox();
- beforeEach( () => {
- locale = { t: val => val };
- } );
- describe( 'createLabeledInputText()', () => {
- let labeledView;
- beforeEach( () => {
- labeledView = new LabeledView( locale, createLabeledInputText );
- } );
- afterEach( () => {
- labeledView.destroy();
- } );
- it( 'should create an InputTextView instance', () => {
- expect( labeledView.view ).to.be.instanceOf( InputTextView );
- } );
- it( 'should pass the Locale to the input', () => {
- expect( labeledView.view.locale ).to.equal( locale );
- } );
- it( 'should set input #id and #ariaDescribedById', () => {
- labeledView.render();
- expect( labeledView.view.id ).to.equal( labeledView.labelView.for );
- expect( labeledView.view.ariaDescribedById ).to.equal( labeledView.statusView.element.id );
- } );
- it( 'should bind input\'s #isReadOnly to LabeledView#isEnabled', () => {
- labeledView.isEnabled = true;
- expect( labeledView.view.isReadOnly ).to.be.false;
- labeledView.isEnabled = false;
- expect( labeledView.view.isReadOnly ).to.be.true;
- } );
- it( 'should bind input\'s #hasError to LabeledView#errorText', () => {
- labeledView.errorText = 'some error';
- expect( labeledView.view.hasError ).to.be.true;
- labeledView.errorText = null;
- expect( labeledView.view.hasError ).to.be.false;
- } );
- it( 'should clean LabeledView#errorText upon input\'s DOM "update" event', () => {
- labeledView.errorText = 'some error';
- labeledView.view.fire( 'input' );
- expect( labeledView.errorText ).to.be.null;
- } );
- } );
- describe( 'createLabeledDropdown', () => {
- let labeledView;
- beforeEach( () => {
- labeledView = new LabeledView( locale, createLabeledDropdown );
- } );
- afterEach( () => {
- labeledView.destroy();
- } );
- it( 'should create a DropdownView', () => {
- expect( labeledView.view ).to.be.instanceOf( DropdownView );
- } );
- it( 'should pass the Locale to the dropdown', () => {
- expect( labeledView.view.locale ).to.equal( locale );
- } );
- it( 'should set dropdown\'s #id and #ariaDescribedById', () => {
- labeledView.render();
- expect( labeledView.view.id ).to.equal( labeledView.labelView.for );
- expect( labeledView.view.ariaDescribedById ).to.equal( labeledView.statusView.element.id );
- } );
- it( 'should bind dropdown\'s #isEnabled to the labeled view', () => {
- labeledView.isEnabled = true;
- expect( labeledView.view.isEnabled ).to.be.true;
- labeledView.isEnabled = false;
- expect( labeledView.view.isEnabled ).to.be.false;
- } );
- } );
- } );
|