Skip to content

Commit ae9c0a6

Browse files
Goamandmo-odoo
authored andcommitted
[FIX] adapt setTag commands tests
After the commits that changed the toolbar (15f27e8), the tests for setting tags were not adapted and broke because the toolbar no longer rely on the id of the element to specify which command to run.
1 parent 2d94352 commit ae9c0a6

File tree

2 files changed

+28
-42
lines changed

2 files changed

+28
-42
lines changed

src/tests/editor.test.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { OdooEditor } from '../editor.js';
22
import { getTraversedNodes } from '../utils/utils.js';
33
import {
4-
applyElementStyle,
54
BasicEditor,
65
deleteBackward,
76
deleteForward,
@@ -2589,35 +2588,35 @@ describe('Editor', () => {
25892588
it('should turn a heading 1 into a paragraph', async () => {
25902589
await testEditor(BasicEditor, {
25912590
contentBefore: '<h1>ab[]cd</h1>',
2592-
stepFunction: editor => applyElementStyle(editor, 'paragraph'),
2591+
stepFunction: editor => editor.execCommand('setTag', 'p'),
25932592
contentAfter: '<p>ab[]cd</p>',
25942593
});
25952594
});
25962595
it('should turn a heading 1 into a paragraph (character selected)', async () => {
25972596
await testEditor(BasicEditor, {
25982597
contentBefore: '<h1>a[b]c</h1>',
2599-
stepFunction: editor => applyElementStyle(editor, 'paragraph'),
2598+
stepFunction: editor => editor.execCommand('setTag', 'p'),
26002599
contentAfter: '<p>a[b]c</p>',
26012600
});
26022601
});
26032602
it('should turn a heading 1, a paragraph and a heading 2 into three paragraphs', async () => {
26042603
await testEditor(BasicEditor, {
26052604
contentBefore: '<h1>a[b</h1><p>cd</p><h2>e]f</h2>',
2606-
stepFunction: editor => applyElementStyle(editor, 'paragraph'),
2605+
stepFunction: editor => editor.execCommand('setTag', 'p'),
26072606
contentAfter: '<p>a[b</p><p>cd</p><p>e]f</p>',
26082607
});
26092608
});
26102609
it.skip('should turn a heading 1 into a paragraph after a triple click', async () => {
26112610
await testEditor(BasicEditor, {
26122611
contentBefore: '<h1>[ab</h1><h2>]cd</h2>',
2613-
stepFunction: editor => applyElementStyle(editor, 'paragraph'),
2612+
stepFunction: editor => editor.execCommand('setTag', 'p'),
26142613
contentAfter: '<p>[ab</p><h2>]cd</h2>',
26152614
});
26162615
});
26172616
it('should not turn a div into a paragraph', async () => {
26182617
await testEditor(BasicEditor, {
26192618
contentBefore: '<div>[ab]</div>',
2620-
stepFunction: editor => applyElementStyle(editor, 'paragraph'),
2619+
stepFunction: editor => editor.execCommand('setTag', 'p'),
26212620
contentAfter: '<div><p>[ab]</p></div>',
26222621
});
26232622
});
@@ -2626,35 +2625,35 @@ describe('Editor', () => {
26262625
it('should turn a paragraph into a heading 1', async () => {
26272626
await testEditor(BasicEditor, {
26282627
contentBefore: '<p>ab[]cd</p>',
2629-
stepFunction: editor => applyElementStyle(editor, 'heading1'),
2628+
stepFunction: editor => editor.execCommand('setTag', 'h1'),
26302629
contentAfter: '<h1>ab[]cd</h1>',
26312630
});
26322631
});
26332632
it('should turn a paragraph into a heading 1 (character selected)', async () => {
26342633
await testEditor(BasicEditor, {
26352634
contentBefore: '<p>a[b]c</p>',
2636-
stepFunction: editor => applyElementStyle(editor, 'heading1'),
2635+
stepFunction: editor => editor.execCommand('setTag', 'h1'),
26372636
contentAfter: '<h1>a[b]c</h1>',
26382637
});
26392638
});
26402639
it('should turn a paragraph, a heading 1 and a heading 2 into three headings 1', async () => {
26412640
await testEditor(BasicEditor, {
26422641
contentBefore: '<p>a[b</p><h1>cd</h1><h2>e]f</h2>',
2643-
stepFunction: editor => applyElementStyle(editor, 'heading1'),
2642+
stepFunction: editor => editor.execCommand('setTag', 'h1'),
26442643
contentAfter: '<h1>a[b</h1><h1>cd</h1><h1>e]f</h1>',
26452644
});
26462645
});
26472646
it.skip('should turn a paragraph into a heading 1 after a triple click', async () => {
26482647
await testEditor(BasicEditor, {
26492648
contentBefore: '<p>[ab</p><h2>]cd</h2>',
2650-
stepFunction: editor => applyElementStyle(editor, 'heading1'),
2649+
stepFunction: editor => editor.execCommand('setTag', 'h1'),
26512650
contentAfter: '<h1>[ab</h1><h2>]cd</h2>',
26522651
});
26532652
});
26542653
it('should not turn a div into a heading 1', async () => {
26552654
await testEditor(BasicEditor, {
26562655
contentBefore: '<div>[ab]</div>',
2657-
stepFunction: editor => applyElementStyle(editor, 'heading1'),
2656+
stepFunction: editor => editor.execCommand('setTag', 'h1'),
26582657
contentAfter: '<div><h1>[ab]</h1></div>',
26592658
});
26602659
});
@@ -2663,35 +2662,35 @@ describe('Editor', () => {
26632662
it('should turn a heading 1 into a heading 2', async () => {
26642663
await testEditor(BasicEditor, {
26652664
contentBefore: '<h1>ab[]cd</h1>',
2666-
stepFunction: editor => applyElementStyle(editor, 'heading2'),
2665+
stepFunction: editor => editor.execCommand('setTag', 'h2'),
26672666
contentAfter: '<h2>ab[]cd</h2>',
26682667
});
26692668
});
26702669
it('should turn a heading 1 into a heading 2 (character selected)', async () => {
26712670
await testEditor(BasicEditor, {
26722671
contentBefore: '<h1>a[b]c</h1>',
2673-
stepFunction: editor => applyElementStyle(editor, 'heading2'),
2672+
stepFunction: editor => editor.execCommand('setTag', 'h2'),
26742673
contentAfter: '<h2>a[b]c</h2>',
26752674
});
26762675
});
26772676
it('should turn a heading 1, a heading 2 and a paragraph into three headings 2', async () => {
26782677
await testEditor(BasicEditor, {
26792678
contentBefore: '<h1>a[b</h1><h2>cd</h2><p>e]f</p>',
2680-
stepFunction: editor => applyElementStyle(editor, 'heading2'),
2679+
stepFunction: editor => editor.execCommand('setTag', 'h2'),
26812680
contentAfter: '<h2>a[b</h2><h2>cd</h2><h2>e]f</h2>',
26822681
});
26832682
});
26842683
it.skip('should turn a paragraph into a heading 2 after a triple click', async () => {
26852684
await testEditor(BasicEditor, {
26862685
contentBefore: '<p>[ab</p><h1>]cd</h1>',
2687-
stepFunction: editor => applyElementStyle(editor, 'heading2'),
2686+
stepFunction: editor => editor.execCommand('setTag', 'h2'),
26882687
contentAfter: '<h2>[ab</h2><h1>]cd</h1>',
26892688
});
26902689
});
26912690
it('should not turn a div into a heading 2', async () => {
26922691
await testEditor(BasicEditor, {
26932692
contentBefore: '<div>[ab]</div>',
2694-
stepFunction: editor => applyElementStyle(editor, 'heading2'),
2693+
stepFunction: editor => editor.execCommand('setTag', 'h2'),
26952694
contentAfter: '<div><h2>[ab]</h2></div>',
26962695
});
26972696
});
@@ -2700,35 +2699,35 @@ describe('Editor', () => {
27002699
it('should turn a heading 1 into a heading 3', async () => {
27012700
await testEditor(BasicEditor, {
27022701
contentBefore: '<h1>ab[]cd</h1>',
2703-
stepFunction: editor => applyElementStyle(editor, 'heading3'),
2702+
stepFunction: editor => editor.execCommand('setTag', 'h3'),
27042703
contentAfter: '<h3>ab[]cd</h3>',
27052704
});
27062705
});
27072706
it('should turn a heading 1 into a heading 3 (character selected)', async () => {
27082707
await testEditor(BasicEditor, {
27092708
contentBefore: '<h1>a[b]c</h1>',
2710-
stepFunction: editor => applyElementStyle(editor, 'heading3'),
2709+
stepFunction: editor => editor.execCommand('setTag', 'h3'),
27112710
contentAfter: '<h3>a[b]c</h3>',
27122711
});
27132712
});
27142713
it('should turn a heading 1, a paragraph and a heading 2 into three headings 3', async () => {
27152714
await testEditor(BasicEditor, {
27162715
contentBefore: '<h1>a[b</h1><p>cd</p><h2>e]f</h2>',
2717-
stepFunction: editor => applyElementStyle(editor, 'heading3'),
2716+
stepFunction: editor => editor.execCommand('setTag', 'h3'),
27182717
contentAfter: '<h3>a[b</h3><h3>cd</h3><h3>e]f</h3>',
27192718
});
27202719
});
27212720
it.skip('should turn a paragraph into a heading 3 after a triple click', async () => {
27222721
await testEditor(BasicEditor, {
27232722
contentBefore: '<p>[ab</p><h1>]cd</h1>',
2724-
stepFunction: editor => applyElementStyle(editor, 'heading3'),
2723+
stepFunction: editor => editor.execCommand('setTag', 'h3'),
27252724
contentAfter: '<h3>[ab</h3><h1>]cd</h1>',
27262725
});
27272726
});
27282727
it('should not turn a div into a heading 3', async () => {
27292728
await testEditor(BasicEditor, {
27302729
contentBefore: '<div>[ab]</div>',
2731-
stepFunction: editor => applyElementStyle(editor, 'heading3'),
2730+
stepFunction: editor => editor.execCommand('setTag', 'h3'),
27322731
contentAfter: '<div><h3>[ab]</h3></div>',
27332732
});
27342733
});
@@ -2737,21 +2736,21 @@ describe('Editor', () => {
27372736
it('should turn a heading 1 into a pre', async () => {
27382737
await testEditor(BasicEditor, {
27392738
contentBefore: '<h1>ab[]cd</h1>',
2740-
stepFunction: editor => applyElementStyle(editor, 'pre'),
2739+
stepFunction: editor => editor.execCommand('setTag', 'pre'),
27412740
contentAfter: '<pre>ab[]cd</pre>',
27422741
});
27432742
});
27442743
it('should turn a heading 1 into a pre (character selected)', async () => {
27452744
await testEditor(BasicEditor, {
27462745
contentBefore: '<h1>a[b]c</h1>',
2747-
stepFunction: editor => applyElementStyle(editor, 'pre'),
2746+
stepFunction: editor => editor.execCommand('setTag', 'pre'),
27482747
contentAfter: '<pre>a[b]c</pre>',
27492748
});
27502749
});
27512750
it('should turn a heading 1 a pre and a paragraph into three pres', async () => {
27522751
await testEditor(BasicEditor, {
27532752
contentBefore: '<h1>a[b</h1><pre>cd</pre><p>e]f</p>',
2754-
stepFunction: editor => applyElementStyle(editor, 'pre'),
2753+
stepFunction: editor => editor.execCommand('setTag', 'pre'),
27552754
contentAfter: '<pre>a[b</pre><pre>cd</pre><pre>e]f</pre>',
27562755
});
27572756
});
@@ -2760,36 +2759,36 @@ describe('Editor', () => {
27602759
it('should turn a blockquote into a paragraph', async () => {
27612760
await testEditor(BasicEditor, {
27622761
contentBefore: '<h1>ab[]cd</h1>',
2763-
stepFunction: editor => applyElementStyle(editor, 'blockquote'),
2762+
stepFunction: editor => editor.execCommand('setTag', 'blockquote'),
27642763
contentAfter: '<blockquote>ab[]cd</blockquote>',
27652764
});
27662765
});
27672766
it('should turn a heading 1 into a blockquote (character selected)', async () => {
27682767
await testEditor(BasicEditor, {
27692768
contentBefore: '<h1>a[b]c</h1>',
2770-
stepFunction: editor => applyElementStyle(editor, 'blockquote'),
2769+
stepFunction: editor => editor.execCommand('setTag', 'blockquote'),
27712770
contentAfter: '<blockquote>a[b]c</blockquote>',
27722771
});
27732772
});
27742773
it('should turn a heading 1, a paragraph and a heading 2 into three blockquote', async () => {
27752774
await testEditor(BasicEditor, {
27762775
contentBefore: '<h1>a[b</h1><p>cd</p><h2>e]f</h2>',
2777-
stepFunction: editor => applyElementStyle(editor, 'blockquote'),
2776+
stepFunction: editor => editor.execCommand('setTag', 'blockquote'),
27782777
contentAfter:
27792778
'<blockquote>a[b</blockquote><blockquote>cd</blockquote><blockquote>e]f</blockquote>',
27802779
});
27812780
});
27822781
it.skip('should turn a heading 1 into a blockquote after a triple click', async () => {
27832782
await testEditor(BasicEditor, {
27842783
contentBefore: '<h1>[ab</h1><h2>]cd</h2>',
2785-
stepFunction: editor => applyElementStyle(editor, 'blockquote'),
2784+
stepFunction: editor => editor.execCommand('setTag', 'blockquote'),
27862785
contentAfter: '<blockquote>[ab</blockquote><h2>]cd</h2>',
27872786
});
27882787
});
27892788
it('should not turn a div into a blockquote', async () => {
27902789
await testEditor(BasicEditor, {
27912790
contentBefore: '<div>[ab]</div>',
2792-
stepFunction: editor => applyElementStyle(editor, 'blockquote'),
2791+
stepFunction: editor => editor.execCommand('setTag', 'blockquote'),
27932792
contentAfter: '<div><blockquote>[ab]</blockquote></div>',
27942793
});
27952794
});

src/tests/utils.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -383,17 +383,4 @@ export function redo(editor) {
383383
editor.historyRedo();
384384
}
385385

386-
export function simulateToolbarClick(editor, buttonId) {
387-
const button = document.createElement('div');
388-
button.classList.add('btn');
389-
button.id = buttonId;
390-
const ev = new MouseEvent('click');
391-
Object.defineProperty(ev, 'target', { value: button });
392-
editor._onToolbarClick(ev);
393-
}
394-
395-
export function applyElementStyle(editor, style) {
396-
simulateToolbarClick(editor, style);
397-
}
398-
399386
export class BasicEditor extends OdooEditor {}

0 commit comments

Comments
 (0)