|
1 | 1 | import type EditorJS from '../../../../types/index';
|
2 | 2 | import type { ConversionConfig, ToolboxConfig } from '../../../../types';
|
3 | 3 | import ToolMock from '../../fixtures/tools/ToolMock';
|
| 4 | +import {nanoid} from "nanoid"; |
4 | 5 |
|
5 | 6 | /**
|
6 | 7 | * There will be described test cases of 'blocks.*' API
|
@@ -102,6 +103,94 @@ describe('api.blocks', () => {
|
102 | 103 | });
|
103 | 104 | });
|
104 | 105 |
|
| 106 | + it('should update tune data when it is provided', () => { |
| 107 | + /** |
| 108 | + * Example Tune Class |
| 109 | + */ |
| 110 | + class ExampleTune { |
| 111 | + |
| 112 | + protected data: object; |
| 113 | + /** |
| 114 | + * |
| 115 | + * @param data |
| 116 | + */ |
| 117 | + constructor({ data}) { |
| 118 | + this.data = data; |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Tell editor.js that this Tool is a Block Tune |
| 123 | + * |
| 124 | + * @returns {boolean} |
| 125 | + */ |
| 126 | + public static get isTune(): boolean { |
| 127 | + return true; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Create Tunes controls wrapper that will be appended to the Block Tunes panel |
| 132 | + * |
| 133 | + * @returns {Element} |
| 134 | + */ |
| 135 | + public render(): Element { |
| 136 | + return document.createElement('div'); |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * CSS selectors used in Tune |
| 141 | + */ |
| 142 | + public static get CSS(): object { |
| 143 | + return {}; |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * Returns Tune state |
| 148 | + * |
| 149 | + * @returns {string} |
| 150 | + */ |
| 151 | + public save(): object | string { |
| 152 | + return this.data || ''; |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + |
| 157 | + cy.createEditor({ |
| 158 | + tools: { |
| 159 | + exampleTune: ExampleTune, |
| 160 | + }, |
| 161 | + tunes: [ 'exampleTune' ], |
| 162 | + data: { |
| 163 | + blocks: [ |
| 164 | + { |
| 165 | + id: nanoid(), |
| 166 | + type: 'paragraph', |
| 167 | + data: { |
| 168 | + text: 'First block', |
| 169 | + }, |
| 170 | + tunes: { |
| 171 | + exampleTune: 'citation', |
| 172 | + }, |
| 173 | + }, |
| 174 | + ], |
| 175 | + }, |
| 176 | + }).as('editorInstance'); |
| 177 | + |
| 178 | + // Update the tunes data of a block |
| 179 | + // Check if it is updated |
| 180 | + cy.get<EditorJS>('@editorInstance') |
| 181 | + .then(async (editor) => { |
| 182 | + await editor.blocks.update(editor.blocks.getBlockByIndex(0).id, null, { |
| 183 | + exampleTune: 'test', |
| 184 | + }); |
| 185 | + const data = await editor.save(); |
| 186 | + |
| 187 | + const actual = JSON.stringify(data.blocks[0].tunes); |
| 188 | + const expected = JSON.stringify({ exampleTune: 'test' }); |
| 189 | + |
| 190 | + expect(actual).to.eq(expected); |
| 191 | + }); |
| 192 | + }); |
| 193 | + |
105 | 194 | /**
|
106 | 195 | * When incorrect id passed, editor should not update any block
|
107 | 196 | */
|
|
0 commit comments