Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Utils useful for Editor.js tools development",
"repository": "https://github.com/editor-js/utils/tree/main/packages/helpers",
"link": "https://github.com/editor-js/utils/tree/main/packages/helpers",
"version": "1.2.2",
"version": "1.2.3",
"main": "dist/index.js",
"type": "module",
"license": "MIT",
Expand All @@ -14,6 +14,6 @@
"access": "public"
},
"dependencies": {
"codex-tooltip": "^1.0.6"
"codex-tooltip": "^1.1.0"
}
}
70 changes: 70 additions & 0 deletions packages/helpers/src/tooltip/tooltip.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { afterEach, describe, expect, test, vi } from 'vitest';

/**
* Stand-in for codex-tooltip: records construction, since constructing it is what registers
* its window-level scroll listener
*/
const { Tooltip } = vi.hoisted(() => ({
Tooltip: vi.fn(function (this: Record<string, unknown>) {
this.show = vi.fn();
this.hide = vi.fn();
this.onHover = vi.fn();
this.destroy = vi.fn();
}),
}));

vi.mock('codex-tooltip', () => ({ default: Tooltip }));

/**
* The parts of a stand-in instance the tests inspect
*/
interface TooltipInstance {
/**
* Recorded hide() calls
*/
hide: ReturnType<typeof vi.fn>;
}

const tooltip = await import('./tooltip');

describe('tooltip', () => {
afterEach(() => {
tooltip.destroy();
Tooltip.mockClear();
});

test('hide() does not create the tooltip when none has been shown', () => {
tooltip.hide();
tooltip.hide(true);

expect(Tooltip).not.toHaveBeenCalled();
});

test('hide() hides an existing tooltip', () => {
const element = {} as HTMLElement;

tooltip.show(element, 'Hint');
tooltip.hide(true);

const instance = Tooltip.mock.instances[0] as unknown as TooltipInstance;

expect(Tooltip).toHaveBeenCalledTimes(1);
expect(instance.hide).toHaveBeenCalledWith(true);
});

test('show() creates the tooltip on first use', () => {
tooltip.show(({} as HTMLElement), 'Hint');

expect(Tooltip).toHaveBeenCalledTimes(1);
});

test('hide() after destroy() does not create a new tooltip', () => {
tooltip.show(({} as HTMLElement), 'Hint');
tooltip.destroy();
Tooltip.mockClear();

tooltip.hide();

expect(Tooltip).not.toHaveBeenCalled();
});
});
6 changes: 4 additions & 2 deletions packages/helpers/src/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ export function show(element: HTMLElement, content: TooltipContent, options?: To

/**
* Hides tooltip
*
* Does nothing when no tooltip has been created: there is nothing to hide, and creating one here
* would register its window-level listeners on teardown paths (e.g. destroying a popover item)
* where nothing was ever shown
* @param skipHidingDelay — pass true to immediately hide the tooltip
*/
export function hide(skipHidingDelay = false): void {
prepare();

lib?.hide(skipHidingDelay);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@editorjs/ui-kit",
"description": "UI Components for Editor.js",
"packageManager": "yarn@4.4.0",
"version": "2.0.0",
"version": "2.0.1",
"type": "module",
"main": "dist/index.js",
"types": "dist/src/index.d.ts",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@editorjs/helpers@workspace:packages/helpers"
dependencies:
codex-tooltip: "npm:^1.0.6"
codex-tooltip: "npm:^1.1.0"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -2643,10 +2643,10 @@ __metadata:
languageName: node
linkType: hard

"codex-tooltip@npm:^1.0.6":
version: 1.0.6
resolution: "codex-tooltip@npm:1.0.6"
checksum: 10c0/ec7488795aafbb004382899b51170190fc13ec2723004355a44e0bc50402325585108b9ef9825a7e6a6dff30e4e9edab8c93a3fe95cb2583e15f89630528676f
"codex-tooltip@npm:^1.1.0":
version: 1.1.0
resolution: "codex-tooltip@npm:1.1.0"
checksum: 10c0/e9f7904f22a604b39d51d17cb92ea35eaa3e8b3902d1e4b4fb9dc30a39591b1d013bbc4c01a965700569031cbcb78325d82ee831a9ec5060ddfbdb5771772ab2
languageName: node
linkType: hard

Expand Down
Loading