From 5fba4053a6a92d462387a87e838db8f3a93b72f6 Mon Sep 17 00:00:00 2001 From: Christian Findlay <16697547+MelbourneDeveloper@users.noreply.github.com> Date: Thu, 19 Sep 2024 06:51:07 +1000 Subject: [PATCH] Add a unit test back and run in actions --- .github/workflows/build_and_test.yml | 8 +++- .gitignore | 6 +++ .../layout/layout_manager_impl_test.dart | 46 +++++++++++++++++++ test.sh | 6 ++- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 charts_common/test/chart/layout/layout_manager_impl_test.dart diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index e302fb258..cfd6bbd51 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -41,7 +41,13 @@ jobs: cd $GITHUB_WORKSPACE done - - name: Run Tests + - name: Run Common Tests + run: | + cd charts_common + flutter test --coverage + cd $GITHUB_WORKSPACE + + - name: Run UI Tests run: | cd charts_flutter flutter test --coverage diff --git a/.gitignore b/.gitignore index 807ce0030..a2167c8a2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,9 @@ charts_flutter/test/widget_tests/failures/ charts_flutter/test/example_widget_tests/failures/ charts_flutter/test/.DS_Store + +charts_common/coverage/ + +charts_common/.DS_Store + +charts_common/test/chart/.DS_Store diff --git a/charts_common/test/chart/layout/layout_manager_impl_test.dart b/charts_common/test/chart/layout/layout_manager_impl_test.dart new file mode 100644 index 000000000..4ffe3f0df --- /dev/null +++ b/charts_common/test/chart/layout/layout_manager_impl_test.dart @@ -0,0 +1,46 @@ +// Copyright 2018 the Charts project authors. Please see the AUTHORS file +// for details. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import 'package:nimble_charts_common/src/chart/layout/layout_config.dart'; +import 'package:nimble_charts_common/src/chart/layout/layout_manager_impl.dart'; + +import 'package:test/test.dart'; + +void main() { + test('default layout', () { + final layout = LayoutManagerImpl()..measure(400, 300); + + expect(layout.marginTop, equals(0)); + expect(layout.marginRight, equals(0)); + expect(layout.marginBottom, equals(0)); + expect(layout.marginLeft, equals(0)); + }); + + test('all fixed margin', () { + final layout = LayoutManagerImpl( + config: LayoutConfig( + topSpec: MarginSpec.fixedPixel(12), + rightSpec: MarginSpec.fixedPixel(11), + bottomSpec: MarginSpec.fixedPixel(10), + leftSpec: MarginSpec.fixedPixel(9), + ), + )..measure(400, 300); + + expect(layout.marginTop, equals(12)); + expect(layout.marginRight, equals(11)); + expect(layout.marginBottom, equals(10)); + expect(layout.marginLeft, equals(9)); + }); +} diff --git a/test.sh b/test.sh index 97e9cd997..c978fe92a 100644 --- a/test.sh +++ b/test.sh @@ -1,4 +1,8 @@ -cd charts_flutter +cd charts_common + +flutter test --update-goldens --coverage + +cd ../charts_flutter flutter test --update-goldens --coverage