| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- /**
- * @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 View from '../../src/view';
- import LabeledFieldView from '../../src/labeledfield/labeledfieldview';
- import LabelView from '../../src/label/labelview';
- describe( 'LabeledFieldView', () => {
- const locale = {};
- let labeledInput, view;
- beforeEach( () => {
- labeledInput = new LabeledFieldView( locale, ( labeledInput, viewUid, statusUid ) => {
- view = new View( locale );
- view.setTemplate( { tag: 'div' } );
- view.focus = () => {};
- view.viewUid = viewUid;
- view.statusUid = statusUid;
- return view;
- } );
- labeledInput.render();
- } );
- afterEach( () => {
- labeledInput.destroy();
- } );
- describe( 'constructor()', () => {
- it( 'should set labeledInput#locale', () => {
- expect( labeledInput.locale ).to.deep.equal( locale );
- } );
- it( 'should set labeledInput#fieldView', () => {
- expect( labeledInput.fieldView ).to.equal( view );
- } );
- it( 'should set labeledInput#label', () => {
- expect( labeledInput.label ).to.be.undefined;
- } );
- it( 'should set labeledInput#isEnabled', () => {
- expect( labeledInput.isEnabled ).to.be.true;
- } );
- it( 'should set labeledInput#errorText', () => {
- expect( labeledInput.errorText ).to.be.null;
- } );
- it( 'should set labeledInput#infoText', () => {
- expect( labeledInput.infoText ).to.be.null;
- } );
- it( 'should set labeledInput#class', () => {
- expect( labeledInput.class ).to.be.undefined;
- } );
- it( 'should create labeledInput#labelView', () => {
- expect( labeledInput.labelView ).to.instanceOf( LabelView );
- } );
- it( 'should create labeledInput#statusView', () => {
- expect( labeledInput.statusView ).to.instanceOf( View );
- expect( labeledInput.statusView.element.tagName ).to.equal( 'DIV' );
- expect( labeledInput.statusView.element.classList.contains( 'ck' ) ).to.be.true;
- expect( labeledInput.statusView.element.classList.contains( 'ck-labeled-field-view__status' ) ).to.be.true;
- } );
- it( 'should allow pairing #view and #labelView by unique id', () => {
- expect( labeledInput.labelView.for ).to.equal( view.viewUid );
- } );
- it( 'should allow pairing #view and #statusView by unique id', () => {
- expect( view.statusUid ).to.equal( labeledInput.statusView.element.id );
- } );
- } );
- describe( 'template', () => {
- it( 'should have the CSS class', () => {
- expect( labeledInput.element.classList.contains( 'ck' ) ).to.be.true;
- expect( labeledInput.element.classList.contains( 'ck-labeled-field-view' ) ).to.be.true;
- } );
- it( 'should have #labeledInput', () => {
- expect( labeledInput.template.children[ 0 ] ).to.equal( labeledInput.labelView );
- } );
- it( 'should have #view', () => {
- expect( labeledInput.template.children[ 1 ] ).to.equal( view );
- } );
- it( 'should have the #statusView container', () => {
- expect( labeledInput.template.children[ 2 ] ).to.equal( labeledInput.statusView );
- } );
- describe( 'DOM bindings', () => {
- describe( 'class', () => {
- it( 'should react on labeledInput#class', () => {
- labeledInput.class = 'foo';
- expect( labeledInput.element.classList.contains( 'foo' ) ).to.be.true;
- labeledInput.class = 'bar';
- expect( labeledInput.element.classList.contains( 'foo' ) ).to.be.false;
- expect( labeledInput.element.classList.contains( 'bar' ) ).to.be.true;
- } );
- } );
- describe( 'status container', () => {
- it( 'should react on labeledInput#errorText', () => {
- const statusElement = labeledInput.statusView.element;
- labeledInput.errorText = '';
- expect( statusElement.classList.contains( 'ck-hidden' ) ).to.be.true;
- expect( statusElement.classList.contains( 'ck-labeled-field-view__status_error' ) ).to.be.false;
- expect( statusElement.hasAttribute( 'role' ) ).to.be.false;
- expect( statusElement.innerHTML ).to.equal( '' );
- labeledInput.errorText = 'foo';
- expect( statusElement.classList.contains( 'ck-hidden' ) ).to.be.false;
- expect( statusElement.classList.contains( 'ck-labeled-field-view__status_error' ) ).to.be.true;
- expect( statusElement.getAttribute( 'role' ) ).to.equal( 'alert' );
- expect( statusElement.innerHTML ).to.equal( 'foo' );
- } );
- it( 'should react on labeledInput#infoText', () => {
- const statusElement = labeledInput.statusView.element;
- labeledInput.infoText = '';
- expect( statusElement.classList.contains( 'ck-hidden' ) ).to.be.true;
- expect( statusElement.classList.contains( 'ck-labeled-field-view__status_error' ) ).to.be.false;
- expect( statusElement.hasAttribute( 'role' ) ).to.be.false;
- expect( statusElement.innerHTML ).to.equal( '' );
- labeledInput.infoText = 'foo';
- expect( statusElement.classList.contains( 'ck-hidden' ) ).to.be.false;
- expect( statusElement.classList.contains( 'ck-labeled-field-view__status_error' ) ).to.be.false;
- expect( statusElement.hasAttribute( 'role' ) ).to.be.false;
- expect( statusElement.innerHTML ).to.equal( 'foo' );
- } );
- } );
- } );
- } );
- describe( 'binding', () => {
- it( 'should bind labeledInput#label to labeledInput.labelView#label', () => {
- labeledInput.label = 'Foo bar';
- expect( labeledInput.labelView.text ).to.equal( 'Foo bar' );
- } );
- } );
- describe( 'focus()', () => {
- it( 'should focus the #view in DOM', () => {
- const spy = sinon.spy( view, 'focus' );
- labeledInput.focus();
- sinon.assert.calledOnce( spy );
- } );
- } );
- } );
|