diff --git a/lib/service/configuration_service.dart b/lib/service/configuration_service.dart index 93b89d7..8ca89ec 100644 --- a/lib/service/configuration_service.dart +++ b/lib/service/configuration_service.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:rules_of_living/service/engine_service.dart'; class ConfigurationService { @@ -26,4 +28,10 @@ class ConfigurationService { void toggleGrid() { showGrid = !showGrid; } -} \ No newline at end of file + + void setGridSize({int x, int y}) { + x = x ?? engineService.engine.gridSize.x; + y = y ?? engineService.engine.gridSize.y; + engineService.engine.gridSize = Point(x, y); + } +} diff --git a/test/service/configuration_service_test.dart b/test/service/configuration_service_test.dart index 1afa50a..f28f6e8 100644 --- a/test/service/configuration_service_test.dart +++ b/test/service/configuration_service_test.dart @@ -1,30 +1,46 @@ +import 'dart:math'; + import 'package:rules_of_living/src/Engine.dart'; @TestOn('browser') - import 'package:test/test.dart'; import 'package:rules_of_living/service/configuration_service.dart'; import 'package:rules_of_living/service/engine_service.dart'; import 'package:mockito/mockito.dart'; class MockEngine extends Mock implements Engine {} -class MockEngineService extends Mock implements EngineService { - MockEngine _engine = MockEngine(); - @override - Engine get engine => _engine; -} void main() { - group("simulation speed", () { - ConfigurationService sut; - MockEngineService mes; - setUp(() { - mes = MockEngineService(); - sut = ConfigurationService(mes); - }); + ConfigurationService sut; + EngineService engineService; + MockEngine me; + setUp(() { + me = MockEngine(); + engineService = EngineService(); + engineService.getEngine(me); + sut = ConfigurationService(engineService); + }); + group("simulation speed", () { test("speed changes propagate to engine", () { sut.simSpeed = 312; - verify(mes.engine.stepsPerSecond=312); + verify(me.stepsPerSecond = 312); + }); + }); + + group("grid size", () { + test("grid changes are sent to engine", () { + sut.setGridSize(x: 512, y: 388); + verify(me.gridSize = Point(512, 388)); + }); + test("grid can be changed solely on x axis", () { + when(me.gridSize).thenReturn(Point(100, 100)); + sut.setGridSize(x: 555); + verify(me.gridSize = Point(555, 100)); + }); + test("grid can be changed solely on y axis", () { + when(me.gridSize).thenReturn(Point(100, 100)); + sut.setGridSize(y: 556); + verify(me.gridSize = Point(100, 556)); }); }); }