OLD | NEW |
1 library ng_style_spec; | 1 library ng_style_spec; |
2 | 2 |
3 import '../_specs.dart'; | 3 import '../_specs.dart'; |
4 import 'dart:html' as dom; | 4 import 'dart:html' as dom; |
5 | 5 |
6 main() => describe('NgStyle', () { | 6 void main() { |
7 TestBed _; | 7 describe('NgStyle', () { |
| 8 TestBed _; |
8 | 9 |
9 beforeEach(inject((TestBed tb) => _ = tb)); | 10 beforeEach((TestBed tb) => _ = tb); |
10 | 11 |
11 it('should set', () { | 12 it('should set', () { |
12 dom.Element element = _.compile('<div ng-style="{height: \'40px\'}"></div>')
; | 13 dom.Element element = _.compile('<div ng-style="{height: \'40px\'}"></div>
'); |
13 _.rootScope.apply(); | 14 _.rootScope.apply(); |
14 expect(element.style.height).toEqual('40px'); | 15 expect(element.style.height).toEqual('40px'); |
15 }); | |
16 | |
17 | |
18 it('should silently ignore undefined style', () { | |
19 dom.Element element = _.compile('<div ng-style="myStyle"></div>'); | |
20 _.rootScope.apply(); | |
21 expect(element.classes.contains('ng-exception')).toBeFalsy(); | |
22 }); | |
23 | |
24 | |
25 describe('preserving styles set before and after compilation', () { | |
26 var scope, preCompStyle, preCompVal, postCompStyle, postCompVal, element; | |
27 | |
28 beforeEach(inject(() { | |
29 preCompStyle = 'width'; | |
30 preCompVal = '300px'; | |
31 postCompStyle = 'height'; | |
32 postCompVal = '100px'; | |
33 element = $('<div ng-style="styleObj"></div>'); | |
34 element.css(preCompStyle, preCompVal); | |
35 document.body.append(element[0]); | |
36 _.compile(element); | |
37 scope = _.rootScope; | |
38 scope.context['styleObj'] = {'margin-top': '44px'}; | |
39 scope.apply(); | |
40 element.css(postCompStyle, postCompVal); | |
41 })); | |
42 | |
43 afterEach(() { | |
44 element.remove(null); | |
45 }); | 16 }); |
46 | 17 |
47 | 18 |
48 it('should not mess up stuff after compilation', () { | 19 it('should silently ignore undefined style', () { |
49 element.css('margin', '44px'); | 20 dom.Element element = _.compile('<div ng-style="myStyle"></div>'); |
50 expect(element.css(preCompStyle)).toEqual(preCompVal); | 21 _.rootScope.apply(); |
51 expect(element.css('margin-top')).toEqual('44px'); | 22 expect(element).not.toHaveClass('ng-exception'); |
52 expect(element.css(postCompStyle)).toEqual(postCompVal); | |
53 }); | |
54 | |
55 it(r'should not mess up stuff after $apply with no model changes', () { | |
56 element.css('padding-top', '33px'); | |
57 scope.apply(); | |
58 expect(element.css(preCompStyle)).toEqual(preCompVal); | |
59 expect(element.css('margin-top')).toEqual('44px'); | |
60 expect(element.css(postCompStyle)).toEqual(postCompVal); | |
61 expect(element.css('padding-top')).toEqual('33px'); | |
62 }); | 23 }); |
63 | 24 |
64 | 25 |
65 it(r'should not mess up stuff after $apply with non-colliding model changes'
, () { | 26 describe('preserving styles set before and after compilation', () { |
66 scope.context['styleObj'] = {'padding-top': '99px'}; | 27 var scope, preCompStyle, widthVal, postCompStyle, heightVal; |
67 scope.apply(); | 28 Element element; |
68 expect(element.css(preCompStyle)).toEqual(preCompVal); | 29 |
69 expect(element.css('margin-top')).not.toEqual('44px'); | 30 beforeEach(() { |
70 expect(element.css('padding-top')).toEqual('99px'); | 31 preCompStyle = 'width'; |
71 expect(element.css(postCompStyle)).toEqual(postCompVal); | 32 widthVal = '300px'; |
72 }); | 33 postCompStyle = 'height'; |
| 34 heightVal = '100px'; |
| 35 element = e('<div ng-style="styleObj"></div>'); |
| 36 element.style.width = widthVal; |
| 37 document.body.append(element); |
| 38 _.compile(element); |
| 39 scope = _.rootScope; |
| 40 scope.context['styleObj'] = {'margin-top': '44px'}; |
| 41 scope.apply(); |
| 42 element.style.height = heightVal; |
| 43 }); |
| 44 |
| 45 it('should not mess up stuff after compilation', () { |
| 46 element.style.margin = '44px'; |
| 47 expect(element.style.width).toEqual(widthVal); |
| 48 expect(element.style.marginTop).toEqual('44px'); |
| 49 expect(element.style.height).toEqual(heightVal); |
| 50 }); |
| 51 |
| 52 it(r'should not mess up stuff after $apply with no model changes', () { |
| 53 element.style.paddingTop = '33px'; |
| 54 scope.apply(); |
| 55 expect(element.style.width).toEqual(widthVal); |
| 56 expect(element.style.marginTop).toEqual('44px'); |
| 57 expect(element.style.height).toEqual(heightVal); |
| 58 expect(element.style.paddingTop).toEqual('33px'); |
| 59 }); |
73 | 60 |
74 | 61 |
75 it(r'should overwrite original styles after a colliding model change', () { | 62 it(r'should not mess up stuff after $apply with non-colliding model change
s', () { |
76 scope.context['styleObj'] = {'height': '99px', 'width': '88px'}; | 63 scope.context['styleObj'] = {'padding-top': '99px'}; |
77 scope.apply(); | 64 scope.apply(); |
78 expect(element.css(preCompStyle)).toEqual('88px'); | 65 expect(element.style.width).toEqual(widthVal); |
79 expect(element.css(postCompStyle)).toEqual('99px'); | 66 expect(element.style.marginTop).not.toEqual('44px'); |
80 scope.context['styleObj'] = {}; | 67 expect(element.style.paddingTop).toEqual('99px'); |
81 scope.apply(); | 68 expect(element.style.height).toEqual(heightVal); |
82 expect(element.css(preCompStyle)).not.toEqual('88px'); | 69 }); |
83 expect(element.css(postCompStyle)).not.toEqual('99px'); | 70 |
| 71 |
| 72 it(r'should overwrite original styles after a colliding model change', ()
{ |
| 73 scope.context['styleObj'] = {'height': '99px', 'width': '88px'}; |
| 74 scope.apply(); |
| 75 expect(element.style.width).toEqual('88px'); |
| 76 expect(element.style.height).toEqual('99px'); |
| 77 scope.context['styleObj'] = {}; |
| 78 scope.apply(); |
| 79 expect(element.style.width).not.toEqual('88px'); |
| 80 expect(element.style.height).not.toEqual('99px'); |
| 81 }); |
84 }); | 82 }); |
85 }); | 83 }); |
86 }); | 84 } |
OLD | NEW |