diff --git a/.github/workflows/flutter.yml b/.github/workflows/flutter.yml new file mode 100644 index 0000000..70e0883 --- /dev/null +++ b/.github/workflows/flutter.yml @@ -0,0 +1,36 @@ +name: Flutter + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +defaults: + run: + working-directory: ./api/ui + +jobs: + tests: + name: Build and Test + runs-on: ubuntu-latest + steps: + - name: Set up Flutter + uses: subosito/flutter-action@v2 + with: + channel: 'stable' + - name: Check out the code + uses: actions/checkout@v2 + - run: flutter --version + - name: Restore packages + run: flutter pub get + - name: Analyze + run: flutter analyze + - name: Run tests + run: flutter test --coverage + - name: Coverage report + run: | + sudo apt update -qq + sudo apt install -qq -y lcov + genhtml coverage/lcov.info -o coverage/html + # open coverage/html/index.html diff --git a/api/ui/lib/models/config.dart b/api/ui/lib/models/config.dart index ff994e8..dc1dada 100644 --- a/api/ui/lib/models/config.dart +++ b/api/ui/lib/models/config.dart @@ -1,10 +1,10 @@ enum ConfigProperty { - EnableApi(name: 'user.enableApi'), - IsAdmin(name: 'user.isAdmin'), - Currency(name: 'user.currency'), - VacationTag(name: 'user.vacationTag'), - TimezoneOffset(name: 'user.tzOffset'), - OmitLeadingSlash(name: 'user.omitCommandSlash'); + enableApi(name: 'user.enableApi'), + isAdmin(name: 'user.isAdmin'), + currency(name: 'user.currency'), + vacationTag(name: 'user.vacationTag'), + timezoneOffset(name: 'user.tzOffset'), + omitLeadingSlash(name: 'user.omitCommandSlash'); const ConfigProperty({required this.name}); @@ -25,16 +25,16 @@ class Config { Map diffChanged(Config cnf) { Map diff = {}; if (currency != cnf.currency) { - diff[ConfigProperty.Currency.name] = cnf.currency; + diff[ConfigProperty.currency.name] = cnf.currency; } if (vacationTag != cnf.vacationTag) { - diff[ConfigProperty.VacationTag.name] = cnf.vacationTag; + diff[ConfigProperty.vacationTag.name] = cnf.vacationTag; } if (timezoneOffset != cnf.timezoneOffset) { - diff[ConfigProperty.TimezoneOffset.name] = cnf.timezoneOffset; + diff[ConfigProperty.timezoneOffset.name] = cnf.timezoneOffset; } if (omitLeadingCommandSlash != cnf.omitLeadingCommandSlash) { - diff[ConfigProperty.OmitLeadingSlash.name] = cnf.omitLeadingCommandSlash; + diff[ConfigProperty.omitLeadingSlash.name] = cnf.omitLeadingCommandSlash; } return diff; } diff --git a/api/ui/lib/models/constants.dart b/api/ui/lib/models/constants.dart index ccec45c..d284c33 100644 --- a/api/ui/lib/models/constants.dart +++ b/api/ui/lib/models/constants.dart @@ -1,4 +1,4 @@ -final KeyToken = 'TOKEN'; +const keyToken = 'TOKEN'; enum Routes { root(route: '/'), diff --git a/api/ui/lib/screens/home/suggestions.dart b/api/ui/lib/screens/home/suggestions.dart index 3bb90ca..f562348 100644 --- a/api/ui/lib/screens/home/suggestions.dart +++ b/api/ui/lib/screens/home/suggestions.dart @@ -56,10 +56,10 @@ class _SuggestionsWidgetState extends State { return const Text( 'Currently, there are no suggestions to display.'); } - List suggList = []; + List suggestionsList = []; for (var s in suggestions.entries) { for (var v in s.value) { - suggList.add(SuggestionWidget( + suggestionsList.add(SuggestionWidget( type: s.key, suggestion: v, fnRm: _deleteSuggestion, @@ -85,7 +85,7 @@ class _SuggestionsWidgetState extends State { // wireframe for each widget. mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, - children: suggList, + children: suggestionsList, ))); } } diff --git a/api/ui/lib/screens/login.dart b/api/ui/lib/screens/login.dart index 03737b1..609597d 100644 --- a/api/ui/lib/screens/login.dart +++ b/api/ui/lib/screens/login.dart @@ -86,7 +86,7 @@ class _LoginState extends State { backgroundColor: Theme.of(context).colorScheme.inversePrimary, // Here we take the value from the MyHomePage object that was created by // the App.build method, and use it to set our appbar title. - title: Text('Beancount-Bot-Tg Login' /*widget.title*/), + title: const Text('Beancount-Bot-Tg Login' /*widget.title*/), ), body: Center( // Center is a layout widget. It takes a single child and positions it diff --git a/api/ui/lib/service/api.dart b/api/ui/lib/service/api.dart index f829237..1f69fa0 100644 --- a/api/ui/lib/service/api.dart +++ b/api/ui/lib/service/api.dart @@ -81,12 +81,12 @@ class ClientAuthentication extends BaseCrud { static storeToken(String token) async { SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setString(KeyToken, token); + prefs.setString(keyToken, token); } static Future loadToken() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - return prefs.getString(KeyToken); + return prefs.getString(keyToken); } Future<(Config? config, String? errorMsg)> getConfig() async { diff --git a/api/ui/test/widget_test.dart b/api/ui/test/widget_test.dart index a44b7d2..b21364f 100644 --- a/api/ui/test/widget_test.dart +++ b/api/ui/test/widget_test.dart @@ -5,26 +5,13 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:ui/main.dart'; void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { + testWidgets('Run app', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); }); }