This repository has been archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
/
exports_test.dart
234 lines (208 loc) · 7.03 KB
/
exports_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
@TestOn('browser')
import 'package:angular_test/angular_test.dart';
import 'package:test/test.dart';
import 'package:angular/angular.dart';
import 'exports_statics.dart' as lib;
import 'exports_statics.dart';
import 'exports_test.template.dart' as ng_generated;
void main() {
ng_generated.initReflector();
group('exports', () {
tearDown(disposeAnyRunningTest);
group('can interpolate', () {
test('constants', () async {
var testBed = new NgTestBed<InterpolateConstantTest>();
var fixture = await testBed.create();
expect(fixture.text, 'hello');
});
test('static fields', () async {
var testBed = new NgTestBed<InterpolateStaticFieldTest>();
var fixture = await testBed.create();
expect(fixture.text, 'static field');
});
test('enums', () async {
var testBed = new NgTestBed<InterpolateEnumTest>();
var fixture = await testBed.create();
expect(fixture.text, 'MyEnum.a');
});
test('top-level functions', () async {
var testBed = new NgTestBed<InterpolateTopLevelFunctionTest>();
var fixture = await testBed.create();
expect(fixture.text, 'hello!!!');
});
test('static functions', () async {
var testBed = new NgTestBed<InterpolateStaticFunctionTest>();
var fixture = await testBed.create();
expect(fixture.text, 'hello???');
});
});
test('can be used in NgFor', () async {
var testBed = new NgTestBed<StaticNgForTest>();
var fixture = await testBed.create();
expect(fixture.text, '123');
});
test('can be used in event handlers', () async {
var testBed = new NgTestBed<StaticEventHandlerTest>();
var fixture = await testBed.create();
var div = fixture.rootElement.querySelector('div');
clickHandled = false;
await fixture.update((_) {
div.click();
});
expect(clickHandled, true);
});
test('can be assigned in an event handler', () async {
var testBed = new NgTestBed<StaticEventHandlerTargetTest>();
var fixture = await testBed.create();
var div = fixture.rootElement.querySelector('div');
MyClass.clickHandled = false;
await fixture.update((_) {
div.click();
});
expect(MyClass.clickHandled, true);
});
test('can be used as event handler arguments', () async {
var testBed = new NgTestBed<StaticEventHandlerArgTest>();
var fixture = await testBed.create();
var div = fixture.rootElement.querySelector('div');
var listArg;
await fixture.update((StaticEventHandlerArgTest component) {
component.clickHandler = (list) {
listArg = list;
};
div.click();
});
expect(listArg, myList);
});
test('can refer to own statics automatically', () async {
var testBed = new NgTestBed<SelfReferTest>();
var fixture = await testBed.create();
expect(fixture.text, 'hello');
await fixture.update((_) {
SelfReferTest.staticField = 'goodbye';
});
expect(fixture.text, 'goodbye');
});
test('can refer to own statics automatically with @HostBinding', () async {
var testBed = new NgTestBed<SelfReferHostBindingTest>();
var fixture = await testBed.create();
expect(fixture.rootElement.title, 'hello');
await fixture.update((_) {
SelfReferHostBindingTest.staticField = 'goodbye';
});
expect(fixture.rootElement.title, 'goodbye');
});
group('can be prefixed', () {
test('with library prefix', () async {
var testBed = new NgTestBed<StaticLibraryPrefixTest>();
var fixture = await testBed.create();
expect(fixture.text, 'hello');
});
});
});
}
@Component(
selector: 'interpolate-constant-test',
template: '<div>{{myConst}}</div>',
exports: const [myConst],
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class InterpolateConstantTest {}
@Component(
selector: 'interpolate-static-field-test',
template: '<div>{{MyClass.staticField}}</div>',
exports: const [MyClass],
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class InterpolateStaticFieldTest {}
@Component(
selector: 'interpolate-enum-test',
template: '<div>{{MyEnum.a}}</div>',
exports: const [MyEnum],
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class InterpolateEnumTest {}
@Component(
selector: 'interpolate-top-level-function-test',
template: '<div>{{myFunc("hello")}}</div>',
exports: const [myFunc],
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class InterpolateTopLevelFunctionTest {}
@Component(
selector: 'interpolate-static-function-test',
template: '<div>{{MyClass.staticFunc("hello")}}</div>',
exports: const [MyClass],
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class InterpolateStaticFunctionTest {}
@Component(
selector: 'static-ng-for-test',
template: '<div *ngFor="let item of myList">{{item}}</div>',
exports: const [myList],
directives: const [NgFor],
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class StaticNgForTest {}
@Component(
selector: 'static-event-handler-test',
template: '<div (click)="staticClickHandler()"></div>',
exports: const [staticClickHandler],
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class StaticEventHandlerTest {}
@Component(
selector: 'static-event-handler-target-test',
template: '<div (click)="MyClass.clickHandled = true"></div>',
exports: const [MyClass],
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class StaticEventHandlerTargetTest {}
@Component(
selector: 'static-event-handle-arg-test',
template: '<div (click)="handleClick(myList)"></div>',
exports: const [myList],
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class StaticEventHandlerArgTest {
Function clickHandler;
handleClick(List list) {
clickHandler(list);
}
}
@Component(
selector: 'static-library-prefix-test',
template: '<p>{{lib.myConst}}</p>',
exports: const [lib.myConst],
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class StaticLibraryPrefixTest {}
@Component(
selector: 'self-refer-test',
template: '<p>{{SelfReferTest.staticField}}</p>',
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class SelfReferTest {
static String staticField = 'hello';
}
@Component(
selector: 'self-refer-host-binding-test',
template: '',
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
visibility: Visibility.all,
)
class SelfReferHostBindingTest {
@HostBinding('title')
static var staticField = 'hello';
}