Enable cached engine returns for EngineService
This commit is contained in:
parent
66bf87d9d8
commit
cc33628e5f
2 changed files with 23 additions and 2 deletions
|
@ -5,13 +5,15 @@ import 'package:rules_of_living/src/Engine.dart';
|
||||||
class EngineService {
|
class EngineService {
|
||||||
Engine _engine;
|
Engine _engine;
|
||||||
|
|
||||||
Engine get engine => _engine ?? create(null);
|
Engine get engine => _engine ?? createEngine(null);
|
||||||
|
|
||||||
Engine create(html.CanvasElement canvas) {
|
Engine createEngine(html.CanvasElement canvas) {
|
||||||
_engine = Engine(canvas);
|
_engine = Engine(canvas);
|
||||||
return _engine;
|
return _engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setCanvas(html.CanvasElement canvas) => engine.canvas = canvas;
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
engine.running = true;
|
engine.running = true;
|
||||||
}
|
}
|
||||||
|
|
19
test/service/engine_service_test.dart
Normal file
19
test/service/engine_service_test.dart
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
@TestOn('browser')
|
||||||
|
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
import 'package:rules_of_living/service/engine_service.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
EngineService sut;
|
||||||
|
setUp(() {
|
||||||
|
sut = EngineService();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EngineService creates an engine on demand", () {
|
||||||
|
expect(sut.engine, isNotNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EngineService returns the cached engine on subsequent requests", () {
|
||||||
|
expect(sut.engine, allOf(isNotNull, equals(sut.engine)));
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue