|
|
@@ -20,9 +20,9 @@ describe( 'LinkCommand', () => {
|
|
|
// Allow text in $root.
|
|
|
document.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
|
|
|
- // Allow text with link attribute in paragraph.
|
|
|
+ // Allow text with linkHref attribute in paragraph.
|
|
|
document.schema.registerItem( 'p', '$block' );
|
|
|
- document.schema.allow( { name: '$text', attributes: 'link', inside: '$root' } );
|
|
|
+ document.schema.allow( { name: '$text', attributes: 'linkHref', inside: '$root' } );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
@@ -32,13 +32,13 @@ describe( 'LinkCommand', () => {
|
|
|
|
|
|
describe( 'value', () => {
|
|
|
describe( 'collapsed selection', () => {
|
|
|
- it( 'should be equal attribute value when selection is placed inside element with link attribute', () => {
|
|
|
- setData( document, `<$text link="url">foo[]bar</$text>` );
|
|
|
+ it( 'should be equal attribute value when selection is placed inside element with linkHref attribute', () => {
|
|
|
+ setData( document, `<$text linkHref="url">foo[]bar</$text>` );
|
|
|
|
|
|
expect( command.value ).to.equal( 'url' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should be undefined when selection is placed inside element without link attribute', () => {
|
|
|
+ it( 'should be undefined when selection is placed inside element without linkHref attribute', () => {
|
|
|
setData( document, `<$text bold="true">foo[]bar</$text>` );
|
|
|
|
|
|
expect( command.value ).to.undefined;
|
|
|
@@ -46,14 +46,14 @@ describe( 'LinkCommand', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'non-collapsed selection', () => {
|
|
|
- it( 'should be equal attribute value when selection contains only elements with link attribute', () => {
|
|
|
- setData( document, 'fo[<$text link="url">ob</$text>]ar' );
|
|
|
+ it( 'should be equal attribute value when selection contains only elements with linkHref attribute', () => {
|
|
|
+ setData( document, 'fo[<$text linkHref="url">ob</$text>]ar' );
|
|
|
|
|
|
expect( command.value ).to.equal( 'url' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should be undefined when selection contains not only elements with link attribute', () => {
|
|
|
- setData( document, 'f[o<$text link="url">ob</$text>]ar' );
|
|
|
+ it( 'should be undefined when selection contains not only elements with linkHref attribute', () => {
|
|
|
+ setData( document, 'f[o<$text linkHref="url">ob</$text>]ar' );
|
|
|
|
|
|
expect( command.value ).to.undefined;
|
|
|
} );
|
|
|
@@ -62,18 +62,18 @@ describe( 'LinkCommand', () => {
|
|
|
|
|
|
describe( '_doExecute', () => {
|
|
|
describe( 'non-collapsed selection', () => {
|
|
|
- it( 'should set link attribute to selected text', () => {
|
|
|
+ it( 'should set linkHref attribute to selected text', () => {
|
|
|
setData( document, 'f[ooba]r' );
|
|
|
|
|
|
expect( command.value ).to.undefined;
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
- expect( getData( document ) ).to.equal( 'f[<$text link="url">ooba</$text>]r' );
|
|
|
+ expect( getData( document ) ).to.equal( 'f[<$text linkHref="url">ooba</$text>]r' );
|
|
|
expect( command.value ).to.equal( 'url' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should set link attribute to selected text when text already has attributes', () => {
|
|
|
+ it( 'should set linkHref attribute to selected text when text already has attributes', () => {
|
|
|
setData( document, 'f[o<$text bold="true">oba]r</$text>' );
|
|
|
|
|
|
expect( command.value ).to.undefined;
|
|
|
@@ -81,56 +81,66 @@ describe( 'LinkCommand', () => {
|
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
expect( command.value ).to.equal( 'url' );
|
|
|
- expect( getData( document ) )
|
|
|
- .to.equal( 'f[<$text link="url">o</$text><$text bold="true" link="url">oba</$text>]<$text bold="true">r</$text>' );
|
|
|
+ expect( getData( document ) ).to.equal(
|
|
|
+ 'f[<$text linkHref="url">o</$text>' +
|
|
|
+ '<$text bold="true" linkHref="url">oba</$text>]' +
|
|
|
+ '<$text bold="true">r</$text>'
|
|
|
+ );
|
|
|
} );
|
|
|
|
|
|
- it( 'should overwrite existing link attribute when selected text wraps text with link attribute', () => {
|
|
|
- setData( document, 'f[o<$text link="other url">o</$text>ba]r' );
|
|
|
+ it( 'should overwrite existing linkHref attribute when selected text wraps text with linkHref attribute', () => {
|
|
|
+ setData( document, 'f[o<$text linkHref="other url">o</$text>ba]r' );
|
|
|
|
|
|
expect( command.value ).to.undefined;
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
- expect( getData( document ) ).to.equal( 'f[<$text link="url">ooba</$text>]r' );
|
|
|
+ expect( getData( document ) ).to.equal( 'f[<$text linkHref="url">ooba</$text>]r' );
|
|
|
expect( command.value ).to.equal( 'url' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should split text and overwrite attribute value when selection is inside text with link attribute', () => {
|
|
|
- setData( document, 'f<$text link="other url">o[ob]a</$text>r' );
|
|
|
+ it( 'should split text and overwrite attribute value when selection is inside text with linkHref attribute', () => {
|
|
|
+ setData( document, 'f<$text linkHref="other url">o[ob]a</$text>r' );
|
|
|
|
|
|
expect( command.value ).to.equal( 'other url' );
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
- expect( getData( document ) )
|
|
|
- .to.equal( 'f<$text link="other url">o</$text>[<$text link="url">ob</$text>]<$text link="other url">a</$text>r' );
|
|
|
+ expect( getData( document ) ).to.equal(
|
|
|
+ 'f' +
|
|
|
+ '<$text linkHref="other url">o</$text>' +
|
|
|
+ '[<$text linkHref="url">ob</$text>]' +
|
|
|
+ '<$text linkHref="other url">a</$text>' +
|
|
|
+ 'r'
|
|
|
+ );
|
|
|
expect( command.value ).to.equal( 'url' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should overwrite link attribute of selected text only, when selection start inside text with link attribute', () => {
|
|
|
- setData( document, 'f<$text link="other url">o[o</$text>ba]r' );
|
|
|
+ it(
|
|
|
+ 'should overwrite linkHref attribute of selected text only, when selection start inside text with linkHref attribute',
|
|
|
+ () => {
|
|
|
+ setData( document, 'f<$text linkHref="other url">o[o</$text>ba]r' );
|
|
|
|
|
|
expect( command.value ).to.equal( 'other url' );
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
- expect( getData( document ) ).to.equal( 'f<$text link="other url">o</$text>[<$text link="url">oba</$text>]r' );
|
|
|
+ expect( getData( document ) ).to.equal( 'f<$text linkHref="other url">o</$text>[<$text linkHref="url">oba</$text>]r' );
|
|
|
expect( command.value ).to.equal( 'url' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should overwrite link attribute of selected text only, when selection end inside text with link attribute', () => {
|
|
|
- setData( document, 'f[o<$text link="other url">ob]a</$text>r' );
|
|
|
+ it( 'should overwrite linkHref attribute of selected text only, when selection end inside text with linkHref attribute', () => {
|
|
|
+ setData( document, 'f[o<$text linkHref="other url">ob]a</$text>r' );
|
|
|
|
|
|
expect( command.value ).to.undefined;
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
- expect( getData( document ) ).to.equal( 'f[<$text link="url">oob</$text>]<$text link="other url">a</$text>r' );
|
|
|
+ expect( getData( document ) ).to.equal( 'f[<$text linkHref="url">oob</$text>]<$text linkHref="other url">a</$text>r' );
|
|
|
expect( command.value ).to.equal( 'url' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should set link attribute to selected text when text is split by $block element', () => {
|
|
|
+ it( 'should set linkHref attribute to selected text when text is split by $block element', () => {
|
|
|
setData( document, '<p>f[oo</p><p>ba]r</p>' );
|
|
|
|
|
|
expect( command.value ).to.undefined;
|
|
|
@@ -138,14 +148,14 @@ describe( 'LinkCommand', () => {
|
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
expect( getData( document ) )
|
|
|
- .to.equal( '<p>f[<$text link="url">oo</$text></p><p><$text link="url">ba</$text>]r</p>' );
|
|
|
+ .to.equal( '<p>f[<$text linkHref="url">oo</$text></p><p><$text linkHref="url">ba</$text>]r</p>' );
|
|
|
expect( command.value ).to.equal( 'url' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should set link attribute only to allowed elements and omit disallowed', () => {
|
|
|
+ it( 'should set linkHref attribute only to allowed elements and omit disallowed', () => {
|
|
|
// Disallow text in img.
|
|
|
document.schema.registerItem( 'img', '$block' );
|
|
|
- document.schema.disallow( { name: '$text', attributes: 'link', inside: 'img' } );
|
|
|
+ document.schema.disallow( { name: '$text', attributes: 'linkHref', inside: 'img' } );
|
|
|
|
|
|
setData( document, '<p>f[oo<img></img>ba]r</p>' );
|
|
|
|
|
|
@@ -154,31 +164,36 @@ describe( 'LinkCommand', () => {
|
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
expect( getData( document ) )
|
|
|
- .to.equal( '<p>f[<$text link="url">oo</$text><img></img><$text link="url">ba</$text>]r</p>' );
|
|
|
+ .to.equal( '<p>f[<$text linkHref="url">oo</$text><img></img><$text linkHref="url">ba</$text>]r</p>' );
|
|
|
expect( command.value ).to.equal( 'url' );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( 'collapsed selection', () => {
|
|
|
- it( 'should insert text with link attribute and data equal to href', () => {
|
|
|
+ it( 'should insert text with linkHref attribute and data equal to href', () => {
|
|
|
setData( document, 'foo[]bar' );
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
- expect( getData( document ) ).to.equal( 'foo[<$text link="url">url</$text>]bar' );
|
|
|
+ expect( getData( document ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should insert text with link attribute and data equal to href when selection is inside text with link attribute', () => {
|
|
|
- setData( document, '<$text link="other url">foo[]bar</$text>' );
|
|
|
+ it(
|
|
|
+ 'should insert text with linkHref attribute and data equal to href when selection is inside text with linkHref attribute',
|
|
|
+ () => {
|
|
|
+ setData( document, '<$text linkHref="other url">foo[]bar</$text>' );
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
- expect( getData( document ) )
|
|
|
- .to.equal( '<$text link="other url">foo</$text>[<$text link="url">url</$text>]<$text link="other url">bar</$text>' );
|
|
|
+ expect( getData( document ) ).to.equal(
|
|
|
+ '<$text linkHref="other url">foo</$text>' +
|
|
|
+ '[<$text linkHref="url">url</$text>]' +
|
|
|
+ '<$text linkHref="other url">bar</$text>'
|
|
|
+ );
|
|
|
} );
|
|
|
|
|
|
- it( 'should not insert text with link attribute when is not allowed in parent', () => {
|
|
|
- document.schema.disallow( { name: '$text', attributes: 'link', inside: 'p' } );
|
|
|
+ it( 'should not insert text with linkHref attribute when is not allowed in parent', () => {
|
|
|
+ document.schema.disallow( { name: '$text', attributes: 'linkHref', inside: 'p' } );
|
|
|
setData( document, '<p>foo[]bar</p>' );
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
|
@@ -194,7 +209,7 @@ describe( 'LinkCommand', () => {
|
|
|
|
|
|
beforeEach( () => {
|
|
|
document.schema.registerItem( 'x', '$block' );
|
|
|
- document.schema.disallow( { name: '$text', inside: 'x', attributes: 'link' } );
|
|
|
+ document.schema.disallow( { name: '$text', inside: 'x', attributes: 'linkHref' } );
|
|
|
} );
|
|
|
|
|
|
describe( 'when selection is collapsed', () => {
|