From 990e424470f4379271390132b31338e64b5f6150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Wed, 20 Dec 2017 22:50:48 +0100 Subject: [PATCH] WIP --- tests/model/schema/schema2.js | 121 ++++++++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 19 deletions(-) diff --git a/tests/model/schema/schema2.js b/tests/model/schema/schema2.js index 4160c9b4d..673c1f83a 100644 --- a/tests/model/schema/schema2.js +++ b/tests/model/schema/schema2.js @@ -697,26 +697,22 @@ describe( 'Schema', () => { } ); describe( 'real scenarios', () => { - let r1bQi, r1i; + let r1bQi, r1i, r1lI, r1bQlI; const rules = [ () => { - schema.register( '$root' ); - }, - () => { - schema.register( '$block', { - allowIn: '$root' - } ); - }, - () => { - schema.register( '$text', { - allowIn: '$block' + schema.register( 'paragraph', { + allowWhere: '$block', + allowContentOf: '$block', + allowAttributesOf: '$block' } ); }, () => { - schema.register( 'paragraph', { + schema.register( 'listItem', { allowWhere: '$block', - allowContentOf: '$block' + allowContentOf: '$block', + allowAttributes: [ 'indent', 'type' ], + allowAttributesOf: '$block' } ); }, () => { @@ -727,7 +723,8 @@ describe( 'Schema', () => { }, () => { schema.register( 'image', { - allowWhere: '$block' + allowWhere: '$block', + allowAttributes: [ 'src', 'alt' ] } ); }, () => { @@ -735,10 +732,28 @@ describe( 'Schema', () => { allowIn: 'image', allowContentOf: '$block' } ); + }, + () => { + schema.extend( '$text', { + allowAttributes: [ 'bold', 'italic' ] + } ); + }, + () => { + schema.extend( '$block', { + allowAttributes: 'alignment' + } ); } ]; beforeEach( () => { + schema.register( '$root' ); + schema.register( '$block', { + allowIn: '$root' + } ); + schema.register( '$text', { + allowIn: '$block' + } ); + for ( const rule of rules ) { rule(); } @@ -757,9 +772,11 @@ describe( 'Schema', () => { root1 = new Element( '$root', null, [ new Element( 'paragraph', null, 'foo' ), - new Element( 'paragraph', { align: 'right' }, 'bar' ), + new Element( 'paragraph', { alignment: 'right' }, 'bar' ), + new Element( 'listItem', { type: 'x', indent: 0 }, 'foo' ), new Element( 'blockQuote', null, [ new Element( 'paragraph', null, 'foo' ), + new Element( 'listItem', { type: 'x', indent: 0 }, 'foo' ), new Element( 'image', null, [ new Element( 'caption', null, 'foo' ) ] ) @@ -770,10 +787,12 @@ describe( 'Schema', () => { ] ); r1p1 = root1.getChild( 0 ); r1p2 = root1.getChild( 1 ); - r1bQ = root1.getChild( 2 ); + r1lI = root1.getChild( 2 ); + r1bQ = root1.getChild( 3 ); + r1i = root1.getChild( 4 ); r1bQp = r1bQ.getChild( 0 ); - r1bQi = r1bQ.getChild( 1 ); - r1i = root1.getChild( 3 ); + r1bQlI = r1bQ.getChild( 1 ); + r1bQi = r1bQ.getChild( 2 ); } ); it( 'passes $root>paragraph', () => { @@ -782,7 +801,15 @@ describe( 'Schema', () => { it( 'passes $root>paragraph>$text', () => { expect( schema.checkChild( r1p1, '$text' ), 'paragraph' ).to.be.true; - expect( schema.checkChild( r1p2, '$text' ), 'paragraph[align]' ).to.be.true; + expect( schema.checkChild( r1p2, '$text' ), 'paragraph[alignment]' ).to.be.true; + } ); + + it( 'passes $root>listItem', () => { + expect( schema.checkChild( root1, 'listItem' ) ).to.be.true; + } ); + + it( 'passes $root>listItem>$text', () => { + expect( schema.checkChild( r1lI, '$text' ) ).to.be.true; } ); it( 'passes $root>blockQuote>paragraph', () => { @@ -793,6 +820,14 @@ describe( 'Schema', () => { expect( schema.checkChild( r1bQp, '$text' ) ).to.be.true; } ); + it( 'passes $root>blockQuote>listItem', () => { + expect( schema.checkChild( r1bQ, 'listItem' ) ).to.be.true; + } ); + + it( 'passes $root>blockQuote>listItem>$text', () => { + expect( schema.checkChild( r1bQlI, '$text' ) ).to.be.true; + } ); + it( 'passes $root>blockQuote>image', () => { expect( schema.checkChild( r1bQ, 'image' ) ).to.be.true; } ); @@ -881,6 +916,54 @@ describe( 'Schema', () => { it( 'rejects $root>image>caption>blockQuote', () => { expect( schema.checkChild( r1i.getChild( 0 ), 'blockQuote' ) ).to.be.false; } ); + + it( 'accepts attribute paragraph[alignment]', () => { + expect( schema.checkAttribute( r1p1, 'alignment' ) ).to.be.true; + } ); + + it( 'accepts attribute listItem[alignment]', () => { + expect( schema.checkAttribute( r1lI, 'alignment' ) ).to.be.true; + } ); + + it( 'accepts attribute listItem[indent]', () => { + expect( schema.checkAttribute( r1lI, 'indent' ) ).to.be.true; + } ); + + it( 'accepts attribute listItem[type]', () => { + expect( schema.checkAttribute( r1lI, 'type' ) ).to.be.true; + } ); + + it( 'accepts attribute image[src]', () => { + expect( schema.checkAttribute( r1i, 'src' ) ).to.be.true; + } ); + + it( 'accepts attribute image[alt]', () => { + expect( schema.checkAttribute( r1i, 'alt' ) ).to.be.true; + } ); + + it( 'rejects attribute $root[indent]', () => { + expect( schema.checkAttribute( root1, 'indent' ) ).to.be.false; + } ); + + it( 'rejects attribute paragraph[indent]', () => { + expect( schema.checkAttribute( r1p1, 'indent' ) ).to.be.false; + } ); + + it( 'rejects attribute blockQuote[indent]', () => { + expect( schema.checkAttribute( r1bQ, 'indent' ) ).to.be.false; + } ); + + it( 'rejects attribute blockQuote[alignment]', () => { + expect( schema.checkAttribute( r1bQ, 'alignment' ) ).to.be.false; + } ); + + it( 'rejects attribute image[indent]', () => { + expect( schema.checkAttribute( r1i, 'indent' ) ).to.be.false; + } ); + + it( 'rejects attribute image[alignment]', () => { + expect( schema.checkAttribute( r1i, 'alignment' ) ).to.be.false; + } ); } ); // TODO: