From cc33628e5fd81e0702a48ecb20677b97adb3ae58 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 25 Aug 2018 14:51:28 +0200 Subject: [PATCH] Enable cached engine returns for EngineService --- lib/service/engine_service.dart | 6 ++++-- test/service/engine_service_test.dart | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/service/engine_service_test.dart diff --git a/lib/service/engine_service.dart b/lib/service/engine_service.dart index f6c7304..69f4699 100644 --- a/lib/service/engine_service.dart +++ b/lib/service/engine_service.dart @@ -5,13 +5,15 @@ import 'package:rules_of_living/src/Engine.dart'; class EngineService { 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); return _engine; } + void setCanvas(html.CanvasElement canvas) => engine.canvas = canvas; + void run() { engine.running = true; } diff --git a/test/service/engine_service_test.dart b/test/service/engine_service_test.dart new file mode 100644 index 0000000..9d4a226 --- /dev/null +++ b/test/service/engine_service_test.dart @@ -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))); + }); +}