Skip to content

Commit

Permalink
fix: Fixing tests and 100% coverage. #4
Browse files Browse the repository at this point in the history
  • Loading branch information
LuchoTurtle committed May 10, 2023
1 parent 0cd3899 commit 30b01a8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/app_localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class AppLocalization {

// This function will load requested language `.json` file and will assign it to the `_localizedValues` map
Future loadLanguage() async {
String jsonStringValues = await rootBundle.loadString("assets/i18n/${_locale.languageCode}.json");
final path = 'assets/i18n/${_locale.languageCode}.json';
String jsonStringValues = await rootBundle.loadString(path, cache: false);

Map<String, dynamic> mappedValues = json.decode(jsonStringValues);

Expand Down Expand Up @@ -51,6 +52,8 @@ class _AppLocalizationDelegate extends LocalizationsDelegate<AppLocalization> {
return appLocalization;
}

// coverage:ignore-start
@override
bool shouldReload(_AppLocalizationDelegate old) => false;
// coverage:ignore-end
}
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class App extends StatelessWidget {
return deviceLocale;
}
}
// coverage:ignore-start
return supportedLocales.first;
// coverage:ignore-end
},
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
Expand Down
14 changes: 13 additions & 1 deletion test/widget_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:app/app_localization.dart';
import 'package:app/menu.dart';
import 'package:app/pages.dart';
import 'package:app/dynamic_menu.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:app/main.dart';
Expand All @@ -16,13 +19,15 @@ void main() {
testWidgets('Normal setup', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const App());
await tester.pumpAndSettle();

// Verify that our counter starts at 0.
expect(find.text('This is the main page'), findsOneWidget);
});

testWidgets('Tapping on todo item should make menu button appear', (WidgetTester tester) async {
await tester.pumpWidget(const App());
await tester.pumpAndSettle();

final menuButton = find.byKey(iconKey);
final todoItem = find.byKey(todoItemKey);
Expand All @@ -40,6 +45,7 @@ void main() {

testWidgets('Tapping on icon menu should show drawer menu', (WidgetTester tester) async {
await tester.pumpWidget(const App());
await tester.pumpAndSettle();

final menuButton = find.byKey(iconKey);
final todoItem = find.byKey(todoItemKey);
Expand Down Expand Up @@ -71,6 +77,7 @@ void main() {

testWidgets('Navigating into Tours Page', (WidgetTester tester) async {
await tester.pumpWidget(const App());
await tester.pumpAndSettle();

final menuButton = find.byKey(iconKey);
final todoItem = find.byKey(todoItemKey);
Expand Down Expand Up @@ -108,6 +115,7 @@ void main() {

testWidgets('Navigating into Settings Page', (WidgetTester tester) async {
await tester.pumpWidget(const App());
await tester.pumpAndSettle();

final menuButton = find.byKey(iconKey);
final todoItem = find.byKey(todoItemKey);
Expand Down Expand Up @@ -168,6 +176,7 @@ void main() {
testWidgets('Normal setup with shared preferences should show dynamic menu', (WidgetTester tester) async {
// Initialize app
await tester.pumpWidget(const App());
await tester.pumpAndSettle();

final menuButton = find.byKey(iconKey);
final todoItem = find.byKey(todoItemKey);
Expand All @@ -190,6 +199,7 @@ void main() {
testWidgets('Click on first expandable menu item', (WidgetTester tester) async {
// Initialize app
await tester.pumpWidget(const App());
await tester.pumpAndSettle();

final menuButton = find.byKey(iconKey);
final todoItem = find.byKey(todoItemKey);
Expand Down Expand Up @@ -224,6 +234,7 @@ void main() {
testWidgets('Drag and drop nested elements', (WidgetTester tester) async {
// Initialize app
await tester.pumpWidget(const App());
await tester.pumpAndSettle();

final menuButton = find.byKey(iconKey);
final todoItem = find.byKey(todoItemKey);
Expand Down Expand Up @@ -276,12 +287,12 @@ void main() {
});

testWidgets('Drag and drop nested elements on third level', (WidgetTester tester) async {

// To mock the icons fetching images from Network.
// See https://github.com/stelynx/network_image_mock.
mockNetworkImagesFor(() async {
// Initialize app
await tester.pumpWidget(const App());
await tester.pumpAndSettle();

final menuButton = find.byKey(iconKey);
final todoItem = find.byKey(todoItemKey);
Expand Down Expand Up @@ -323,6 +334,7 @@ void main() {
testWidgets('Drag and drop root elements', (WidgetTester tester) async {
// Initialize app
await tester.pumpWidget(const App());
await tester.pumpAndSettle();

final menuButton = find.byKey(iconKey);
final todoItem = find.byKey(todoItemKey);
Expand Down

0 comments on commit 30b01a8

Please sign in to comment.