8
0
Pārlūkot izejas kodu

Add unit tests for document colors collection.

Mateusz Samsel 6 gadi atpakaļ
vecāks
revīzija
462d80964b

+ 56 - 0
packages/ckeditor5-font/tests/documentcolorscollection.js

@@ -0,0 +1,56 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+import DocumentColorsCollection from '../src/documentcolorscollection';
+import Collection from '@ckeditor/ckeditor5-utils/src/collection';
+
+describe( 'DocumentColorsCollection', () => {
+	let documentColorsCollection;
+
+	const colors = [
+		{
+			color: '111',
+		},
+		{
+			color: '222'
+		},
+		{
+			color: '333'
+		},
+		{
+			color: '444'
+		}
+	];
+
+	beforeEach( () => {
+		documentColorsCollection = new DocumentColorsCollection();
+
+		colors.forEach( item => {
+			documentColorsCollection.add( item );
+		} );
+	} );
+
+	it( 'constructor()', () => {
+		expect( documentColorsCollection ).to.be.instanceOf( DocumentColorsCollection );
+		expect( documentColorsCollection ).to.be.instanceOf( Collection );
+	} );
+
+	it( 'has observable "isEmpty" parameter', () => {
+		expect( documentColorsCollection.isEmpty ).to.be.false;
+
+		documentColorsCollection.clear();
+		expect( documentColorsCollection.isEmpty ).to.be.true;
+
+		documentColorsCollection.add( colors[ 0 ] );
+		expect( documentColorsCollection.isEmpty ).to.be.false;
+	} );
+
+	it( 'prevent of adding duplicated colors', () => {
+		expect( documentColorsCollection.length ).to.equal( 4 );
+
+		documentColorsCollection.add( { color: '111' } );
+		expect( documentColorsCollection.length ).to.equal( 4 );
+	} );
+} );