OLD | NEW |
(Empty) | |
| 1 library css_animation_spec; |
| 2 |
| 3 import '../_specs.dart'; |
| 4 |
| 5 main() { |
| 6 describe('CssAnimation', () { |
| 7 TestBed _; |
| 8 |
| 9 beforeEach(inject((TestBed tb) => _ = tb)); |
| 10 afterEach(() => _.rootElements.forEach((e) => e.remove())); |
| 11 |
| 12 it('should correctly respond to an animation lifecycle', async(() { |
| 13 _.compile("<style>.event { transition: all 500ms; }</style>" |
| 14 +"<div class='always remove-start remove-end'></div>"); |
| 15 |
| 16 _.rootElements.forEach((e) => document.body.append(e)); |
| 17 var element = _.rootElements[1]; |
| 18 |
| 19 expect(element).toHaveClass('always'); |
| 20 expect(element).toHaveClass('remove-start'); |
| 21 expect(element).toHaveClass('remove-end'); |
| 22 expect(element).not.toHaveClass('event'); |
| 23 expect(element).not.toHaveClass('event-active'); |
| 24 expect(element).not.toHaveClass('add-start'); |
| 25 expect(element).not.toHaveClass('add-end'); |
| 26 |
| 27 var animation = new CssAnimation(element, |
| 28 "event", |
| 29 "event-active", |
| 30 addAtStart: "add-start", |
| 31 removeAtStart: "remove-start", |
| 32 addAtEnd: "add-end", |
| 33 removeAtEnd: "remove-end"); |
| 34 |
| 35 expect(element).toHaveClass('always'); |
| 36 expect(element).not.toHaveClass('remove-start'); |
| 37 expect(element).toHaveClass('remove-end'); |
| 38 expect(element).toHaveClass('event'); |
| 39 expect(element).not.toHaveClass('event-active'); |
| 40 expect(element).toHaveClass('add-start'); |
| 41 expect(element).not.toHaveClass('add-end'); |
| 42 |
| 43 animation.read(0.0); |
| 44 animation.update(0.0); |
| 45 |
| 46 expect(element).toHaveClass('always'); |
| 47 expect(element).not.toHaveClass('remove-start'); |
| 48 expect(element).toHaveClass('remove-end'); |
| 49 expect(element).toHaveClass('event'); |
| 50 expect(element).toHaveClass('event-active'); |
| 51 expect(element).toHaveClass('add-start'); |
| 52 expect(element).not.toHaveClass('add-end'); |
| 53 |
| 54 animation.read(1000.0); |
| 55 animation.update(1000.0); |
| 56 |
| 57 expect(element).toHaveClass('always'); |
| 58 expect(element).not.toHaveClass('remove-start'); |
| 59 expect(element).not.toHaveClass('remove-end'); |
| 60 expect(element).not.toHaveClass('event'); |
| 61 expect(element).not.toHaveClass('event-active'); |
| 62 expect(element).toHaveClass('add-start'); |
| 63 expect(element).toHaveClass('add-end'); |
| 64 |
| 65 _.rootElements.forEach((e) => e.remove()); |
| 66 })); |
| 67 |
| 68 it('should swap removeAtEnd class if initial style is display none', async((
) { |
| 69 _.compile("<style>.event { transition: all 500ms; display: none; }</style>
" |
| 70 "<div class='remove-at-end'></div>"); |
| 71 _.rootElements.forEach((e) => document.body.append(e)); |
| 72 var element = _.rootElements[1]; |
| 73 |
| 74 var animation = new CssAnimation(element, "event", "event-active", |
| 75 removeAtEnd: 'remove-at-end', addAtEnd: 'add-at-end'); |
| 76 |
| 77 expect(element).toHaveClass('remove-at-end'); |
| 78 |
| 79 animation.read(0.0); |
| 80 animation.update(0.0); |
| 81 expect(element).not.toHaveClass('remove-at-end'); |
| 82 expect(element).not.toHaveClass('add-at-end'); |
| 83 |
| 84 animation.read(1000.0); |
| 85 animation.update(1000.0); |
| 86 expect(element).toHaveClass('add-at-end'); |
| 87 expect(element).not.toHaveClass('remove-at-end'); |
| 88 })); |
| 89 |
| 90 it('should add classes at end', async(() { |
| 91 _.compile("<style>.event { transition: all 500ms; }</style><div></div>"); |
| 92 _.rootElements.forEach((e) => document.body.append(e)); |
| 93 var element = _.rootElements[1]; |
| 94 |
| 95 var animation = new CssAnimation(element, "event", "event-active", |
| 96 addAtEnd: 'add-at-end'); |
| 97 |
| 98 animation.read(0.0); |
| 99 animation.update(0.0); |
| 100 expect(element).not.toHaveClass('add-at-end'); |
| 101 |
| 102 animation.read(1000.0); |
| 103 animation.update(1000.0); |
| 104 expect(element).toHaveClass('add-at-end'); |
| 105 expect(element).not.toHaveClass('event'); |
| 106 expect(element).not.toHaveClass('event-active'); |
| 107 })); |
| 108 |
| 109 it('should remove the cssClassToRemove', async(() { |
| 110 _.compile("<style>.event { transition: all 500ms; }</style>" |
| 111 +"<div class=\"remove-end\"></div>"); |
| 112 _.rootElements.forEach((e) => document.body.append(e)); |
| 113 var element = _.rootElements[1]; |
| 114 |
| 115 var animation = new CssAnimation(element, "event", "event-active", |
| 116 removeAtEnd: 'magic'); |
| 117 |
| 118 animation.complete(); |
| 119 expect(element).not.toHaveClass('magic'); |
| 120 |
| 121 expect(element).not.toHaveClass('event'); |
| 122 expect(element).not.toHaveClass('event-active'); |
| 123 })); |
| 124 |
| 125 it('should clean up event classes when canceled after read', async(() { |
| 126 _.compile("<style>.event { transition: all 500ms; }</style><div></div>"); |
| 127 _.rootElements.forEach((e) => document.body.append(e)); |
| 128 var element = _.rootElements[1]; |
| 129 var animation = new CssAnimation(element, "event", "event-active", |
| 130 addAtEnd: 'magic'); |
| 131 |
| 132 animation.read(0.0); |
| 133 animation.cancel(); |
| 134 expect(element).not.toHaveClass('magic'); |
| 135 expect(element).not.toHaveClass('event'); |
| 136 expect(element).not.toHaveClass('event-active'); |
| 137 })); |
| 138 |
| 139 it('should clean up event classes when canceled after update', async(() { |
| 140 _.compile("<style>.event { transition: all 500ms; }</style><div></div>"); |
| 141 _.rootElements.forEach((e) => document.body.append(e)); |
| 142 var element = _.rootElements[1]; |
| 143 |
| 144 var animation = new CssAnimation(element, "event", "event-active", |
| 145 addAtEnd: 'add-end'); |
| 146 |
| 147 animation.read(0.0); |
| 148 animation.update(0.0); |
| 149 animation.cancel(); |
| 150 expect(element).not.toHaveClass('add-end'); |
| 151 expect(element).not.toHaveClass('event'); |
| 152 expect(element).not.toHaveClass('event-active'); |
| 153 })); |
| 154 }); |
| 155 } |
| 156 |
OLD | NEW |