Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.

Commit 4fe988f

Browse files
matanlureyalorenzen
authored andcommitted
refactor(Goldens): Remove a partially failing test case (from #908).
After further investigation, there is some regression in resolving types from the angular_forms library from within the _goldens library, but only internally for the golden file generator ... woo, a mouth-full. It makes sense to just trim this specific case out, since we have coverage of the type inference feature in other test cases, and not worry about trying to resolve another package from within the golden files. [After speaking to multiple members of the analyzer team, it seems like both order, types (summaries versus source files), and other very subtle things could cause this, and since we are on the deprecated AnalysisContext for builders anyway, it doesn't make sense to focus on this specific case.] ... also refactor that golden file, while we are at it! PiperOrigin-RevId: 186656275
1 parent 1f87b51 commit 4fe988f

10 files changed

+27
-413
lines changed

_goldens/test/_files/directives/directive_wrapper.dart

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'dart:async';
22
import 'dart:html';
33
import 'package:angular/angular.dart';
4-
import 'package:angular_forms/angular_forms.dart';
54

65
@Directive(
76
selector: '[some-child-directive]',
@@ -14,8 +13,6 @@ import 'package:angular_forms/angular_forms.dart';
1413
'[attr.aria-disabled]': 'disabledStr',
1514
'[class.is-disabled]': 'disabled',
1615
},
17-
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
18-
visibility: Visibility.all,
1916
)
2017
class ChildDirective {
2118
Element element;
@@ -51,8 +48,6 @@ class ChildDirective {
5148

5249
@Directive(
5350
selector: '[directive-with-output]',
54-
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
55-
visibility: Visibility.all,
5651
)
5752
class DirectiveWithOutput {
5853
String msg;
@@ -68,12 +63,13 @@ class DirectiveWithOutput {
6863

6964
@Component(
7065
selector: 'test-foo',
71-
template:
72-
'<div some-child-directive directive-with-output [row]="rowIndex" (trigger)="onTrigger">Foo</div>',
66+
template: r'''
67+
<div some-child-directive directive-with-output [row]="rowIndex" (trigger)="onTrigger">
68+
Foo
69+
</div>
70+
''',
7371
directives: const [ChildDirective, DirectiveWithOutput],
7472
styles: const ['div { font-size: 10px; }'],
75-
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
76-
visibility: Visibility.all,
7773
)
7874
class TestFooComponent {
7975
int get rowIndex => 5;
@@ -85,20 +81,6 @@ class MyInjectableClass {
8581
String get title => 'hello';
8682
}
8783

88-
@Component(
89-
selector: 'input-form-test',
90-
directives: const [formDirectives],
91-
template: '''
92-
<div [ngFormModel]="form">
93-
<input type="text" ngControl="login">
94-
</div>''',
95-
// TODO(b/71710685): Change to `Visibility.local` to reduce code size.
96-
visibility: Visibility.all,
97-
)
98-
class InputFormTest {
99-
ControlGroup form;
100-
}
101-
10284
@Directive(
10385
host: const {'[attr.data-msg]': 'msg'},
10486
selector: '[fastDirective]',
@@ -120,8 +102,10 @@ class FastDirective extends ComponentState {
120102

121103
@Component(
122104
selector: 'directive-container',
123-
template: r'<div class="target1" fastDirective [name]="finalName"></div>'
124-
'<div class="target2" fastDirective [name]="nonFinal"></div>',
105+
template: r'''
106+
<div class="target1" fastDirective [name]="finalName"></div>
107+
<div class="target2" fastDirective [name]="nonFinal"></div>
108+
''',
125109
directives: const [FastDirective],
126110
)
127111
class DirectiveContainerTest {

_goldens/test/_files/directives/directive_wrapper.template_debug.golden

Lines changed: 10 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ export 'directive_wrapper.dart';
88
import 'dart:async';
99
import 'dart:html';
1010
import 'package:angular/angular.dart';
11-
import 'package:angular_forms/angular_forms.dart';
1211
import 'package:angular/src/di/reflector.dart' as _ngRef;
1312
import 'package:angular/angular.template.dart' as _ref0;
14-
import 'package:angular_forms/angular_forms.template.dart' as _ref1;
1513
import 'package:angular/src/debug/debug_context.dart';
1614
import 'directive_wrapper.dart' as import1;
1715
import 'package:angular/src/debug/debug_app_view.dart';
@@ -23,14 +21,7 @@ import 'package:angular/src/core/change_detection/change_detection.dart';
2321
import 'package:angular/src/core/linker/app_view_utils.dart' as import8;
2422
import 'package:angular/angular.dart';
2523
import 'package:angular/src/core/linker/element_ref.dart';
26-
import 'package:angular_forms/src/directives/ng_form_model.dart' as import11;
27-
import 'package:angular_forms/src/directives/control_container.dart' as import12;
28-
import 'package:angular_forms/src/directives/default_value_accessor.dart' as import13;
29-
import 'package:angular/src/core/di/opaque_token.dart' as import14;
30-
import 'package:angular_forms/src/directives/control_value_accessor.dart' as import15;
31-
import 'package:angular_forms/src/directives/ng_control_name.dart' as import16;
32-
import 'package:angular_forms/src/directives/ng_control.dart' as import17;
33-
import 'package:angular/src/core/change_detection/directive_change_detector.dart' as import18;
24+
import 'package:angular/src/core/change_detection/directive_change_detector.dart' as import11;
3425

3526
const List<dynamic> styles$TestFooComponent = const ['div._ngcontent-%COMP% { font-size:10px; }'];
3627
List<StaticNodeDebugInfo> nodeDebugInfos_TestFooComponent0 = [
@@ -53,7 +44,7 @@ class ViewTestFooComponent0 extends DebugAppView<import1.TestFooComponent> {
5344
ComponentRef<import1.TestFooComponent> build() {
5445
final import3.HtmlElement parentRenderNode = initViewRoot(rootEl);
5546
var doc = import3.document;
56-
_el_0 = createDivAndAppendDbg(this, doc, parentRenderNode, 0, 0, 0);
47+
_el_0 = createDivAndAppendDbg(this, doc, parentRenderNode, 0, 0, 4);
5748
createAttr(_el_0, 'directive-with-output', '');
5849
createAttr(_el_0, 'role', 'button');
5950
createAttr(_el_0, 'some-child-directive', '');
@@ -62,7 +53,7 @@ class ViewTestFooComponent0 extends DebugAppView<import1.TestFooComponent> {
6253
_DirectiveWithOutput_0_5 = new import1.DirectiveWithOutput();
6354
import3.Text _text_1 = new import3.Text('Foo');
6455
_el_0.append(_text_1);
65-
dbgElm(this, _text_1, 1, 0, 87);
56+
dbgElm(this, _text_1, 1, 0, 91);
6657
_el_0.addEventListener('click', eventHandler1(_ChildDirective_0_4.instance.handleClick));
6758
_el_0.addEventListener('keypress', eventHandler1(_ChildDirective_0_4.instance.handleKeyPress));
6859
final subscription_0 = _ChildDirective_0_4.instance.trigger.listen(eventHandler1(_handle_trigger_0_0));
@@ -71,21 +62,10 @@ class ViewTestFooComponent0 extends DebugAppView<import1.TestFooComponent> {
7162
return null;
7263
}
7364

74-
@override
75-
dynamic injectorGetInternal(dynamic token, int nodeIndex, dynamic notFoundResult) {
76-
if ((identical(token, import1.ChildDirective) && ((0 <= nodeIndex) && (nodeIndex <= 1)))) {
77-
return _ChildDirective_0_4.instance;
78-
}
79-
if ((identical(token, import1.DirectiveWithOutput) && ((0 <= nodeIndex) && (nodeIndex <= 1)))) {
80-
return _DirectiveWithOutput_0_5;
81-
}
82-
return notFoundResult;
83-
}
84-
8565
@override
8666
void detectChangesInternal() {
8767
final import1.TestFooComponent _ctx = ctx;
88-
dbg(0, 0, 48);
68+
dbg(0, 0, 52);
8969
final currVal_0 = _ctx.rowIndex;
9070
if (import8.checkBinding(_expr_0, currVal_0)) {
9171
_ChildDirective_0_4.instance.gridRow = currVal_0;
@@ -95,7 +75,7 @@ class ViewTestFooComponent0 extends DebugAppView<import1.TestFooComponent> {
9575
}
9676

9777
void _handle_trigger_0_0($event) {
98-
dbg(0, 0, 65);
78+
dbg(0, 0, 69);
9979
ctx.onTrigger;
10080
}
10181
}
@@ -124,14 +104,6 @@ class _ViewTestFooComponentHost0 extends DebugAppView<dynamic> {
124104
return new ComponentRef<import1.TestFooComponent>(0, this, rootEl, _TestFooComponent_0_4);
125105
}
126106

127-
@override
128-
dynamic injectorGetInternal(dynamic token, int nodeIndex, dynamic notFoundResult) {
129-
if ((identical(token, import1.TestFooComponent) && (0 == nodeIndex))) {
130-
return _TestFooComponent_0_4;
131-
}
132-
return notFoundResult;
133-
}
134-
135107
@override
136108
void detectChangesInternal() {
137109
_compView_0.detectChanges();
@@ -148,153 +120,6 @@ AppView viewFactory_TestFooComponentHost0(AppView<dynamic> parentView, num paren
148120
}
149121

150122
const ComponentFactory<import1.TestFooComponent> TestFooComponentNgFactory = const ComponentFactory<import1.TestFooComponent>('test-foo', viewFactory_TestFooComponentHost0, _TestFooComponentMetadata);
151-
const List<dynamic> styles$InputFormTest = const [];
152-
List<StaticNodeDebugInfo> nodeDebugInfos_InputFormTest0 = [
153-
new StaticNodeDebugInfo([import11.NgFormModel, import12.ControlContainer], null, <String, dynamic>{}),
154-
new StaticNodeDebugInfo([import13.DefaultValueAccessor, const import14.MultiToken<import15.ControlValueAccessor<dynamic>>('NgValueAccessor'), import16.NgControlName, import17.NgControl], null, <String, dynamic>{})
155-
];
156-
157-
class ViewInputFormTest0 extends DebugAppView<import1.InputFormTest> {
158-
import3.DivElement _el_0;
159-
import11.NgFormModel _NgFormModel_0_4;
160-
dynamic _ControlContainer_0_5;
161-
import3.InputElement _el_1;
162-
import13.DefaultValueAccessor _DefaultValueAccessor_1_4;
163-
List<import15.ControlValueAccessor> _NgValueAccessor_1_5;
164-
import16.NgControlName _NgControlName_1_6;
165-
var _expr_0;
166-
static RenderComponentType _renderType;
167-
ViewInputFormTest0(AppView<dynamic> parentView, num parentIndex) : super(import6.ViewType.COMPONENT, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways, nodeDebugInfos_InputFormTest0) {
168-
rootEl = import3.document.createElement('input-form-test');
169-
_renderType ??= import8.appViewUtils.createRenderType('asset:_goldens/test/_files/directives/directive_wrapper.dart class InputFormTest - inline template', ViewEncapsulation.None, styles$InputFormTest);
170-
setupComponentType(_renderType);
171-
}
172-
@override
173-
ComponentRef<import1.InputFormTest> build() {
174-
final import3.HtmlElement parentRenderNode = initViewRoot(rootEl);
175-
var doc = import3.document;
176-
_el_0 = createDivAndAppendDbg(this, doc, parentRenderNode, 0, 0, 0);
177-
_NgFormModel_0_4 = new import11.NgFormModel(null);
178-
_ControlContainer_0_5 = _NgFormModel_0_4;
179-
_el_1 = createAndAppendDbg(this, doc, 'input', _el_0, 1, 1, 2);
180-
createAttr(_el_1, 'ngControl', 'login');
181-
createAttr(_el_1, 'type', 'text');
182-
_DefaultValueAccessor_1_4 = new import13.DefaultValueAccessor(_el_1);
183-
_NgValueAccessor_1_5 = [_DefaultValueAccessor_1_4];
184-
_NgControlName_1_6 = new import16.NgControlName(_ControlContainer_0_5, null, _NgValueAccessor_1_5);
185-
import8.appViewUtils.eventManager.addEventListener(_el_0, 'submit', eventHandler1(_NgFormModel_0_4.onSubmit));
186-
_el_1.addEventListener('input', eventHandler1(_handle_input_1_0));
187-
_el_1.addEventListener('blur', eventHandler0(_DefaultValueAccessor_1_4.touchHandler));
188-
init(const [], null, [_el_0, _el_1]);
189-
return null;
190-
}
191-
192-
@override
193-
dynamic injectorGetInternal(dynamic token, int nodeIndex, dynamic notFoundResult) {
194-
if ((identical(token, import13.DefaultValueAccessor) && (1 == nodeIndex))) {
195-
return _DefaultValueAccessor_1_4;
196-
}
197-
if ((identical(token, const import14.MultiToken<import15.ControlValueAccessor<dynamic>>('NgValueAccessor')) && (1 == nodeIndex))) {
198-
return _NgValueAccessor_1_5;
199-
}
200-
if (((identical(token, import16.NgControlName) || identical(token, import17.NgControl)) && (1 == nodeIndex))) {
201-
return _NgControlName_1_6;
202-
}
203-
if ((identical(token, import11.NgFormModel) && ((0 <= nodeIndex) && (nodeIndex <= 1)))) {
204-
return _NgFormModel_0_4;
205-
}
206-
if ((identical(token, import12.ControlContainer) && ((0 <= nodeIndex) && (nodeIndex <= 1)))) {
207-
return _ControlContainer_0_5;
208-
}
209-
return notFoundResult;
210-
}
211-
212-
@override
213-
void detectChangesInternal() {
214-
final import1.InputFormTest _ctx = ctx;
215-
bool changed = false;
216-
bool firstCheck = (this.cdState == 0);
217-
changed = false;
218-
dbg(0, 0, 5);
219-
final currVal_0 = _ctx.form;
220-
if (import8.checkBinding(_expr_0, currVal_0)) {
221-
_NgFormModel_0_4.form = currVal_0;
222-
changed = true;
223-
_expr_0 = currVal_0;
224-
}
225-
if (changed) {
226-
_NgFormModel_0_4.ngAfterChanges();
227-
}
228-
changed = false;
229-
if (firstCheck) {
230-
_NgControlName_1_6.name = 'login';
231-
changed = true;
232-
}
233-
if (changed) {
234-
_NgControlName_1_6.ngAfterChanges();
235-
}
236-
}
237-
238-
@override
239-
void destroyInternal() {
240-
dbg(1, 1, 2);
241-
_NgControlName_1_6.ngOnDestroy();
242-
}
243-
244-
void _handle_input_1_0($event) {
245-
dbg(1, 1, 2);
246-
_DefaultValueAccessor_1_4.onChange($event.target.value);
247-
}
248-
}
249-
250-
AppView<import1.InputFormTest> viewFactory_InputFormTest0(AppView<dynamic> parentView, num parentIndex) {
251-
return new ViewInputFormTest0(parentView, parentIndex);
252-
}
253-
254-
const List<dynamic> styles$InputFormTestHost = const [];
255-
List<StaticNodeDebugInfo> nodeDebugInfos_InputFormTestHost0 = [
256-
new StaticNodeDebugInfo([import1.InputFormTest], import1.InputFormTest, <String, dynamic>{})
257-
];
258-
259-
class _ViewInputFormTestHost0 extends DebugAppView<dynamic> {
260-
ViewInputFormTest0 _compView_0;
261-
import1.InputFormTest _InputFormTest_0_4;
262-
_ViewInputFormTestHost0(AppView<dynamic> parentView, num parentIndex) : super(import6.ViewType.HOST, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways, nodeDebugInfos_InputFormTestHost0);
263-
@override
264-
ComponentRef build() {
265-
_compView_0 = new ViewInputFormTest0(this, 0);
266-
rootEl = _compView_0.rootEl;
267-
dbgIdx(rootEl, 0);
268-
_InputFormTest_0_4 = new import1.InputFormTest();
269-
_compView_0.create(_InputFormTest_0_4, projectableNodes);
270-
init0Dbg(rootEl, [rootEl]);
271-
return new ComponentRef<import1.InputFormTest>(0, this, rootEl, _InputFormTest_0_4);
272-
}
273-
274-
@override
275-
dynamic injectorGetInternal(dynamic token, int nodeIndex, dynamic notFoundResult) {
276-
if ((identical(token, import1.InputFormTest) && (0 == nodeIndex))) {
277-
return _InputFormTest_0_4;
278-
}
279-
return notFoundResult;
280-
}
281-
282-
@override
283-
void detectChangesInternal() {
284-
_compView_0.detectChanges();
285-
}
286-
287-
@override
288-
void destroyInternal() {
289-
_compView_0?.destroy();
290-
}
291-
}
292-
293-
AppView viewFactory_InputFormTestHost0(AppView<dynamic> parentView, num parentIndex) {
294-
return new _ViewInputFormTestHost0(parentView, parentIndex);
295-
}
296-
297-
const ComponentFactory<import1.InputFormTest> InputFormTestNgFactory = const ComponentFactory<import1.InputFormTest>('input-form-test', viewFactory_InputFormTestHost0, _InputFormTestMetadata);
298123
const List<dynamic> styles$DirectiveContainerTest = const [];
299124
List<StaticNodeDebugInfo> nodeDebugInfos_DirectiveContainerTest0 = [
300125
new StaticNodeDebugInfo([import1.FastDirective], null, <String, dynamic>{}),
@@ -316,11 +141,11 @@ class ViewDirectiveContainerTest0 extends DebugAppView<import1.DirectiveContaine
316141
ComponentRef<import1.DirectiveContainerTest> build() {
317142
final import3.HtmlElement parentRenderNode = initViewRoot(rootEl);
318143
var doc = import3.document;
319-
_el_0 = createDivAndAppendDbg(this, doc, parentRenderNode, 0, 0, 0);
144+
_el_0 = createDivAndAppendDbg(this, doc, parentRenderNode, 0, 0, 4);
320145
_el_0.className = 'target1';
321146
createAttr(_el_0, 'fastDirective', '');
322147
_FastDirective_0_4 = new FastDirectiveNgCd(new import1.FastDirective(_el_0), this, _el_0);
323-
_el_1 = createDivAndAppendDbg(this, doc, parentRenderNode, 1, 0, 60);
148+
_el_1 = createDivAndAppendDbg(this, doc, parentRenderNode, 1, 1, 4);
324149
_el_1.className = 'target2';
325150
createAttr(_el_1, 'fastDirective', '');
326151
_FastDirective_1_4 = new FastDirectiveNgCd(new import1.FastDirective(_el_1), this, _el_1);
@@ -335,7 +160,7 @@ class ViewDirectiveContainerTest0 extends DebugAppView<import1.DirectiveContaine
335160
if (firstCheck) {
336161
(_FastDirective_0_4.instance.name = _ctx.finalName);
337162
}
338-
dbg(1, 0, 95);
163+
dbg(1, 1, 39);
339164
_FastDirective_1_4.instance.name = _ctx.nonFinal;
340165
}
341166
}
@@ -381,7 +206,7 @@ AppView viewFactory_DirectiveContainerTestHost0(AppView<dynamic> parentView, num
381206

382207
const ComponentFactory<import1.DirectiveContainerTest> DirectiveContainerTestNgFactory = const ComponentFactory<import1.DirectiveContainerTest>('directive-container', viewFactory_DirectiveContainerTestHost0, _DirectiveContainerTestMetadata);
383208

384-
class ChildDirectiveNgCd extends import18.DirectiveChangeDetector {
209+
class ChildDirectiveNgCd extends import11.DirectiveChangeDetector {
385210
final import1.ChildDirective instance;
386211
var _expr_0;
387212
var _expr_1;
@@ -406,7 +231,7 @@ class ChildDirectiveNgCd extends import18.DirectiveChangeDetector {
406231
}
407232
}
408233

409-
class FastDirectiveNgCd extends import18.DirectiveChangeDetector {
234+
class FastDirectiveNgCd extends import11.DirectiveChangeDetector {
410235
final import1.FastDirective instance;
411236
var _expr_0;
412237
FastDirectiveNgCd(this.instance, AppView v, import3.Element e) {
@@ -425,7 +250,6 @@ class FastDirectiveNgCd extends import18.DirectiveChangeDetector {
425250
}
426251

427252
const _TestFooComponentMetadata = const [];
428-
const _InputFormTestMetadata = const [];
429253
const _DirectiveContainerTestMetadata = const [];
430254
var _visited = false;
431255
void initReflector() {
@@ -436,8 +260,6 @@ void initReflector() {
436260

437261
_ngRef.registerComponent(TestFooComponent, TestFooComponentNgFactory);
438262
_ngRef.registerFactory(MyInjectableClass, () => new MyInjectableClass());
439-
_ngRef.registerComponent(InputFormTest, InputFormTestNgFactory);
440263
_ngRef.registerComponent(DirectiveContainerTest, DirectiveContainerTestNgFactory);
441264
_ref0.initReflector();
442-
_ref1.initReflector();
443265
}

0 commit comments

Comments
 (0)