8
0

attribute.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: document */
  6. 'use strict';
  7. var modules = bender.amd.require( 'document/attribute' );
  8. describe( 'attribute', function() {
  9. beforeEach( function() {
  10. var Attribute = modules[ 'document/attribute' ];
  11. Attribute._register = {};
  12. } );
  13. it( 'should create attribute', function() {
  14. var Attribute = modules[ 'document/attribute' ];
  15. var attr = new Attribute( 'foo', 'bar' );
  16. expect( attr ).to.have.property( 'key' ).that.equals( 'foo' );
  17. expect( attr ).to.have.property( 'value' ).that.equals( 'bar' );
  18. } );
  19. it( 'should create equal instance even if object has different order', function() {
  20. var Attribute = modules[ 'document/attribute' ];
  21. var attr1 = new Attribute( 'foo', { a: 1, b: 2 } );
  22. var attr2 = new Attribute( 'foo', { b: 2, a: 1 } );
  23. expect( attr1.isEqual( attr2 ) ).to.be.true;
  24. } );
  25. it( 'should return the same object for registered objects', function() {
  26. var Attribute = modules[ 'document/attribute' ];
  27. Attribute.register( 'register', true );
  28. var attr1 = new Attribute( 'register', true );
  29. var attr2 = new Attribute( 'register', true );
  30. expect( attr1 ).to.be.equals( attr2 );
  31. expect( attr1.isEqual( attr2 ) ).to.be.true;
  32. } );
  33. it( 'should return different objects for different values', function() {
  34. var Attribute = modules[ 'document/attribute' ];
  35. Attribute.register( 'register', true );
  36. var attr1 = new Attribute( 'register', true );
  37. var attr2 = new Attribute( 'register', false );
  38. expect( attr1 ).to.not.be.equals( attr2 );
  39. expect( attr1.isEqual( attr2 ) ).to.not.be.true;
  40. } );
  41. it( 'should return different objects for not registered objects', function() {
  42. var Attribute = modules[ 'document/attribute' ];
  43. Attribute.register( 'register', true );
  44. var attr1 = new Attribute( 'register', false );
  45. var attr2 = new Attribute( 'register', false );
  46. expect( attr1 ).to.not.be.equals( attr2 );
  47. expect( attr1.isEqual( attr2 ) ).to.be.true;
  48. } );
  49. it( 'Attribute.register should return registered attribute', function() {
  50. var Attribute = modules[ 'document/attribute' ];
  51. var attr1 = new Attribute( 'register', true );
  52. var attr2 = Attribute.register( 'register', true );
  53. var attr3 = Attribute.register( 'register', true );
  54. var attr4 = new Attribute( 'register', true );
  55. expect( attr1 ).to.not.be.equals( attr2 );
  56. expect( attr2 ).to.be.equals( attr3 );
  57. expect( attr3 ).to.be.equals( attr4 );
  58. } );
  59. } );