|
@@ -30,18 +30,18 @@ describe( 'LinkCommand', () => {
|
|
|
command.destroy();
|
|
command.destroy();
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'isValue', () => {
|
|
|
|
|
|
|
+ describe( 'hasValue', () => {
|
|
|
describe( 'collapsed selection', () => {
|
|
describe( 'collapsed selection', () => {
|
|
|
it( 'should be equal `true` when selection is placed inside element with link attribute', () => {
|
|
it( 'should be equal `true` when selection is placed inside element with link attribute', () => {
|
|
|
setData( document, `<$text link="url">foo[]bar</$text>` );
|
|
setData( document, `<$text link="url">foo[]bar</$text>` );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should be equal `false` when selection is placed inside element without link attribute', () => {
|
|
it( 'should be equal `false` when selection is placed inside element without link attribute', () => {
|
|
|
setData( document, `<$text bold="true">foo[]bar</$text>` );
|
|
setData( document, `<$text bold="true">foo[]bar</$text>` );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.false;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.false;
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -49,13 +49,13 @@ describe( 'LinkCommand', () => {
|
|
|
it( 'should be equal `true` when selection contains only elements with link attribute', () => {
|
|
it( 'should be equal `true` when selection contains only elements with link attribute', () => {
|
|
|
setData( document, 'fo[<$text link="url">ob</$text>]ar' );
|
|
setData( document, 'fo[<$text link="url">ob</$text>]ar' );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should be equal `false` when selection contains not only elements with link attribute', () => {
|
|
it( 'should be equal `false` when selection contains not only elements with link attribute', () => {
|
|
|
setData( document, 'f[o<$text link="url">ob</$text>]ar' );
|
|
setData( document, 'f[o<$text link="url">ob</$text>]ar' );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.false;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.false;
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
@@ -65,81 +65,81 @@ describe( 'LinkCommand', () => {
|
|
|
it( 'should set link attribute to selected text', () => {
|
|
it( 'should set link attribute to selected text', () => {
|
|
|
setData( document, 'f[ooba]r' );
|
|
setData( document, 'f[ooba]r' );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.false;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.false;
|
|
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
|
|
expect( getData( document ) ).to.equal( 'f[<$text link="url">ooba</$text>]r' );
|
|
expect( getData( document ) ).to.equal( 'f[<$text link="url">ooba</$text>]r' );
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should set link attribute to selected text when text already has attributes', () => {
|
|
it( 'should set link attribute to selected text when text already has attributes', () => {
|
|
|
setData( document, 'f[o<$text bold="true">oba]r</$text>' );
|
|
setData( document, 'f[o<$text bold="true">oba]r</$text>' );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.false;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.false;
|
|
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
expect( getData( document ) )
|
|
expect( getData( document ) )
|
|
|
.to.equal( 'f[<$text link="url">o</$text><$text bold="true" link="url">oba</$text>]<$text bold="true">r</$text>' );
|
|
.to.equal( 'f[<$text link="url">o</$text><$text bold="true" link="url">oba</$text>]<$text bold="true">r</$text>' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should overwrite existing link attribute when selected text wraps text with link attribute', () => {
|
|
it( 'should overwrite existing link attribute when selected text wraps text with link attribute', () => {
|
|
|
- setData( document, 'f[o<$text link="some url">o</$text>ba]r' );
|
|
|
|
|
|
|
+ setData( document, 'f[o<$text link="other url">o</$text>ba]r' );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.false;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.false;
|
|
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
|
|
expect( getData( document ) ).to.equal( 'f[<$text link="url">ooba</$text>]r' );
|
|
expect( getData( document ) ).to.equal( 'f[<$text link="url">ooba</$text>]r' );
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should split text and overwrite attribute value when selection is inside text with link attribute', () => {
|
|
it( 'should split text and overwrite attribute value when selection is inside text with link attribute', () => {
|
|
|
- setData( document, 'f<$text link="some url">o[ob]a</$text>r' );
|
|
|
|
|
|
|
+ setData( document, 'f<$text link="other url">o[ob]a</$text>r' );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
|
|
expect( getData( document ) )
|
|
expect( getData( document ) )
|
|
|
- .to.equal( 'f<$text link="some url">o</$text>[<$text link="url">ob</$text>]<$text link="some url">a</$text>r' );
|
|
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ .to.equal( 'f<$text link="other url">o</$text>[<$text link="url">ob</$text>]<$text link="other url">a</$text>r' );
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should overwrite link attribute of selected text only, when selection starts inside text with link attribute', () => {
|
|
|
|
|
- setData( document, 'f<$text link="some url">o[o</$text>ba]r' );
|
|
|
|
|
|
|
+ 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' );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
|
|
- expect( getData( document ) ).to.equal( 'f<$text link="some url">o</$text>[<$text link="url">oba</$text>]r' );
|
|
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ expect( getData( document ) ).to.equal( 'f<$text link="other url">o</$text>[<$text link="url">oba</$text>]r' );
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should overwrite link attribute of selected text only, when selection end inside text with link attribute', () => {
|
|
it( 'should overwrite link attribute of selected text only, when selection end inside text with link attribute', () => {
|
|
|
- setData( document, 'f[o<$text link="some url">ob]a</$text>r' );
|
|
|
|
|
|
|
+ setData( document, 'f[o<$text link="other url">ob]a</$text>r' );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.false;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.false;
|
|
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
|
|
- expect( getData( document ) ).to.equal( 'f[<$text link="url">oob</$text>]<$text link="some url">a</$text>r' );
|
|
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ expect( getData( document ) ).to.equal( 'f[<$text link="url">oob</$text>]<$text link="other url">a</$text>r' );
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should set link attribute to selected text when text is split by $block element', () => {
|
|
it( 'should set link attribute to selected text when text is split by $block element', () => {
|
|
|
setData( document, '<p>f[oo</p><p>ba]r</p>' );
|
|
setData( document, '<p>f[oo</p><p>ba]r</p>' );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.false;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.false;
|
|
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
|
|
expect( getData( document ) )
|
|
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 link="url">oo</$text></p><p><$text link="url">ba</$text>]r</p>' );
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should set link attribute only to allowed elements and omit disallowed', () => {
|
|
it( 'should set link attribute only to allowed elements and omit disallowed', () => {
|
|
@@ -149,13 +149,13 @@ describe( 'LinkCommand', () => {
|
|
|
|
|
|
|
|
setData( document, '<p>f[oo<img></img>ba]r</p>' );
|
|
setData( document, '<p>f[oo<img></img>ba]r</p>' );
|
|
|
|
|
|
|
|
- expect( command.isValue ).to.false;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.false;
|
|
|
|
|
|
|
|
command._doExecute( 'url' );
|
|
command._doExecute( 'url' );
|
|
|
|
|
|
|
|
expect( getData( document ) )
|
|
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 link="url">oo</$text><img></img><$text link="url">ba</$text>]r</p>' );
|
|
|
- expect( command.isValue ).to.true;
|
|
|
|
|
|
|
+ expect( command.hasValue ).to.true;
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -168,7 +168,16 @@ describe( 'LinkCommand', () => {
|
|
|
expect( getData( document ) ).to.equal( 'foo[<$text link="url">url</$text>]bar' );
|
|
expect( getData( document ) ).to.equal( 'foo[<$text link="url">url</$text>]bar' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should not insert text with link attribute when text is not allowed in parent', () => {
|
|
|
|
|
|
|
+ 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>' );
|
|
|
|
|
+
|
|
|
|
|
+ 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>' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should not insert text with link attribute when is not allowed in parent', () => {
|
|
|
document.schema.disallow( { name: '$text', attributes: 'link', inside: 'p' } );
|
|
document.schema.disallow( { name: '$text', attributes: 'link', inside: 'p' } );
|
|
|
setData( document, '<p>foo[]bar</p>' );
|
|
setData( document, '<p>foo[]bar</p>' );
|
|
|
|
|
|