forked from flame-engine/flame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresizable_test.dart
54 lines (42 loc) · 1.23 KB
/
resizable_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
import 'dart:ui';
import 'package:test/test.dart';
import 'package:flame/game.dart';
import 'package:flame/components/component.dart';
import 'package:flame/components/mixins/resizable.dart';
class MyComponent extends PositionComponent with Resizable {
String name;
List<MyComponent> myChildren;
MyComponent(this.name, {this.myChildren = const []});
@override
Iterable<Resizable> resizableChildren() => myChildren;
@override
void update(double dt) {}
@override
void render(Canvas c) {}
}
class MyGame extends BaseGame {}
Size size = const Size(1.0, 1.0);
void main() {
group('resizable test', () {
test('propagate resize to children', () {
final MyComponent a = MyComponent('a');
final MyComponent b = MyComponent('b', myChildren: [a]);
b.resize(size);
expect(a.size, size);
});
test('game calls resize on add', () {
final MyComponent a = MyComponent('a');
final MyGame game = MyGame();
game.resize(size);
game.add(a);
expect(a.size, size);
});
test('game calls resize after added', () {
final MyComponent a = MyComponent('a');
final MyGame game = MyGame();
game.add(a);
game.resize(size);
expect(a.size, size);
});
});
}