Skip to content

Commit

Permalink
Add Flutter GitHub Actions workflow
Browse files Browse the repository at this point in the history
Refactor and fix linting
Fix stub tests
  • Loading branch information
LucaBernstein committed May 25, 2023
1 parent f92492d commit 10abea7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 31 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 10 additions & 10 deletions api/ui/lib/models/config.dart
Original file line number Diff line number Diff line change
@@ -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});

Expand All @@ -25,16 +25,16 @@ class Config {
Map<String, dynamic> diffChanged(Config cnf) {
Map<String, dynamic> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion api/ui/lib/models/constants.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
final KeyToken = 'TOKEN';
const keyToken = 'TOKEN';

enum Routes {
root(route: '/'),
Expand Down
6 changes: 3 additions & 3 deletions api/ui/lib/screens/home/suggestions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class _SuggestionsWidgetState extends State<SuggestionsWidget> {
return const Text(
'Currently, there are no suggestions to display.');
}
List<Widget> suggList = [];
List<Widget> 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,
Expand All @@ -85,7 +85,7 @@ class _SuggestionsWidgetState extends State<SuggestionsWidget> {
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: suggList,
children: suggestionsList,
)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/ui/lib/screens/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class _LoginState extends State<LoginPage> {
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
Expand Down
4 changes: 2 additions & 2 deletions api/ui/lib/service/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?> loadToken() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(KeyToken);
return prefs.getString(keyToken);
}

Future<(Config? config, String? errorMsg)> getConfig() async {
Expand Down
15 changes: 1 addition & 14 deletions api/ui/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

0 comments on commit 10abea7

Please sign in to comment.