From 7cc04c015c37bdc3176beaf40d08c72c6bd09881 Mon Sep 17 00:00:00 2001 From: Tanya Fomina Date: Thu, 28 Apr 2022 23:32:06 +0800 Subject: [PATCH] Add testcase for missing toolbox title --- test/cypress/tests/i18n.spec.ts | 87 ++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 22 deletions(-) diff --git a/test/cypress/tests/i18n.spec.ts b/test/cypress/tests/i18n.spec.ts index 82075c3a..2f31d48c 100644 --- a/test/cypress/tests/i18n.spec.ts +++ b/test/cypress/tests/i18n.spec.ts @@ -1,17 +1,31 @@ import Header from '@editorjs/header'; +import { ToolboxConfig } from '../../../types'; + +/** + * Tool class allowing to test case when capitalized tool name is used as translation key if toolbox title is missing + */ +class TestTool { + /** + * Returns toolbox config without title + */ + public static get toolbox(): ToolboxConfig { + return { + title: '', + icon: '', + }; + } +} describe('Editor i18n', () => { - /** - * Stores translations for tool names - */ - const toolNamesDictionary = { - Heading: 'Заголовок', - }; + context('Toolbox', () => { + it('should translate tool title in a toolbox', () => { + if (this && this.editorInstance) { + this.editorInstance.destroy(); + } + const toolNamesDictionary = { + Heading: 'Заголовок', + }; - beforeEach(() => { - if (this && this.editorInstance) { - this.editorInstance.destroy(); - } else { cy.createEditor({ tools: { header: Header, @@ -22,20 +36,49 @@ describe('Editor i18n', () => { }, }, }).as('editorInstance'); - } - }); - it('should translate tool title in a toolbox', () => { - cy.get('[data-cy=editorjs]') - .get('div.ce-block') - .click(); + cy.get('[data-cy=editorjs]') + .get('div.ce-block') + .click(); - cy.get('[data-cy=editorjs]') - .get('div.ce-toolbar__plus') - .click(); + cy.get('[data-cy=editorjs]') + .get('div.ce-toolbar__plus') + .click(); - cy.get('[data-cy=editorjs]') - .get('div.ce-popover__item[data-item-name=header]') - .should('contain.text', toolNamesDictionary.Heading); + cy.get('[data-cy=editorjs]') + .get('div.ce-popover__item[data-item-name=header]') + .should('contain.text', toolNamesDictionary.Heading); + }); + + it('should use capitalized tool name as translation key if toolbox title is missing', () => { + if (this && this.editorInstance) { + this.editorInstance.destroy(); + } + const toolNamesDictionary = { + TestTool: 'ТестТул', + }; + + cy.createEditor({ + tools: { + testTool: TestTool, + }, + i18n: { + messages: { + toolNames: toolNamesDictionary, + }, + }, + }).as('editorInstance'); + cy.get('[data-cy=editorjs]') + .get('div.ce-block') + .click(); + + cy.get('[data-cy=editorjs]') + .get('div.ce-toolbar__plus') + .click(); + + cy.get('[data-cy=editorjs]') + .get('div.ce-popover__item[data-item-name=testTool]') + .should('contain.text', toolNamesDictionary.TestTool); + }); }); }); \ No newline at end of file