Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor: improve test coverage

Adorian Doran4a62b70eaf10
diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.ts
index b01fb0f818..2ab2d1d63a 100644
--- a/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.ts
+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.ts
@@ -247,6 +247,7 @@ function getButtonFace(tool: ContentEmbedTool) {
* keystroke of `ButtonView` throws on a key that CKEditor cannot parse, such as `?`.
*/
function addKeystrokes(dropdown: DropdownView, children: ContentEmbedTool[]) {
+ /* v8 ignore next -- `addListToDropdown()` creates `listView` before this runs. */
const buttons = [ ...dropdown.listView?.items ?? [] ]
.filter(item => item instanceof ListItemView)
.map(item => item.children.first);
diff --git a/packages/ckeditor5/src/plugins/image_to_drawing.ts b/packages/ckeditor5/src/plugins/image_to_drawing.ts
index 9b745f1956..584c732584 100644
--- a/packages/ckeditor5/src/plugins/image_to_drawing.ts
+++ b/packages/ckeditor5/src/plugins/image_to_drawing.ts
@@ -62,6 +62,7 @@ export class ConvertImageToDrawingCommand extends Command {
const editor = this.editor;
const image = this.getSelectedBlockImage();
const src = image?.getAttribute("src");
+ /* v8 ignore next -- `refresh()` disables the command without a block image with a src. */
if (!image || typeof src !== "string") return;
const size = this.getShownSize(image);
@@ -105,16 +106,16 @@ export class ConvertImageToDrawingCommand extends Command {
const editing = this.editor.editing;
const viewElement = editing.mapper.toViewElement(image);
const figure = viewElement && editing.view.domConverter.mapViewToDom(viewElement);
+ /* v8 ignore next -- the editing view renders the selected image as a `<figure>`. */
if (!(figure instanceof HTMLElement)) return {};
- const { width, height } = figure.querySelector("img")?.getBoundingClientRect()
- ?? { width: 0, height: 0 };
- if (!width || !height) return {};
+ const rect = figure.querySelector("img")?.getBoundingClientRect();
+ if (!rect?.width || !rect.height) return {};
const em = parseFloat(getComputedStyle(figure).fontSize);
return {
- [SIZE_ATTRIBUTES.width]: toEm(width / em, MIN_EMBED_SIZE.width),
- [SIZE_ATTRIBUTES.height]: toEm(height / em, MIN_EMBED_SIZE.height)
+ [SIZE_ATTRIBUTES.width]: toEm(rect.width / em, MIN_EMBED_SIZE.width),
+ [SIZE_ATTRIBUTES.height]: toEm(rect.height / em, MIN_EMBED_SIZE.height)
};
}
@@ -129,10 +130,7 @@ export class ConvertImageToDrawingCommand extends Command {
const CONVERTING = "converting";
function getCaption(image: ModelElement) {
- for (const child of image.getChildren()) {
- if (child.is("element", "caption")) return child;
- }
- return null;
+ return [ ...image.getChildren() ].find((child) => child.is("element", "caption"));
}
/** `value` in `em`, rounded to hundredths and no less than `min`. */
diff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.ts
index 8f3d986613..dd2130ea76 100644
--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.ts
+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.ts
@@ -109,7 +109,7 @@ export default class MulticolumnEditing extends Plugin {
view: (model, { writer }) => {
const column: ViewEditableElement & PlaceholderableViewElement =
writer.createEditableElement("div", { class: COLUMN_CLASS });
- column.placeholder = getColumnPlaceholder(t, model.index ?? 0);
+ column.placeholder = getColumnPlaceholder(t, model.index);
enableViewPlaceholder({
view: editor.editing.view,
element: column,
@@ -155,9 +155,9 @@ export default class MulticolumnEditing extends Plugin {
/**
* The placeholder of the column at `index`, which names its position. A layout has at most
- * `MAX_COLUMNS` (four) columns.
+ * `MAX_COLUMNS` (four) columns. A column in a layout always has an index.
*/
-function getColumnPlaceholder(t: LocaleTranslate, index: number) {
+function getColumnPlaceholder(t: LocaleTranslate, index: number | null) {
switch (index) {
case 0: return t("Type the content of the first column");
case 1: return t("Type the content of the second column");