From 11e6a3c4a9a8bb42d864c890d70b2f31ec478be4 Mon Sep 17 00:00:00 2001 From: Tanya Fomina Date: Sat, 4 May 2024 17:55:22 +0300 Subject: [PATCH] Add order test --- test/cypress/tests/ui/BlockTunes.cy.ts | 94 ++++++++++++++++++++++++++ test/cypress/tests/utils/popover.cy.ts | 2 - 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/test/cypress/tests/ui/BlockTunes.cy.ts b/test/cypress/tests/ui/BlockTunes.cy.ts index 0cf9207a..3ee359b5 100644 --- a/test/cypress/tests/ui/BlockTunes.cy.ts +++ b/test/cypress/tests/ui/BlockTunes.cy.ts @@ -1,6 +1,7 @@ import { selectionChangeDebounceTimeout } from '../../../../src/components/constants'; import Header from '@editorjs/header'; import { ToolboxConfig } from '../../../../types'; +import { TunesMenuConfig } from '../../../../types/tools'; describe('BlockTunes', function () { @@ -344,4 +345,97 @@ describe('BlockTunes', function () { }); }); }); + + describe('Tunes order', () => { + it('should display block specific tunes before common tunes', () => { + /** + * Tool with several toolbox entries configured + */ + class TestTool { + /** + * TestTool contains several toolbox options + */ + public static get toolbox(): ToolboxConfig { + return [ + { + title: 'Title 1', + icon: 'Icon1', + data: { + level: 1, + }, + }, + ]; + } + + /** + * Tool can render itself + */ + public render(): HTMLDivElement { + const div = document.createElement('div'); + + div.innerText = 'Some text'; + + return div; + } + + /** + * + */ + public renderSettings(): TunesMenuConfig { + return { + icon: 'Icon', + title: 'Tune', + }; + } + + /** + * Tool can save it's data + */ + public save(): { text: string; level: number } { + return { + text: 'Some text', + level: 1, + }; + } + } + + /** Editor instance with TestTool installed and one block of TestTool type */ + cy.createEditor({ + tools: { + testTool: TestTool, + }, + data: { + blocks: [ + { + type: 'testTool', + data: { + text: 'Some text', + level: 1, + }, + }, + ], + }, + }); + + /** Open block tunes menu */ + cy.get('[data-cy=editorjs]') + .get('.ce-block') + .click(); + + cy.get('[data-cy=editorjs]') + .get('.ce-toolbar__settings-btn') + .click(); + + /** Check there are more than 1 tune */ + cy.get('[data-cy=editorjs]') + .get('.ce-popover-item') + .should('have.length.above', 1); + + /** Check the first tune is tool specific tune */ + cy.get('[data-cy=editorjs]') + .get('.ce-popover-item:first-child') + .contains('Tune') + .should('exist'); + }); + }); }); diff --git a/test/cypress/tests/utils/popover.cy.ts b/test/cypress/tests/utils/popover.cy.ts index 8998da9b..1fe4f388 100644 --- a/test/cypress/tests/utils/popover.cy.ts +++ b/test/cypress/tests/utils/popover.cy.ts @@ -581,7 +581,6 @@ describe('Popover', () => { /** Tool data displayed in block tunes popover */ public render(): TunesMenuConfig { return { - // @ts-expect-error type is not specified on purpose to test the back compatibility onActivate: (): void => {}, icon: 'Icon', title: 'Tune', @@ -591,7 +590,6 @@ describe('Popover', () => { } } - /** Create editor instance */ cy.createEditor({ tools: {