-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manual link decorators for images will not crash decorators for linked text #8119
Changes from 5 commits
65f3519
052032c
3cbb748
a344f4e
dec11ed
b5a2d00
4d734d4
58fc76d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -711,4 +711,155 @@ describe( 'LinkImageEditing', () => { | |||
} ); | ||||
} ); | ||||
} ); | ||||
|
||||
describe( 'integration', () => { | ||||
let editor, model; | ||||
|
||||
beforeEach( () => { | ||||
return VirtualTestEditor | ||||
.create( { | ||||
plugins: [ Paragraph, LinkImageEditing ], | ||||
link: { | ||||
decorators: { | ||||
isExternal: { | ||||
mode: 'manual', | ||||
label: 'Open in a new tab', | ||||
attributes: { | ||||
target: '_blank', | ||||
rel: 'noopener noreferrer' | ||||
} | ||||
}, | ||||
isDownloadable: { | ||||
mode: 'manual', | ||||
label: 'Downloadable', | ||||
attributes: { | ||||
download: 'download' | ||||
} | ||||
}, | ||||
isGallery: { | ||||
mode: 'manual', | ||||
label: 'Gallery link', | ||||
attributes: { | ||||
class: 'gallery' | ||||
} | ||||
} | ||||
} | ||||
} | ||||
} ) | ||||
.then( newEditor => { | ||||
editor = newEditor; | ||||
model = editor.model; | ||||
} ); | ||||
} ); | ||||
|
||||
afterEach( () => { | ||||
return editor.destroy(); | ||||
} ); | ||||
|
||||
// See: #7975. | ||||
describe( 'manual decorators: linked text and linked image', () => { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're testing the upcast implementation here and there are already two tests for handling link decorators during the upcast. Wouldn't it make sense to put your unit tests next to it? I think a good idea would be to nest decorator-related suite in the That should result with nice and tight suite. |
||||
it( 'should upcast the decorators when linked image (figure > a > img)', () => { | ||||
editor.setData( | ||||
'<figure class="image">' + | ||||
'<a class="gallery" href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' + | ||||
'<img src="sample.jpg" alt="bar">' + | ||||
'</a>' + | ||||
'<figcaption>Caption</figcaption>' + | ||||
'</figure>' + | ||||
'<p>' + | ||||
'<a href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' + | ||||
'https://cksource.com' + | ||||
'</a>' + | ||||
'</p>' | ||||
); | ||||
|
||||
expect( getModelData( model, { withoutSelection: true } ) ).to.equal( | ||||
'<image alt="bar" ' + | ||||
'linkHref="https://cksource.com" ' + | ||||
'linkIsDownloadable="true" ' + | ||||
'linkIsExternal="true" ' + | ||||
'linkIsGallery="true" ' + | ||||
'src="sample.jpg">' + | ||||
'</image>' + | ||||
'<paragraph>' + | ||||
'<$text linkHref="https://cksource.com" linkIsDownloadable="true" linkIsExternal="true">' + | ||||
'https://cksource.com' + | ||||
'</$text>' + | ||||
'</paragraph>' | ||||
); | ||||
} ); | ||||
|
||||
it( 'should upcast the decorators when linked image (a > img)', () => { | ||||
editor.setData( | ||||
'<a class="gallery" href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' + | ||||
'<img src="sample.jpg" alt="bar">' + | ||||
'</a>' + | ||||
'<p>' + | ||||
'<a href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' + | ||||
'https://cksource.com' + | ||||
'</a>' + | ||||
'</p>' | ||||
); | ||||
|
||||
expect( getModelData( model, { withoutSelection: true } ) ).to.equal( | ||||
'<image alt="bar" ' + | ||||
'linkHref="https://cksource.com" ' + | ||||
'linkIsDownloadable="true" ' + | ||||
'linkIsExternal="true" ' + | ||||
'linkIsGallery="true" ' + | ||||
'src="sample.jpg">' + | ||||
'</image>' + | ||||
'<paragraph>' + | ||||
'<$text linkHref="https://cksource.com" linkIsDownloadable="true" linkIsExternal="true">' + | ||||
'https://cksource.com' + | ||||
'</$text>' + | ||||
'</paragraph>' | ||||
); | ||||
} ); | ||||
|
||||
it( 'should downcast the decorators after applying a change', () => { | ||||
setModelData( model, | ||||
'<image alt="bar" src="sample.jpg"></image>' + | ||||
'<paragraph>' + | ||||
'<$text>https://cksource.com</$text>' + | ||||
'</paragraph>' | ||||
); | ||||
|
||||
model.change( writer => { | ||||
// <image> | ||||
writer.setSelection( model.document.getRoot().getChild( 0 ), 'on' ); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A much simpler approach is to select image by enclosing it in brackets in line
Like so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a side note: I checked that the image does not necessarily need a focus, as the test passes if I remove this particular |
||||
} ); | ||||
|
||||
editor.execute( 'link', 'https://cksource.com', { | ||||
linkIsDownloadable: true, | ||||
linkIsExternal: true, | ||||
linkIsGallery: true | ||||
} ); | ||||
|
||||
model.change( writer => { | ||||
// <$text> | ||||
writer.setSelection( model.document.getRoot().getChild( 1 ).getChild( 0 ), 'on' ); | ||||
} ); | ||||
|
||||
editor.execute( 'link', 'https://cksource.com', { | ||||
linkIsDownloadable: true, | ||||
linkIsExternal: true, | ||||
linkIsGallery: true | ||||
} ); | ||||
|
||||
expect( editor.getData() ).to.equal( | ||||
'<figure class="image">' + | ||||
'<a class="gallery" href="https://cksource.com" download="download" target="_blank" rel="noopener noreferrer">' + | ||||
'<img src="sample.jpg" alt="bar">' + | ||||
'</a>' + | ||||
'</figure>' + | ||||
'<p>' + | ||||
'<a class="gallery" href="https://cksource.com" download="download" target="_blank" rel="noopener noreferrer">' + | ||||
'https://cksource.com' + | ||||
'</a>' + | ||||
'</p>' | ||||
); | ||||
} ); | ||||
} ); | ||||
} ); | ||||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that for better readability we can simplify it just to one or max two decorators to get the full coverage and keep the markup simpler.