manualdecorator.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import ManualDecorator from '../../src/utils/manualdecorator';
  6. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  7. describe( 'Manual Decorator', () => {
  8. let manualDecorator;
  9. testUtils.createSinonSandbox();
  10. beforeEach( () => {
  11. manualDecorator = new ManualDecorator( {
  12. id: 'foo',
  13. label: 'bar',
  14. attributes: {
  15. one: 'two'
  16. }
  17. } );
  18. } );
  19. it( 'constructor', () => {
  20. expect( manualDecorator.id ).to.equal( 'foo' );
  21. expect( manualDecorator.label ).to.equal( 'bar' );
  22. expect( manualDecorator.attributes ).to.deep.equal( { one: 'two' } );
  23. expect( manualDecorator.defaultValue ).to.deep.equal( undefined );
  24. } );
  25. it( 'constructor with defaultValue', () => {
  26. manualDecorator = new ManualDecorator( {
  27. id: 'foo',
  28. label: 'bar',
  29. attributes: {
  30. one: 'two'
  31. },
  32. defaultValue: true
  33. } );
  34. expect( manualDecorator.id ).to.equal( 'foo' );
  35. expect( manualDecorator.label ).to.equal( 'bar' );
  36. expect( manualDecorator.attributes ).to.deep.equal( { one: 'two' } );
  37. expect( manualDecorator.defaultValue ).to.deep.equal( true );
  38. } );
  39. it( '#value is observable', () => {
  40. const spy = testUtils.sinon.spy();
  41. expect( manualDecorator.value ).to.be.undefined;
  42. manualDecorator.on( 'change:value', spy );
  43. manualDecorator.value = true;
  44. expect( spy.calledOnce ).to.be.true;
  45. testUtils.sinon.assert.calledWithExactly( spy.firstCall, testUtils.sinon.match.any, 'value', true, undefined );
  46. manualDecorator.value = false;
  47. expect( spy.calledTwice ).to.be.true;
  48. testUtils.sinon.assert.calledWithExactly( spy.secondCall, testUtils.sinon.match.any, 'value', false, true );
  49. } );
  50. } );