editor-base.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. 'use strict';
  7. import Editor from '/ckeditor5/editor/editor.js';
  8. import Command from '/ckeditor5/command/command.js';
  9. import Locale from '/ckeditor5/utils/locale.js';
  10. import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
  11. describe( 'Editor', () => {
  12. describe( 'locale', () => {
  13. it( 'is instantiated and t() is exposed', () => {
  14. const editor = new Editor();
  15. expect( editor.locale ).to.be.instanceof( Locale );
  16. expect( editor.t ).to.equal( editor.locale.t );
  17. } );
  18. it( 'is configured with the config.lang', () => {
  19. const editor = new Editor( { lang: 'pl' } );
  20. expect( editor.locale.lang ).to.equal( 'pl' );
  21. } );
  22. } );
  23. describe( 'destroy', () => {
  24. it( 'should fire "destroy"', () => {
  25. const editor = new Editor();
  26. let spy = sinon.spy();
  27. editor.on( 'destroy', spy );
  28. return editor.destroy().then( () => {
  29. expect( spy.calledOnce ).to.be.true;
  30. } );
  31. } );
  32. it( 'should destroy all components it initialized', () => {
  33. const editor = new Editor();
  34. const spy1 = sinon.spy( editor.data, 'destroy' );
  35. const spy2 = sinon.spy( editor.document, 'destroy' );
  36. return editor.destroy()
  37. .then( () => {
  38. expect( spy1.calledOnce ).to.be.true;
  39. expect( spy2.calledOnce ).to.be.true;
  40. } );
  41. } );
  42. } );
  43. describe( 'execute', () => {
  44. it( 'should execute specified command', () => {
  45. const editor = new Editor();
  46. let command = new Command( editor );
  47. sinon.spy( command, '_execute' );
  48. editor.commands.set( 'commandName', command );
  49. editor.execute( 'commandName' );
  50. expect( command._execute.calledOnce ).to.be.true;
  51. } );
  52. it( 'should throw an error if specified command has not been added', () => {
  53. const editor = new Editor();
  54. expect( () => {
  55. editor.execute( 'command' );
  56. } ).to.throw( CKEditorError, /^editor-command-not-found:/ );
  57. } );
  58. } );
  59. } );