Composite.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. topSuite("Ext.draw.sprite.Composite", ['Ext.draw.sprite.*'], function() {
  2. var proto = Ext.draw.sprite.Text.prototype;
  3. describe('add', function () {
  4. var draw;
  5. it('should remove added sprites from their surface', function () {
  6. draw = new Ext.draw.Container({
  7. renderTo: document.body,
  8. width: 200,
  9. height: 200,
  10. sprites: [
  11. {
  12. type: 'rect',
  13. id: 'rect',
  14. x: 50,
  15. y: 50,
  16. width: 100,
  17. height: 100,
  18. fillStyle: 'orange'
  19. },
  20. {
  21. type: 'circle',
  22. id: 'circle',
  23. cx: 100,
  24. cy: 100,
  25. r: 50,
  26. fillStyle: 'red'
  27. }
  28. ]
  29. });
  30. var mainSurface = draw.getSurface();
  31. var composite = new Ext.draw.sprite.Composite();
  32. expect(mainSurface.getItems().length).toBe(2);
  33. composite.add(mainSurface.get('rect'));
  34. composite.add(mainSurface.get('circle'));
  35. mainSurface.add(composite);
  36. expect(mainSurface.getItems().length).toBe(1);
  37. expect(mainSurface.get(0).isComposite).toBe(true);
  38. });
  39. afterEach(function () {
  40. Ext.destroy(draw);
  41. });
  42. });
  43. describe('destroy', function () {
  44. it("should destroy composite's children", function () {
  45. var composite = new Ext.draw.sprite.Composite({});
  46. composite.add({
  47. type: 'text',
  48. text: 'hello'
  49. });
  50. composite.add({
  51. type: 'rect'
  52. });
  53. var sprites = composite.sprites,
  54. child = sprites[1];
  55. composite.destroy();
  56. expect(sprites.length).toEqual(0);
  57. expect(child.destroyed).toEqual(true);
  58. });
  59. });
  60. });