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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional tests from change_detection_integration_test.
Started an additional `container_test.dart` for change detection that has more to do with how change detection is propogated through containers and doesn't fit the patterns in binding_test.dart. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=155661818
- Loading branch information
1 parent
dce8d27
commit fad7626
Showing
2 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
@TestOn('browser') | ||
import 'package:angular2/angular2.dart'; | ||
import 'package:angular_test/angular_test.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
tearDown(disposeAnyRunningTest); | ||
|
||
test('should *not* assign any values if the initial value is null', () async { | ||
final fixture = await new NgTestBed<BoundValueTest>().create(); | ||
await fixture.update(expectAsync1((comp) { | ||
expect(comp.child.updates, 0, reason: 'No changes should have happened'); | ||
expect(comp.child.value, isNull); | ||
})); | ||
}); | ||
|
||
test('should propagate null if the initial value is non-null', () async { | ||
final fixture = await new NgTestBed<BoundValueTest>().create( | ||
beforeChangeDetection: (comp) => comp.boundValue = 'Hello', | ||
); | ||
await fixture.update(expectAsync1((comp) { | ||
expect(comp.child.updates, 1, reason: 'One CD should have happened'); | ||
expect(comp.child.value, 'Hello'); | ||
comp.boundValue = null; | ||
})); | ||
await fixture.update(expectAsync1((comp) { | ||
expect(comp.child.updates, 2, reason: 'Two CDs should have happened'); | ||
expect(comp.child.value, isNull); | ||
})); | ||
}); | ||
|
||
test('should not recreate literal maps unless content changes', () async { | ||
Map boundMap; | ||
final fixture = await new NgTestBed<BoundMapTest>().create( | ||
beforeChangeDetection: (comp) { | ||
comp.value = 'bar'; | ||
}, | ||
); | ||
await fixture.update(expectAsync1((comp) { | ||
boundMap = comp.child.value; | ||
expect(boundMap, {'key': 'bar'}); | ||
})); | ||
await fixture.update(expectAsync1((comp) { | ||
expect(boundMap, same(comp.child.value), reason: 'Should be identical'); | ||
comp.value = 'foo'; | ||
})); | ||
await fixture.update(expectAsync1((comp) { | ||
expect(comp.child.value, {'key': 'foo'}); | ||
})); | ||
}); | ||
|
||
test('should not recreate literal lists unless content changes', () async { | ||
List boundList; | ||
final fixture = await new NgTestBed<BoundListTest>().create( | ||
beforeChangeDetection: (comp) { | ||
comp.value = 'bar'; | ||
}, | ||
); | ||
await fixture.update(expectAsync1((comp) { | ||
boundList = comp.child.value; | ||
expect(boundList, ['bar']); | ||
})); | ||
await fixture.update(expectAsync1((comp) { | ||
expect(boundList, same(comp.child.value), reason: 'Should be identical'); | ||
comp.value = 'foo'; | ||
})); | ||
await fixture.update(expectAsync1((comp) { | ||
expect(comp.child.value, ['foo']); | ||
})); | ||
}); | ||
|
||
test('should support interpolation', () async { | ||
final fixture = await new NgTestBed<BoundValueTest>().create( | ||
beforeChangeDetection: (comp) => comp.boundValue = 'Hello World', | ||
); | ||
expect(fixture.text, 'Hello World'); | ||
}); | ||
|
||
test('should output empty for null values in interpolation', () async { | ||
final fixture = await new NgTestBed<BoundValueTest>().create(); | ||
expect(fixture.text, isEmpty); | ||
}); | ||
} | ||
|
||
@Component( | ||
selector: 'child', | ||
template: r'{{value}}', | ||
) | ||
class ChildComponent { | ||
var _value; | ||
var updates = 0; | ||
|
||
@Input() | ||
set value(value) { | ||
updates++; | ||
_value = value; | ||
} | ||
|
||
get value => _value; | ||
} | ||
|
||
@Component( | ||
selector: 'test', | ||
directives: const [ChildComponent], | ||
template: '<child [value]="boundValue"></child>', | ||
) | ||
class BoundValueTest { | ||
var boundValue; | ||
|
||
@ViewChild(ChildComponent) | ||
ChildComponent child; | ||
} | ||
|
||
@Component( | ||
selector: 'test', | ||
directives: const [ChildComponent], | ||
template: r'''<child [value]="{'key': value}"></child>''', | ||
) | ||
class BoundMapTest { | ||
var value; | ||
|
||
@ViewChild(ChildComponent) | ||
ChildComponent child; | ||
} | ||
|
||
@Component( | ||
selector: 'test', | ||
directives: const [ChildComponent], | ||
template: r'''<child [value]="[value]"></child>''', | ||
) | ||
class BoundListTest { | ||
var value; | ||
|
||
@ViewChild(ChildComponent) | ||
ChildComponent child; | ||
} |