Skip to content

Commit c5cedc9

Browse files
committed
#24 - Test for new Commands module
1 parent ab97d10 commit c5cedc9

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

test/unit/modules/Commands.spec.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// jshint strict: false
2+
3+
import Mediator from '../../../src/scripts/core/Mediator';
4+
import Commands from '../../../src/scripts/modules/Commands';
5+
import Config from '../../../src/scripts/modules/Config';
6+
import selectionHelper from '../helpers/selection';
7+
8+
describe('modules/Commands', function () {
9+
let mediator, $editableEl, editableEl;
10+
11+
beforeEach((done) => {
12+
loadFixtures('index.html');
13+
14+
mediator = new Mediator();
15+
new Commands({ mediator });
16+
new Config({ mediator });
17+
18+
$editableEl = jQuery('.content-editable');
19+
editableEl = $editableEl[0];
20+
editableEl.contentEditable = true;
21+
22+
setTimeout(done, 250);
23+
});
24+
25+
it('should execute a given command', () => {
26+
const contentBlock = document.createElement('p');
27+
const contentBlockText = 'text inside an exisiting block';
28+
29+
contentBlock.innerHTML = contentBlockText;
30+
editableEl.innerHTML = '';
31+
editableEl.appendChild(contentBlock);
32+
33+
selectionHelper.selectAll(contentBlock.childNodes[0]);
34+
mediator.exec('commands:exec', {
35+
command: 'formatBlock',
36+
value: 'H1'
37+
});
38+
39+
expect(editableEl.innerHTML).toBe(`<h1>${contentBlockText}</h1>`);
40+
});
41+
42+
it('should execute a default command', () => {
43+
const contentBlock = document.createElement('h1');
44+
const contentBlockText = 'text inside an exisiting block';
45+
46+
contentBlock.innerHTML = contentBlockText;
47+
editableEl.innerHTML = '';
48+
editableEl.appendChild(contentBlock);
49+
50+
selectionHelper.selectAll(contentBlock.childNodes[0]);
51+
mediator.exec('commands:format:default');
52+
53+
expect(editableEl.innerHTML).toBe(`<p>${contentBlockText}</p>`);
54+
});
55+
56+
it('should execute a formatBlock command', () => {
57+
const contentBlock = document.createElement('p');
58+
const contentBlockText = 'text inside an exisiting block';
59+
60+
contentBlock.innerHTML = contentBlockText;
61+
editableEl.innerHTML = '';
62+
editableEl.appendChild(contentBlock);
63+
64+
selectionHelper.selectAll(contentBlock.childNodes[0]);
65+
mediator.exec('commands:format:block', {
66+
style: 'BLOCKQUOTE'
67+
});
68+
69+
expect(editableEl.innerHTML).toBe(`<blockquote>${contentBlockText}</blockquote>`);
70+
});
71+
});

test/unit/modules/Config.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// jshint strict: false
2+
13
import Mediator from '../../../src/scripts/core/Mediator';
24
import Config from '../../../src/scripts/modules/Config';
35

0 commit comments

Comments
 (0)