8
0

attribute.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. const modules = bender.amd.require( 'document/attribute' );
  8. describe( 'Attribute', function() {
  9. let Attribute;
  10. before( function() {
  11. Attribute = modules[ 'document/attribute' ];
  12. } );
  13. beforeEach( function() {
  14. Attribute._register = {};
  15. } );
  16. describe( 'constructor', function() {
  17. it( 'should create attribute', function() {
  18. var attr = new Attribute( 'foo', 'bar' );
  19. expect( attr ).to.have.property( 'key' ).that.equals( 'foo' );
  20. expect( attr ).to.have.property( 'value' ).that.equals( 'bar' );
  21. } );
  22. it( 'should create equal instance even if object has different order', function() {
  23. var attr1 = new Attribute( 'foo', { a: 1, b: 2 } );
  24. var attr2 = new Attribute( 'foo', { b: 2, a: 1 } );
  25. expect( attr1.isEqual( attr2 ) ).to.be.true;
  26. } );
  27. it( 'should return the same object for registered objects', function() {
  28. Attribute.register( 'register', true );
  29. var attr1 = new Attribute( 'register', true );
  30. var attr2 = new Attribute( 'register', true );
  31. expect( attr1 ).to.equal( attr2 );
  32. expect( attr1.isEqual( attr2 ) ).to.be.true;
  33. } );
  34. it( 'should return different objects for different values', function() {
  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. Attribute.register( 'register', true );
  43. var attr1 = new Attribute( 'register', false );
  44. var attr2 = new Attribute( 'register', false );
  45. expect( attr1 ).to.not.be.equals( attr2 );
  46. expect( attr1.isEqual( attr2 ) ).to.be.true;
  47. } );
  48. } );
  49. describe( 'register', function() {
  50. it( 'Attribute.register should return registered attribute', function() {
  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.equal( attr3 );
  57. expect( attr3 ).to.equal( attr4 );
  58. } );
  59. } );
  60. } );