8
0
Эх сурвалжийг харах

Code style: wrapped tests in a main describe().

Piotrek Koszuliński 9 жил өмнө
parent
commit
bcba15a515

+ 112 - 110
packages/ckeditor5-engine/tests/model/schema/schemaitem.js

@@ -10,145 +10,147 @@ import { SchemaItem as SchemaItem } from 'ckeditor5/engine/model/schema.js';
 
 let schema, item;
 
-beforeEach( () => {
-	schema = new Schema();
-
-	schema.registerItem( 'p', '$block' );
-	schema.registerItem( 'header', '$block' );
-	schema.registerItem( 'div', '$block' );
-	schema.registerItem( 'html', '$block' );
-	schema.registerItem( 'span', '$inline' );
-	schema.registerItem( 'image', '$inline' );
-
-	item = new SchemaItem( schema );
-} );
-
-describe( 'constructor()', () => {
-	it( 'should create empty schema item', () => {
-		let item = new SchemaItem( schema );
-
-		expect( item._disallowed ).to.deep.equal( [] );
-		expect( item._allowed ).to.deep.equal( [] );
+describe( 'SchemaItem', () => {
+	beforeEach( () => {
+		schema = new Schema();
+
+		schema.registerItem( 'p', '$block' );
+		schema.registerItem( 'header', '$block' );
+		schema.registerItem( 'div', '$block' );
+		schema.registerItem( 'html', '$block' );
+		schema.registerItem( 'span', '$inline' );
+		schema.registerItem( 'image', '$inline' );
+
+		item = new SchemaItem( schema );
 	} );
-} );
-
-describe( 'allow', () => {
-	it( 'should add paths to the item as copies of passed array', () => {
-		let path1 = [ 'div', 'header' ];
-		let path2 = [ 'p' ];
-
-		item.allow( path1 );
-		item.allow( path2 );
-
-		let paths = item._getPaths( 'allow' );
-
-		expect( paths.length ).to.equal( 2 );
 
-		expect( paths[ 0 ] ).not.to.equal( path1 );
-		expect( paths[ 1 ] ).not.to.equal( path2 );
+	describe( 'constructor()', () => {
+		it( 'should create empty schema item', () => {
+			let item = new SchemaItem( schema );
 
-		expect( paths[ 0 ] ).to.deep.equal( [ 'div', 'header' ] );
-		expect( paths[ 1 ] ).to.deep.equal( [ 'p' ] );
+			expect( item._disallowed ).to.deep.equal( [] );
+			expect( item._allowed ).to.deep.equal( [] );
+		} );
 	} );
 
-	it( 'should group paths by attribute', () => {
-		item.allow( [ 'p' ], 'bold' );
-		item.allow( [ 'div' ] );
-		item.allow( [ 'header' ], 'bold' );
+	describe( 'allow', () => {
+		it( 'should add paths to the item as copies of passed array', () => {
+			let path1 = [ 'div', 'header' ];
+			let path2 = [ 'p' ];
 
-		let pathsWithNoAttribute = item._getPaths( 'allow' );
-		let pathsWithBoldAttribute = item._getPaths( 'allow', 'bold' );
+			item.allow( path1 );
+			item.allow( path2 );
 
-		expect( pathsWithNoAttribute.length ).to.equal( 1 );
-		expect( pathsWithNoAttribute[ 0 ] ).to.deep.equal( [ 'div' ] );
+			let paths = item._getPaths( 'allow' );
 
-		expect( pathsWithBoldAttribute.length ).to.equal( 2 );
-		expect( pathsWithBoldAttribute[ 0 ] ).to.deep.equal( [ 'p' ] );
-		expect( pathsWithBoldAttribute[ 1 ] ).to.deep.equal( [ 'header' ] );
-	} );
-} );
+			expect( paths.length ).to.equal( 2 );
 
-describe( 'disallow', () => {
-	it( 'should add paths to the item as copies of passed array', () => {
-		let path1 = [ 'div', 'header' ];
-		let path2 = [ 'p' ];
+			expect( paths[ 0 ] ).not.to.equal( path1 );
+			expect( paths[ 1 ] ).not.to.equal( path2 );
 
-		item.disallow( path1 );
-		item.disallow( path2 );
+			expect( paths[ 0 ] ).to.deep.equal( [ 'div', 'header' ] );
+			expect( paths[ 1 ] ).to.deep.equal( [ 'p' ] );
+		} );
 
-		let paths = item._getPaths( 'disallow' );
+		it( 'should group paths by attribute', () => {
+			item.allow( [ 'p' ], 'bold' );
+			item.allow( [ 'div' ] );
+			item.allow( [ 'header' ], 'bold' );
 
-		expect( paths.length ).to.equal( 2 );
+			let pathsWithNoAttribute = item._getPaths( 'allow' );
+			let pathsWithBoldAttribute = item._getPaths( 'allow', 'bold' );
 
-		expect( paths[ 0 ] ).not.to.equal( path1 );
-		expect( paths[ 1 ] ).not.to.equal( path2 );
+			expect( pathsWithNoAttribute.length ).to.equal( 1 );
+			expect( pathsWithNoAttribute[ 0 ] ).to.deep.equal( [ 'div' ] );
 
-		expect( paths[ 0 ] ).to.deep.equal( [ 'div', 'header' ] );
-		expect( paths[ 1 ] ).to.deep.equal( [ 'p' ] );
+			expect( pathsWithBoldAttribute.length ).to.equal( 2 );
+			expect( pathsWithBoldAttribute[ 0 ] ).to.deep.equal( [ 'p' ] );
+			expect( pathsWithBoldAttribute[ 1 ] ).to.deep.equal( [ 'header' ] );
+		} );
 	} );
 
-	it( 'should group paths by attribute', () => {
-		item.disallow( [ 'p' ], 'bold' );
-		item.disallow( [ 'div' ] );
-		item.disallow( [ 'header' ], 'bold' );
+	describe( 'disallow', () => {
+		it( 'should add paths to the item as copies of passed array', () => {
+			let path1 = [ 'div', 'header' ];
+			let path2 = [ 'p' ];
 
-		let pathsWithNoAttribute = item._getPaths( 'disallow' );
-		let pathsWithBoldAttribute = item._getPaths( 'disallow', 'bold' );
+			item.disallow( path1 );
+			item.disallow( path2 );
 
-		expect( pathsWithNoAttribute.length ).to.equal( 1 );
-		expect( pathsWithNoAttribute[ 0 ] ).to.deep.equal( [ 'div' ] );
+			let paths = item._getPaths( 'disallow' );
 
-		expect( pathsWithBoldAttribute.length ).to.equal( 2 );
-		expect( pathsWithBoldAttribute[ 0 ] ).to.deep.equal( [ 'p' ] );
-		expect( pathsWithBoldAttribute[ 1 ] ).to.deep.equal( [ 'header' ] );
-	} );
-} );
+			expect( paths.length ).to.equal( 2 );
 
-describe( '_hasMatchingPath', () => {
-	it( 'should return true if there is at least one allowed path that matches query path', () => {
-		item.allow( [ 'div' , 'header' ] );
-		item.allow( [ 'image' ] );
+			expect( paths[ 0 ] ).not.to.equal( path1 );
+			expect( paths[ 1 ] ).not.to.equal( path2 );
 
-		expect( item._hasMatchingPath( 'allow', [ 'div', 'header' ] ) ).to.be.true;
-		expect( item._hasMatchingPath( 'allow', [ 'html', 'div', 'header' ] ) ).to.be.true;
-		expect( item._hasMatchingPath( 'allow', [ 'div', 'header', 'span' ] ) ).to.be.true;
-		expect( item._hasMatchingPath( 'allow', [ 'html', 'div', 'p', 'header', 'span' ] ) ).to.be.true;
-	} );
+			expect( paths[ 0 ] ).to.deep.equal( [ 'div', 'header' ] );
+			expect( paths[ 1 ] ).to.deep.equal( [ 'p' ] );
+		} );
 
-	it( 'should return false if there are no allowed paths that match query path', () => {
-		item.allow( [ 'div', 'p' ] );
+		it( 'should group paths by attribute', () => {
+			item.disallow( [ 'p' ], 'bold' );
+			item.disallow( [ 'div' ] );
+			item.disallow( [ 'header' ], 'bold' );
 
-		expect( item._hasMatchingPath( 'allow', [ 'p' ] ) ).to.be.false;
-		expect( item._hasMatchingPath( 'allow', [ 'div' ] ) ).to.be.false;
-		expect( item._hasMatchingPath( 'allow', [ 'p', 'div' ] ) ).to.be.false;
-	} );
+			let pathsWithNoAttribute = item._getPaths( 'disallow' );
+			let pathsWithBoldAttribute = item._getPaths( 'disallow', 'bold' );
 
-	it( 'should return true if there is at least one disallowed path that matches query path', () => {
-		item.allow( [ 'div', 'header' ] );
-		item.disallow( [ 'p', 'header' ] );
+			expect( pathsWithNoAttribute.length ).to.equal( 1 );
+			expect( pathsWithNoAttribute[ 0 ] ).to.deep.equal( [ 'div' ] );
 
-		expect( item._hasMatchingPath( 'disallow', [ 'html', 'div', 'p', 'header', 'span' ] ) ).to.be.true;
+			expect( pathsWithBoldAttribute.length ).to.equal( 2 );
+			expect( pathsWithBoldAttribute[ 0 ] ).to.deep.equal( [ 'p' ] );
+			expect( pathsWithBoldAttribute[ 1 ] ).to.deep.equal( [ 'header' ] );
+		} );
 	} );
 
-	it( 'should use only paths that are registered for given attribute', () => {
-		item.allow( [ 'div', 'p' ] );
-		item.allow( [ 'div' ], 'bold' );
-		item.allow( [ 'header' ] );
-		item.disallow( [ 'header' ], 'bold' );
-
-		expect( item._hasMatchingPath( 'allow', [ 'html', 'div', 'p' ]  ) ).to.be.true;
-		expect( item._hasMatchingPath( 'allow', [ 'html', 'div' ] ) ).to.be.false;
-		expect( item._hasMatchingPath( 'allow', [ 'html', 'div' ], 'bold' ) ).to.be.true;
-
-		expect( item._hasMatchingPath( 'disallow', [ 'html', 'div', 'header' ] ) ).to.be.false;
-		expect( item._hasMatchingPath( 'disallow', [ 'html', 'div', 'p', 'header', 'span' ], 'bold' ) ).to.be.true;
+	describe( '_hasMatchingPath', () => {
+		it( 'should return true if there is at least one allowed path that matches query path', () => {
+			item.allow( [ 'div' , 'header' ] );
+			item.allow( [ 'image' ] );
+
+			expect( item._hasMatchingPath( 'allow', [ 'div', 'header' ] ) ).to.be.true;
+			expect( item._hasMatchingPath( 'allow', [ 'html', 'div', 'header' ] ) ).to.be.true;
+			expect( item._hasMatchingPath( 'allow', [ 'div', 'header', 'span' ] ) ).to.be.true;
+			expect( item._hasMatchingPath( 'allow', [ 'html', 'div', 'p', 'header', 'span' ] ) ).to.be.true;
+		} );
+
+		it( 'should return false if there are no allowed paths that match query path', () => {
+			item.allow( [ 'div', 'p' ] );
+
+			expect( item._hasMatchingPath( 'allow', [ 'p' ] ) ).to.be.false;
+			expect( item._hasMatchingPath( 'allow', [ 'div' ] ) ).to.be.false;
+			expect( item._hasMatchingPath( 'allow', [ 'p', 'div' ] ) ).to.be.false;
+		} );
+
+		it( 'should return true if there is at least one disallowed path that matches query path', () => {
+			item.allow( [ 'div', 'header' ] );
+			item.disallow( [ 'p', 'header' ] );
+
+			expect( item._hasMatchingPath( 'disallow', [ 'html', 'div', 'p', 'header', 'span' ] ) ).to.be.true;
+		} );
+
+		it( 'should use only paths that are registered for given attribute', () => {
+			item.allow( [ 'div', 'p' ] );
+			item.allow( [ 'div' ], 'bold' );
+			item.allow( [ 'header' ] );
+			item.disallow( [ 'header' ], 'bold' );
+
+			expect( item._hasMatchingPath( 'allow', [ 'html', 'div', 'p' ]  ) ).to.be.true;
+			expect( item._hasMatchingPath( 'allow', [ 'html', 'div' ] ) ).to.be.false;
+			expect( item._hasMatchingPath( 'allow', [ 'html', 'div' ], 'bold' ) ).to.be.true;
+
+			expect( item._hasMatchingPath( 'disallow', [ 'html', 'div', 'header' ] ) ).to.be.false;
+			expect( item._hasMatchingPath( 'disallow', [ 'html', 'div', 'p', 'header', 'span' ], 'bold' ) ).to.be.true;
+		} );
 	} );
-} );
 
-describe( 'toJSON', () => {
-	it( 'should create proper JSON string', () => {
-		let parsedItem = JSON.parse( JSON.stringify( item ) );
+	describe( 'toJSON', () => {
+		it( 'should create proper JSON string', () => {
+			let parsedItem = JSON.parse( JSON.stringify( item ) );
 
-		expect( parsedItem._schema ).to.equal( '[model.Schema]' );
+			expect( parsedItem._schema ).to.equal( '[model.Schema]' );
+		} );
 	} );
 } );