documentcolorcollection.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 DocumentColorCollection from '../src/documentcolorcollection';
  6. import Collection from '@ckeditor/ckeditor5-utils/src/collection';
  7. describe( 'DocumentColorCollection', () => {
  8. let documentColorCollection;
  9. const colors = [
  10. {
  11. color: '111'
  12. },
  13. {
  14. color: '222'
  15. },
  16. {
  17. color: '333'
  18. },
  19. {
  20. color: '444'
  21. }
  22. ];
  23. beforeEach( () => {
  24. documentColorCollection = new DocumentColorCollection();
  25. colors.forEach( item => {
  26. documentColorCollection.add( item );
  27. } );
  28. } );
  29. it( 'constructor()', () => {
  30. expect( documentColorCollection ).to.be.instanceOf( DocumentColorCollection );
  31. expect( documentColorCollection ).to.be.instanceOf( Collection );
  32. } );
  33. it( 'has observable "isEmpty" parameter', () => {
  34. expect( documentColorCollection.isEmpty ).to.be.false;
  35. documentColorCollection.clear();
  36. expect( documentColorCollection.isEmpty ).to.be.true;
  37. documentColorCollection.add( colors[ 0 ] );
  38. expect( documentColorCollection.isEmpty ).to.be.false;
  39. } );
  40. it( 'prevent of adding duplicated colors', () => {
  41. expect( documentColorCollection.length ).to.equal( 4 );
  42. documentColorCollection.add( { color: '111' } );
  43. expect( documentColorCollection.length ).to.equal( 4 );
  44. } );
  45. it( 'hasColor()', () => {
  46. expect( documentColorCollection.hasColor( '111' ) ).to.be.true;
  47. expect( documentColorCollection.hasColor( '555' ) ).to.be.false;
  48. } );
  49. } );