list.js 3.8 KB

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