import Quill from '../../../core/quill'; import { addControls } from '../../../modules/toolbar'; describe('Toolbar', function() { describe('add controls', function() { it('single level', function() { addControls(this.container, ['bold', 'italic']); expect(this.container).toEqualHTML(` `); }); it('nested group', function() { addControls(this.container, [ ['bold', 'italic'], ['underline', 'strike'], ]); expect(this.container).toEqualHTML(` `); }); it('button value', function() { addControls(this.container, ['bold', { header: '2' }]); expect(this.container).toEqualHTML(` `); }); it('select', function() { addControls(this.container, [{ size: ['10px', false, '18px', '32px'] }]); expect(this.container).toEqualHTML(` `); }); it('everything', function() { addControls(this.container, [ [ { font: [false, 'sans-serif', 'monospace'] }, { size: ['10px', false, '18px', '32px'] }, ], ['bold', 'italic', 'underline', 'strike'], [ { list: 'ordered' }, { list: 'bullet' }, { align: [false, 'center', 'right', 'justify'] }, ], ['link', 'image'], ]); expect(this.container).toEqualHTML(` `); }); }); describe('active', function() { beforeEach(function() { const container = this.initialize( HTMLElement, `

0123

5678

0123

5678

0123

`, ); this.quill = new Quill(container, { modules: { toolbar: [ ['bold', 'link'], [{ size: ['small', false, 'large'] }], [{ align: '' }, { align: 'center' }], ], }, theme: 'snow', }); }); it('toggle button', function() { const boldButton = this.container.parentNode.querySelector( 'button.ql-bold', ); this.quill.setSelection(7); expect(boldButton.classList.contains('ql-active')).toBe(true); this.quill.setSelection(2); expect(boldButton.classList.contains('ql-active')).toBe(false); }); it('link', function() { const linkButton = this.container.parentNode.querySelector( 'button.ql-link', ); this.quill.setSelection(12); expect(linkButton.classList.contains('ql-active')).toBe(true); this.quill.setSelection(2); expect(linkButton.classList.contains('ql-active')).toBe(false); }); it('dropdown', function() { const sizeSelect = this.container.parentNode.querySelector( 'select.ql-size', ); this.quill.setSelection(21); expect(sizeSelect.selectedIndex).toEqual(0); this.quill.setSelection(23); expect(sizeSelect.selectedIndex).toEqual(2); this.quill.setSelection(21, 2); expect(sizeSelect.selectedIndex).toBeLessThan(0); this.quill.setSelection(2); expect(sizeSelect.selectedIndex).toEqual(1); }); it('custom button', function() { const centerButton = this.container.parentNode.querySelector( 'button.ql-align[value="center"]', ); const leftButton = this.container.parentNode.querySelector( 'button.ql-align[value]', ); this.quill.setSelection(17); expect(centerButton.classList.contains('ql-active')).toBe(true); expect(leftButton.classList.contains('ql-active')).toBe(false); this.quill.setSelection(2); expect(centerButton.classList.contains('ql-active')).toBe(false); expect(leftButton.classList.contains('ql-active')).toBe(true); this.quill.blur(); expect(centerButton.classList.contains('ql-active')).toBe(false); expect(leftButton.classList.contains('ql-active')).toBe(false); }); }); });