view.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: core, ui */
  6. 'use strict';
  7. var modules = bender.amd.require( 'ckeditor', 'ui/view', 'ckeditorerror' );
  8. describe( 'View', function() {
  9. var view;
  10. beforeEach( 'Create a test view instance', function() {
  11. var View = modules[ 'ui/view' ];
  12. view = new View( {
  13. a: 'foo',
  14. b: 42
  15. } );
  16. } );
  17. it( 'accepts the model', function() {
  18. expect( view ).to.have.deep.property( 'model.a', 'foo' );
  19. expect( view ).to.have.deep.property( 'model.b', 42 );
  20. } );
  21. it( 'has no default element', function() {
  22. expect( () => view.el ).to.throw( modules.ckeditorerror );
  23. } );
  24. it( 'has no default template', function() {
  25. expect( view.template ).to.be.undefined();
  26. } );
  27. it( 'has no default regions', function() {
  28. expect( view.regions.length ).to.be.equal( 0 );
  29. } );
  30. it( 'provides binding to the model', function() {
  31. var spy = sinon.spy();
  32. var callback = view.bind( 'a', spy );
  33. expect( spy.called ).to.be.false;
  34. callback( 'el', 'updater' );
  35. sinon.assert.calledOnce( spy );
  36. sinon.assert.calledWithExactly( spy, 'el', 'foo' );
  37. spy.reset();
  38. view.model.a = 'bar';
  39. sinon.assert.calledOnce( spy );
  40. sinon.assert.calledWithExactly( spy, 'el', 'bar' );
  41. } );
  42. } );