| 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 void main() { | 6 main() => describe('NgStyle', () { |
| 7 describe('NgStyle', () { | 7 TestBed _; |
| 8 TestBed _; | |
| 9 | 8 |
| 10 beforeEach((TestBed tb) => _ = tb); | 9 beforeEach(inject((TestBed tb) => _ = tb)); |
| 11 | 10 |
| 12 it('should set', () { | 11 it('should set', () { |
| 13 dom.Element element = _.compile('<div ng-style="{height: \'40px\'}"></div>
'); | 12 dom.Element element = _.compile('<div ng-style="{height: \'40px\'}"></div>')
; |
| 14 _.rootScope.apply(); | 13 _.rootScope.apply(); |
| 15 expect(element.style.height).toEqual('40px'); | 14 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); |
| 16 }); | 45 }); |
| 17 | 46 |
| 18 | 47 |
| 19 it('should silently ignore undefined style', () { | 48 it('should not mess up stuff after compilation', () { |
| 20 dom.Element element = _.compile('<div ng-style="myStyle"></div>'); | 49 element.css('margin', '44px'); |
| 21 _.rootScope.apply(); | 50 expect(element.css(preCompStyle)).toEqual(preCompVal); |
| 22 expect(element).not.toHaveClass('ng-exception'); | 51 expect(element.css('margin-top')).toEqual('44px'); |
| 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'); |
| 23 }); | 62 }); |
| 24 | 63 |
| 25 | 64 |
| 26 describe('preserving styles set before and after compilation', () { | 65 it(r'should not mess up stuff after $apply with non-colliding model changes'
, () { |
| 27 var scope, preCompStyle, widthVal, postCompStyle, heightVal; | 66 scope.context['styleObj'] = {'padding-top': '99px'}; |
| 28 Element element; | 67 scope.apply(); |
| 29 | 68 expect(element.css(preCompStyle)).toEqual(preCompVal); |
| 30 beforeEach(() { | 69 expect(element.css('margin-top')).not.toEqual('44px'); |
| 31 preCompStyle = 'width'; | 70 expect(element.css('padding-top')).toEqual('99px'); |
| 32 widthVal = '300px'; | 71 expect(element.css(postCompStyle)).toEqual(postCompVal); |
| 33 postCompStyle = 'height'; | 72 }); |
| 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 }); | |
| 60 | 73 |
| 61 | 74 |
| 62 it(r'should not mess up stuff after $apply with non-colliding model change
s', () { | 75 it(r'should overwrite original styles after a colliding model change', () { |
| 63 scope.context['styleObj'] = {'padding-top': '99px'}; | 76 scope.context['styleObj'] = {'height': '99px', 'width': '88px'}; |
| 64 scope.apply(); | 77 scope.apply(); |
| 65 expect(element.style.width).toEqual(widthVal); | 78 expect(element.css(preCompStyle)).toEqual('88px'); |
| 66 expect(element.style.marginTop).not.toEqual('44px'); | 79 expect(element.css(postCompStyle)).toEqual('99px'); |
| 67 expect(element.style.paddingTop).toEqual('99px'); | 80 scope.context['styleObj'] = {}; |
| 68 expect(element.style.height).toEqual(heightVal); | 81 scope.apply(); |
| 69 }); | 82 expect(element.css(preCompStyle)).not.toEqual('88px'); |
| 70 | 83 expect(element.css(postCompStyle)).not.toEqual('99px'); |
| 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 }); | |
| 82 }); | 84 }); |
| 83 }); | 85 }); |
| 84 } | 86 }); |
| OLD | NEW |