Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Dec 20, 2017
1 parent da82aff commit 483cf59
Showing 1 changed file with 102 additions and 19 deletions.
121 changes: 102 additions & 19 deletions tests/model/schema/schema2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
} );
},
() => {
Expand All @@ -727,18 +723,37 @@ describe( 'Schema', () => {
},
() => {
schema.register( 'image', {
allowWhere: '$block'
allowWhere: '$block',
allowAttributes: [ 'src', 'alt' ]
} );
},
() => {
schema.register( 'caption', {
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();
}
Expand All @@ -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' )
] )
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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;
} );
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 483cf59

Please sign in to comment.