utils.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import { add as addTranslations, _clear as clearTranslations } from '@ckeditor/ckeditor5-utils/src/translation-service';
  8. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  9. import Heading from '../src/heading';
  10. import { getLocalizedOptions } from '../src/utils';
  11. describe( 'utils', () => {
  12. testUtils.createSinonSandbox();
  13. describe( 'getLocalizedOptions()', () => {
  14. let editor, editorElement;
  15. before( () => {
  16. addTranslations( 'pl', {
  17. 'Choose heading': 'Wybierz nagłówek',
  18. 'Paragraph': 'Akapit',
  19. 'Heading': 'Nagłówek',
  20. 'Heading 1': 'Nagłówek 1',
  21. 'Heading 2': 'Nagłówek 2',
  22. 'Heading 3': 'Nagłówek 3'
  23. } );
  24. } );
  25. after( () => {
  26. clearTranslations();
  27. } );
  28. beforeEach( () => {
  29. editorElement = document.createElement( 'div' );
  30. document.body.appendChild( editorElement );
  31. return ClassicTestEditor
  32. .create( editorElement, {
  33. plugins: [ Heading ],
  34. toolbar: [ 'heading' ],
  35. language: 'pl'
  36. } )
  37. .then( newEditor => {
  38. editor = newEditor;
  39. } );
  40. } );
  41. afterEach( () => {
  42. editorElement.remove();
  43. return editor.destroy();
  44. } );
  45. it( 'should return localized options', () => {
  46. const localized = getLocalizedOptions( editor );
  47. expect( Array.isArray( localized ) ).to.be.true;
  48. expect( localized.length ).to.equal( editor.config.get( 'heading.options' ).length );
  49. expect( localized.find( item => item.model == 'paragraph' ).title ).to.equal( 'Akapit' );
  50. expect( localized.find( item => item.model == 'heading1' ).title ).to.equal( 'Nagłówek 1' );
  51. expect( localized.find( item => item.model == 'heading2' ).title ).to.equal( 'Nagłówek 2' );
  52. expect( localized.find( item => item.model == 'heading3' ).title ).to.equal( 'Nagłówek 3' );
  53. } );
  54. } );
  55. } );