Skip to content

Build your personal knowledge base with Trilium Notes

test(images): cover the guards of ImageEditingSource

Elian Doran33d80c8af434
diff --git a/packages/ckeditor5/src/plugins/image_editing_source.spec.ts b/packages/ckeditor5/src/plugins/image_editing_source.spec.ts
index 6d544de1cf..0abeea61de 100644
--- a/packages/ckeditor5/src/plugins/image_editing_source.spec.ts
+++ b/packages/ckeditor5/src/plugins/image_editing_source.spec.ts
@@ -74,4 +74,24 @@ describe("ImageEditingSource", () => {
plugin.refresh();
expect(resolve.mock.calls).toEqual([ [ INLINE_SRC ] ]);
});
+
+ it("leaves an image without a src alone", async () => {
+ const resolve = vi.fn((src: string) => `${src}?v=1`);
+ const editor = await createEditor(resolve);
+ const root = editor.model.document.getRoot();
+ const image = root?.getChild(0);
+ expect(image?.is("element", "imageBlock")).toBe(true);
+
+ resolve.mockClear();
+ editor.model.change((writer) => {
+ if (image?.is("element")) {
+ writer.removeAttribute("src", image);
+ }
+ });
+ editor.plugins.get(ImageEditingSource).refresh();
+
+ // Only the inline image, which keeps its src, is resolved again.
+ expect(resolve.mock.calls).toEqual([ [ INLINE_SRC ] ]);
+ expect(renderedSources(editor)).toEqual([ "", `${INLINE_SRC}?v=1` ]);
+ });
});
diff --git a/packages/ckeditor5/src/plugins/image_editing_source.ts b/packages/ckeditor5/src/plugins/image_editing_source.ts
index 1b3a58ff32..93ae8a0f96 100644
--- a/packages/ckeditor5/src/plugins/image_editing_source.ts
+++ b/packages/ckeditor5/src/plugins/image_editing_source.ts
@@ -106,6 +106,8 @@ export default class ImageEditingSource extends Plugin {
/** The `<img>` of an image block's `<figure>` or of an inline image's wrapper. */
private _findViewImg(image: ModelElement) {
const viewElement = this.editor.editing.mapper.toViewElement(image);
+ /* v8 ignore next -- `ImageEditing` maps every attached image to a view element before
+ its `src` is converted, and `refresh()` skips the images that left the document. */
if (!viewElement) {
return undefined;
}