|
| 1 | +import { describePlugin } from '../../utils/src/testUtils'; |
| 2 | +import { BasicEditor } from '../../bundle-basic-editor/BasicEditor'; |
| 3 | +import JWEditor from '../../core/src/JWEditor'; |
| 4 | +import { Constructor } from '../../utils/src/utils'; |
| 5 | +import { Format } from '../../core/src/Format'; |
| 6 | +import { UnderlineFormat } from '../src/UnderlineFormat'; |
| 7 | +import { SpanFormat } from '../../plugin-span/src/SpanFormat'; |
| 8 | +import { Underline } from '../src/Underline'; |
| 9 | +import { Inline } from '../../plugin-inline/src/Inline'; |
| 10 | + |
| 11 | +const toggleFormat = async (editor: JWEditor, FormatClass: Constructor<Format>): Promise<void> => { |
| 12 | + await editor.execCommand<Inline>('toggleFormat', { |
| 13 | + FormatClass: FormatClass, |
| 14 | + }); |
| 15 | +}; |
| 16 | +describePlugin(Underline, testEditor => { |
| 17 | + describe('underline format', () => { |
| 18 | + it('should keep formats in order if not touched', async () => { |
| 19 | + await testEditor(BasicEditor, { |
| 20 | + contentBefore: '<span><u>g[]ga</u></span>', |
| 21 | + contentAfter: '<span><u>g[]ga</u></span>', |
| 22 | + }); |
| 23 | + }); |
| 24 | + it('should keep formats in order if not touched (2)', async () => { |
| 25 | + await testEditor(BasicEditor, { |
| 26 | + contentBefore: '<u><span>g[]ga</span></u>', |
| 27 | + contentAfter: '<u><span>g[]ga</span></u>', |
| 28 | + }); |
| 29 | + }); |
| 30 | + it('should put underline inside a span', async () => { |
| 31 | + await testEditor(BasicEditor, { |
| 32 | + contentBefore: 'a<span>b[cd]e</span>f', |
| 33 | + stepFunction: async (editor: JWEditor) => { |
| 34 | + await toggleFormat(editor, UnderlineFormat); |
| 35 | + }, |
| 36 | + contentAfter: 'a<span>b[<u>cd]</u>e</span>f', |
| 37 | + }); |
| 38 | + }); |
| 39 | + it('should put underline inside a span (2)', async () => { |
| 40 | + await testEditor(BasicEditor, { |
| 41 | + contentBefore: 'a[<span>bcde]</span>f', |
| 42 | + stepFunction: async (editor: JWEditor) => { |
| 43 | + await toggleFormat(editor, UnderlineFormat); |
| 44 | + }, |
| 45 | + contentAfter: 'a[<span><u>bcde]</u></span>f', |
| 46 | + }); |
| 47 | + }); |
| 48 | + it('should put underline inside a span (3)', async () => { |
| 49 | + await testEditor(BasicEditor, { |
| 50 | + contentBefore: '[a<span>bcd]e</span>f', |
| 51 | + stepFunction: async (editor: JWEditor) => { |
| 52 | + await toggleFormat(editor, UnderlineFormat); |
| 53 | + }, |
| 54 | + contentAfter: '<u>[a</u><span><u>bcd]</u>e</span>f', |
| 55 | + }); |
| 56 | + }); |
| 57 | + it('should put underline inside a span (4)', async () => { |
| 58 | + await testEditor(BasicEditor, { |
| 59 | + contentBefore: '[a<span>bc<span>xx</span>de</span>f]', |
| 60 | + stepFunction: async (editor: JWEditor) => { |
| 61 | + await toggleFormat(editor, UnderlineFormat); |
| 62 | + }, |
| 63 | + contentAfter: |
| 64 | + '<u>[a</u><span><u>bc</u><span><u>xx</u></span><u>de</u></span><u>f]</u>', |
| 65 | + }); |
| 66 | + }); |
| 67 | + it('should put underline inside a span (5)', async () => { |
| 68 | + await testEditor(BasicEditor, { |
| 69 | + contentBefore: '<u>ab[cd]ef</u>', |
| 70 | + stepFunction: async (editor: JWEditor) => { |
| 71 | + await toggleFormat(editor, SpanFormat); |
| 72 | + }, |
| 73 | + contentAfter: '<u>ab[</u><span><u>cd]</u></span><u>ef</u>', |
| 74 | + }); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments