8
0

list.js 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  6. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  7. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  8. import PasteFromOffice from '../../../src/pastefromoffice';
  9. import { stringify } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  10. import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
  11. import simple from '../../_data/list/simple/input.word2016.html';
  12. import styled from '../../_data/list/styled/input.word2016.html';
  13. import multiple from '../../_data/list/multiple/input.word2016.html';
  14. import multipleCombined from '../../_data/list/multiple-combined/input.word2016.html';
  15. import manyOneItem from '../../_data/list/many-one-item/input.word2016.html';
  16. import heading1 from '../../_data/list/heading1/input.word2016.html';
  17. import heading3Styled from '../../_data/list/heading3-styled/input.word2016.html';
  18. import heading7 from '../../_data/list/heading7/input.word2016.html';
  19. import simpleNormalized from '../../_data/list/simple/normalized.word2016.html';
  20. import styledNormalized from '../../_data/list/styled/normalized.word2016.html';
  21. import multipleNormalized from '../../_data/list/multiple/normalized.word2016.html';
  22. import multipleCombinedNormalized from '../../_data/list/multiple-combined/normalized.word2016.html';
  23. import manyOneItemNormalized from '../../_data/list/many-one-item/normalized.word2016.html';
  24. import heading1Normalized from '../../_data/list/heading1/normalized.word2016.html';
  25. import heading3StyledNormalized from '../../_data/list/heading3-styled/normalized.word2016.html';
  26. import heading7Normalized from '../../_data/list/heading7/normalized.word2016.html';
  27. describe( 'List – normalization', () => {
  28. let editor, pasteFromOfficePlugin;
  29. testUtils.createSinonSandbox();
  30. beforeEach( () => {
  31. return VirtualTestEditor
  32. .create( {
  33. plugins: [ Clipboard, PasteFromOffice ]
  34. } )
  35. .then( newEditor => {
  36. editor = newEditor;
  37. pasteFromOfficePlugin = editor.plugins.get( 'PasteFromOffice' );
  38. } );
  39. } );
  40. it( 'normalizes simple list', () => {
  41. expectNormalized( pasteFromOfficePlugin._normalizeWordInput( simple, editor ), simpleNormalized );
  42. } );
  43. it( 'normalizes list with styled items prepended by a paragraph', () => {
  44. expectNormalized( pasteFromOfficePlugin._normalizeWordInput( styled, editor ), styledNormalized );
  45. } );
  46. it( 'normalizes multiple lists separated by the paragraph', () => {
  47. expectNormalized( pasteFromOfficePlugin._normalizeWordInput( multiple, editor ), multipleNormalized );
  48. } );
  49. it( 'normalizes multiple lists one right after another', () => {
  50. expectNormalized( pasteFromOfficePlugin._normalizeWordInput( multipleCombined, editor ), multipleCombinedNormalized );
  51. } );
  52. it( 'normalizes many one item lists', () => {
  53. expectNormalized( pasteFromOfficePlugin._normalizeWordInput( manyOneItem, editor ), manyOneItemNormalized );
  54. } );
  55. it( 'normalizes list created from headings (h1)', () => {
  56. expectNormalized( pasteFromOfficePlugin._normalizeWordInput( heading1, editor ), heading1Normalized );
  57. } );
  58. it( 'normalizes list created from styled headings (h3)', () => {
  59. expectNormalized( pasteFromOfficePlugin._normalizeWordInput( heading3Styled, editor ), heading3StyledNormalized );
  60. } );
  61. it( 'normalizes list created from heading (h7)', () => {
  62. expectNormalized( pasteFromOfficePlugin._normalizeWordInput( heading7, editor ), heading7Normalized );
  63. } );
  64. } );
  65. function expectNormalized( normalizedInput, expectedInput ) {
  66. let expected = expectedInput.replace( /> /g, '>&nbsp;' ).replace( / </g, '&nbsp;<' );
  67. expected = normalizeHtml( expected );
  68. expected = expected.replace( />\s+</g, '><' );
  69. expect( stringify( normalizedInput ) ).to.equal( expected );
  70. }