@@ -6,75 +6,143 @@ import 'dart:html' as dom;
6
6
void main () {
7
7
describe ('ngElement' , () {
8
8
9
- it ('should add classes on domWrite to the element' ,
10
- (TestBed _, NgAnimate animate) {
9
+ describe ('classes' , () {
10
+ it ('should add classes to the element on domWrite' ,
11
+ (TestBed _, NgAnimate animate) {
12
+
13
+ var scope = _.rootScope;
14
+ var element = e ('<div></div>' );
15
+ var ngElement = new NgElement (element, scope, animate);
16
+
17
+ ngElement..addClass ('one' )..addClass ('two three' );
18
+
19
+ ['one' , 'two' , 'three' ].forEach ((className) {
20
+ expect (element).not.toHaveClass (className);
21
+ });
22
+
23
+ scope.apply ();
24
+
25
+ ['one' , 'two' , 'three' ].forEach ((className) {
26
+ expect (element).toHaveClass (className);
27
+ });
28
+ });
29
+
30
+ it ('should remove classes from the element on domWrite' ,
31
+ (TestBed _, NgAnimate animate) {
32
+
33
+ var scope = _.rootScope;
34
+ var element = e ('<div class="one two three four"></div>' );
35
+ var ngElement = new NgElement (element, scope, animate);
36
+
37
+ ngElement..removeClass ('one' )
38
+ ..removeClass ('two' )
39
+ ..removeClass ('three' );
40
+
41
+ ['one' , 'two' , 'three' , 'four' ].forEach ((className) {
42
+ expect (element).toHaveClass (className);
43
+ });
44
+
45
+ scope.apply ();
46
+
47
+ ['one' , 'two' , 'three' ].forEach ((className) {
48
+ expect (element).not.toHaveClass (className);
49
+ });
50
+ expect (element).toHaveClass ('four' );
51
+ });
52
+
53
+ it ('should always apply the last dom operation on the given className' ,
54
+ (TestBed _, NgAnimate animate) {
55
+
56
+ var scope = _.rootScope;
57
+ var element = e ('<div></div>' );
58
+ var ngElement = new NgElement (element, scope, animate);
59
+
60
+ ngElement..addClass ('one' )
61
+ ..addClass ('one' )
62
+ ..removeClass ('one' );
63
+
64
+ expect (element).not.toHaveClass ('one' );
65
+
66
+ scope.apply ();
67
+
68
+ expect (element).not.toHaveClass ('one' );
69
+
70
+ ngElement..removeClass ('one' )
71
+ ..removeClass ('one' )
72
+ ..addClass ('one' );
73
+
74
+ scope.apply ();
75
+
76
+ expect (element.classes.contains ('one' )).toBe (true );
77
+ });
78
+ });
79
+ });
80
+
81
+ describe ('attributes' , () {
82
+ it ('should set attributes on domWrite to the element' ,
83
+ (TestBed _, NgAnimate animate) {
11
84
12
85
var scope = _.rootScope;
13
- var element = _. compile ('<div></div>' );
86
+ var element = e ('<div></div>' );
14
87
var ngElement = new NgElement (element, scope, animate);
15
88
16
- ngElement.addClass ( 'one ' );
17
- ngElement.addClass ( 'two three ' );
89
+ ngElement.setAttribute ( 'id' , 'foo ' );
90
+ ngElement.setAttribute ( 'title' , 'bar ' );
18
91
19
- ['one' , 'two' , 'three' ].forEach ((className ) {
20
- expect (element.classes. contains (className)). toBe ( false );
92
+ ['id' , 'title' ].forEach ((name ) {
93
+ expect (element).not. toHaveAttribute (name );
21
94
});
22
95
23
96
scope.apply ();
24
97
25
- ['one' ,'two' ,'three' ].forEach ((className) {
26
- expect (element.classes.contains (className)).toBe (true );
27
- });
98
+ expect (element).toHaveAttribute ('id' , 'foo' );
99
+ expect (element).toHaveAttribute ('title' , 'bar' );
28
100
});
29
101
30
- it ('should remove classes on domWrite to the element' ,
31
- (TestBed _, NgAnimate animate) {
102
+ it ('should remove attributes from the element on domWrite ' ,
103
+ (TestBed _, NgAnimate animate) {
32
104
33
105
var scope = _.rootScope;
34
- var element = _. compile ('<div class="one two three four "></div>' );
106
+ var element = e ('<div id="foo" title="bar "></div>' );
35
107
var ngElement = new NgElement (element, scope, animate);
36
108
37
- ngElement.removeClass ('one' );
38
- ngElement.removeClass ('two' );
39
- ngElement.removeClass ('three' );
109
+ ngElement..removeAttribute ('id' )
110
+ ..removeAttribute ('title' );
40
111
41
- ['one' ,'two' ,'three' ].forEach ((className) {
42
- expect (element.classes.contains (className)).toBe (true );
43
- });
44
- expect (element.classes.contains ('four' )).toBe (true );
112
+ expect (element).toHaveAttribute ('id' , 'foo' );
113
+ expect (element).toHaveAttribute ('title' , 'bar' );
45
114
46
115
scope.apply ();
47
116
48
- ['one' ,'two' ,'three' ].forEach ((className) {
49
- expect (element.classes.contains (className)).toBe (false );
50
- });
51
- expect (element.classes.contains ('four' )).toBe (true );
117
+ expect (element).not.toHaveAttribute ('id' );
118
+ expect (element).not.toHaveAttribute ('title' );
52
119
});
53
120
54
- it ('should always apply the last dom operation on the given className ' ,
55
- (TestBed _, NgAnimate animate) {
121
+ it ('should always apply the last operation on the attribute ' ,
122
+ (TestBed _, NgAnimate animate) {
56
123
57
124
var scope = _.rootScope;
58
- var element = _. compile ('<div></div>' );
125
+ var element = e ('<div></div>' );
59
126
var ngElement = new NgElement (element, scope, animate);
60
127
61
- ngElement.addClass ( 'one' );
62
- ngElement. addClass ( 'one' );
63
- ngElement. removeClass ( 'one ' );
128
+ ngElement.. setAttribute ( 'id' , 'foo' )
129
+ .. setAttribute ( 'id' , 'foo' )
130
+ .. removeAttribute ( 'id ' );
64
131
65
- expect (element.classes. contains ( 'one' )). toBe ( false );
132
+ expect (element).not. toHaveAttribute ( 'id' );
66
133
67
134
scope.apply ();
68
135
69
- expect (element.classes.contains ('one' )).toBe (false );
136
+ expect (element).not.toHaveAttribute ('id' );
137
+
138
+ ngElement..removeAttribute ('id' )
139
+ ..setAttribute ('id' , 'foobar' )
140
+ ..setAttribute ('id' , 'foo' );
70
141
71
- element.classes. add ( 'one' );
142
+ scope. apply ( );
72
143
73
- ngElement.removeClass ('one' );
74
- ngElement.removeClass ('one' );
75
- ngElement.addClass ('one' );
144
+ expect (element).toHaveAttribute ('id' , 'foo' );
76
145
77
- expect (element.classes.contains ('one' )).toBe (true );
78
146
});
79
147
});
80
148
}
0 commit comments