editor-base.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: editor */
  6. import Editor from '/ckeditor5/editor/editor.js';
  7. import Command from '/ckeditor5/command/command.js';
  8. import Locale from '/ckeditor5/utils/locale.js';
  9. import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
  10. describe( 'Editor', () => {
  11. describe( 'locale', () => {
  12. it( 'is instantiated and t() is exposed', () => {
  13. const editor = new Editor();
  14. expect( editor.locale ).to.be.instanceof( Locale );
  15. expect( editor.t ).to.equal( editor.locale.t );
  16. } );
  17. it( 'is configured with the config.lang', () => {
  18. const editor = new Editor( { lang: 'pl' } );
  19. expect( editor.locale.lang ).to.equal( 'pl' );
  20. } );
  21. } );
  22. describe( 'destroy', () => {
  23. it( 'should fire "destroy"', () => {
  24. const editor = new Editor();
  25. let spy = sinon.spy();
  26. editor.on( 'destroy', spy );
  27. return editor.destroy().then( () => {
  28. expect( spy.calledOnce ).to.be.true;
  29. } );
  30. } );
  31. it( 'should destroy all components it initialized', () => {
  32. const editor = new Editor();
  33. const spy1 = sinon.spy( editor.data, 'destroy' );
  34. const spy2 = sinon.spy( editor.document, 'destroy' );
  35. return editor.destroy()
  36. .then( () => {
  37. expect( spy1.calledOnce ).to.be.true;
  38. expect( spy2.calledOnce ).to.be.true;
  39. } );
  40. } );
  41. } );
  42. describe( 'execute', () => {
  43. it( 'should execute specified command', () => {
  44. const editor = new Editor();
  45. let command = new Command( editor );
  46. sinon.spy( command, '_execute' );
  47. editor.commands.set( 'commandName', command );
  48. editor.execute( 'commandName' );
  49. expect( command._execute.calledOnce ).to.be.true;
  50. } );
  51. it( 'should throw an error if specified command has not been added', () => {
  52. const editor = new Editor();
  53. expect( () => {
  54. editor.execute( 'command' );
  55. } ).to.throw( CKEditorError, /^editor-command-not-found:/ );
  56. } );
  57. } );
  58. } );