|
| 1 | +/** |
| 2 | + * There will be described test cases of 'api.toolbar.*' API |
| 3 | + */ |
| 4 | +import EditorJS from '../../../../types'; |
| 5 | + |
| 6 | +describe('api.toolbar', () => { |
| 7 | + /** |
| 8 | + * api.toolbar.openToolbox(openingState?: boolean) |
| 9 | + */ |
| 10 | + const firstBlock = { |
| 11 | + id: 'bwnFX5LoX7', |
| 12 | + type: 'paragraph', |
| 13 | + data: { |
| 14 | + text: 'The first block content mock.', |
| 15 | + }, |
| 16 | + }; |
| 17 | + const editorDataMock = { |
| 18 | + blocks: [ |
| 19 | + firstBlock, |
| 20 | + ], |
| 21 | + }; |
| 22 | + |
| 23 | + beforeEach(function () { |
| 24 | + cy.createEditor({ |
| 25 | + data: editorDataMock, |
| 26 | + readOnly: false, |
| 27 | + }).as('editorInstance'); |
| 28 | + }); |
| 29 | + |
| 30 | + afterEach(function () { |
| 31 | + if (this.editorInstance) { |
| 32 | + this.editorInstance.destroy(); |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + describe('*.toggleToolbox()', () => { |
| 37 | + const isToolboxVisible = (): void => { |
| 38 | + cy.get('[data-cy=editorjs]').find('div.ce-toolbox') |
| 39 | + .then((toolbox) => { |
| 40 | + if (toolbox.is(':visible')) { |
| 41 | + assert.isOk(true, 'Toolbox visible'); |
| 42 | + } else { |
| 43 | + assert.isNotOk(false, 'Toolbox should be visible'); |
| 44 | + } |
| 45 | + }); |
| 46 | + }; |
| 47 | + |
| 48 | + const isToolboxNotVisible = (): void => { |
| 49 | + cy.get('[data-cy=editorjs]').find('div.ce-toolbox') |
| 50 | + .then((toolbox) => { |
| 51 | + if (!toolbox.is(':visible')) { |
| 52 | + assert.isOk(true, 'Toolbox not visible'); |
| 53 | + } else { |
| 54 | + assert.isNotOk(false, 'Toolbox should not be visible'); |
| 55 | + } |
| 56 | + }); |
| 57 | + }; |
| 58 | + |
| 59 | + it('should open the toolbox', function () { |
| 60 | + cy.get<EditorJS>('@editorInstance').then(async function (editor) { |
| 61 | + editor.toolbar.toggleToolbox(true); |
| 62 | + isToolboxVisible(); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should close the toolbox', function () { |
| 67 | + cy.get<EditorJS>('@editorInstance').then(async function (editor) { |
| 68 | + editor.toolbar.toggleToolbox(true); |
| 69 | + |
| 70 | + isToolboxVisible(); |
| 71 | + |
| 72 | + editor.toolbar.toggleToolbox(false); |
| 73 | + isToolboxNotVisible(); |
| 74 | + }); |
| 75 | + }); |
| 76 | + it('should toggle the toolbox', function () { |
| 77 | + cy.get<EditorJS>('@editorInstance').then(async function (editor) { |
| 78 | + editor.toolbar.toggleToolbox(); |
| 79 | + isToolboxVisible(); |
| 80 | + |
| 81 | + editor.toolbar.toggleToolbox(); |
| 82 | + isToolboxNotVisible(); |
| 83 | + }); |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
0 commit comments