| OLD | NEW |
| (Empty) |
| 1 library ng_style_spec; | |
| 2 | |
| 3 import '../_specs.dart'; | |
| 4 import 'dart:html' as dom; | |
| 5 | |
| 6 main() => describe('NgStyle', () { | |
| 7 TestBed _; | |
| 8 | |
| 9 beforeEach(inject((TestBed tb) => _ = tb)); | |
| 10 | |
| 11 it('should set', () { | |
| 12 dom.Element element = _.compile('<div ng-style="{height: \'40px\'}"></div>')
; | |
| 13 _.rootScope.apply(); | |
| 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); | |
| 45 }); | |
| 46 | |
| 47 | |
| 48 it('should not mess up stuff after compilation', () { | |
| 49 element.css('margin', '44px'); | |
| 50 expect(element.css(preCompStyle)).toEqual(preCompVal); | |
| 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'); | |
| 62 }); | |
| 63 | |
| 64 | |
| 65 it(r'should not mess up stuff after $apply with non-colliding model changes'
, () { | |
| 66 scope.context['styleObj'] = {'padding-top': '99px'}; | |
| 67 scope.apply(); | |
| 68 expect(element.css(preCompStyle)).toEqual(preCompVal); | |
| 69 expect(element.css('margin-top')).not.toEqual('44px'); | |
| 70 expect(element.css('padding-top')).toEqual('99px'); | |
| 71 expect(element.css(postCompStyle)).toEqual(postCompVal); | |
| 72 }); | |
| 73 | |
| 74 | |
| 75 it(r'should overwrite original styles after a colliding model change', () { | |
| 76 scope.context['styleObj'] = {'height': '99px', 'width': '88px'}; | |
| 77 scope.apply(); | |
| 78 expect(element.css(preCompStyle)).toEqual('88px'); | |
| 79 expect(element.css(postCompStyle)).toEqual('99px'); | |
| 80 scope.context['styleObj'] = {}; | |
| 81 scope.apply(); | |
| 82 expect(element.css(preCompStyle)).not.toEqual('88px'); | |
| 83 expect(element.css(postCompStyle)).not.toEqual('99px'); | |
| 84 }); | |
| 85 }); | |
| 86 }); | |
| OLD | NEW |