33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
6- import { ClassicEditor , ImageBlock , ImageInline , ImageResizeEditing , Paragraph } from 'ckeditor5'
6+ import { ClassicEditor , ImageBlock , ImageInline , ImageResizeEditing , ImageStyleEditing , Paragraph } from 'ckeditor5'
77import ImageDowncastPlugin from '../../../../ckeditor/image/ImageDowncastPlugin.ts'
88
99// The editor UI observes the size of its toolbar, which jsdom does not provide.
@@ -26,9 +26,12 @@ async function downcast(initialData) {
2626 const editor = await ClassicEditor . create ( element , {
2727 licenseKey : 'GPL' ,
2828 initialData,
29- plugins : [ Paragraph , ImageBlock , ImageInline , ImageResizeEditing , ImageDowncastPlugin ] ,
29+ plugins : [ Paragraph , ImageBlock , ImageInline , ImageResizeEditing , ImageStyleEditing , ImageDowncastPlugin ] ,
3030 image : {
3131 resizeUnit : 'px' ,
32+ styles : {
33+ options : [ 'alignBlockLeft' , 'alignCenter' , 'alignBlockRight' ] ,
34+ } ,
3235 } ,
3336 } )
3437
@@ -109,4 +112,36 @@ describe('ImageDowncastPlugin', () => {
109112 expect ( resent ) . toContain ( 'width:200px;' )
110113 expect ( resent ) . not . toContain ( 'height=' )
111114 } )
115+
116+ it ( 'inlines the styles of a centred image' , async ( ) => {
117+ const data = await downcast ( '<figure class="image image-style-align-center"><img src="test.png"></figure>' )
118+
119+ expect ( data ) . toContain ( 'margin-left:auto;' )
120+ expect ( data ) . toContain ( 'margin-right:auto;' )
121+ expect ( data ) . toContain ( 'text-align:center;' )
122+ expect ( data ) . toContain ( 'image-style-align-center' )
123+ } )
124+
125+ it ( 'inlines the styles of a right aligned image' , async ( ) => {
126+ const data = await downcast ( '<figure class="image image-style-block-align-right"><img src="test.png"></figure>' )
127+
128+ expect ( data ) . toContain ( 'margin-left:auto;' )
129+ expect ( data ) . toContain ( 'margin-right:0;' )
130+ expect ( data ) . toContain ( 'text-align:right;' )
131+ } )
132+
133+ it ( 'left aligns an image without a style class' , async ( ) => {
134+ const data = await downcast ( '<figure class="image"><img src="test.png"></figure>' )
135+
136+ expect ( data ) . toContain ( 'margin-left:0;' )
137+ expect ( data ) . toContain ( 'margin-right:auto;' )
138+ expect ( data ) . toContain ( 'text-align:left;' )
139+ } )
140+
141+ it ( 'keeps the alignment when the message is reopened and sent again' , async ( ) => {
142+ const sent = await downcast ( '<figure class="image image-style-align-center"><img src="test.png"></figure>' )
143+ const resent = await downcast ( sent )
144+
145+ expect ( resent ) . toContain ( 'text-align:center;' )
146+ } )
112147} )
0 commit comments