|
| 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 | +}); |
0 commit comments