align.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import Delta from 'quill-delta';
  2. import Editor from '../../../core/editor';
  3. describe('Align', function() {
  4. it('add', function() {
  5. const editor = this.initialize(Editor, '<p>0123</p>');
  6. editor.formatText(4, 1, { align: 'center' });
  7. expect(editor.getDelta()).toEqual(
  8. new Delta().insert('0123').insert('\n', { align: 'center' }),
  9. );
  10. expect(editor.scroll.domNode).toEqualHTML(
  11. '<p class="ql-align-center">0123</p>',
  12. );
  13. });
  14. it('remove', function() {
  15. const editor = this.initialize(
  16. Editor,
  17. '<p class="ql-align-center">0123</p>',
  18. );
  19. editor.formatText(4, 1, { align: false });
  20. expect(editor.getDelta()).toEqual(new Delta().insert('0123\n'));
  21. expect(editor.scroll.domNode).toEqualHTML('<p>0123</p>');
  22. });
  23. it('whitelist', function() {
  24. const editor = this.initialize(
  25. Editor,
  26. '<p class="ql-align-center">0123</p>',
  27. );
  28. const initial = editor.scroll.domNode.innerHTML;
  29. editor.formatText(4, 1, { align: 'middle' });
  30. expect(editor.getDelta()).toEqual(
  31. new Delta().insert('0123').insert('\n', { align: 'center' }),
  32. );
  33. expect(editor.scroll.domNode).toEqualHTML(initial);
  34. });
  35. it('invalid scope', function() {
  36. const editor = this.initialize(Editor, '<p>0123</p>');
  37. const initial = editor.scroll.domNode.innerHTML;
  38. editor.formatText(1, 2, { align: 'center' });
  39. expect(editor.getDelta()).toEqual(new Delta().insert('0123\n'));
  40. expect(editor.scroll.domNode).toEqualHTML(initial);
  41. });
  42. });