Skip to content

Commit

Permalink
misc: UI Test
Browse files Browse the repository at this point in the history
  • Loading branch information
popoway committed Jan 7, 2024
1 parent 9957e34 commit a60ce56
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 26 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,24 @@ jobs:
# You can specify other versions if desired, see documentation here:
# https://github.com/dart-lang/setup-dart/blob/main/README.md
# - uses: dart-lang/setup-dart@v1
- uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603
- uses: subosito/flutter-action@v1
with:
flutter-version: '3.13.0'
channel: 'stable'

- name: Install dependencies
run: dart pub get
run: flutter pub get

# Uncomment this step to verify the use of 'dart format' on each commit.
# - name: Verify formatting
# run: dart format --output=none --set-exit-if-changed .

# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: Analyze project source
run: dart analyze
run: flutter analyze --no-fatal-warnings

# Your project will need to have tests in test/ and a dependency on
# package:test for this step to succeed. Note that Flutter projects will
# want to change this to 'flutter test'.
- name: Run tests
# run: dart test
run: flutter test
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"Schyler",
"shuttlemap",
"sportscourt",
"Testeable",
"Timesheet"
],
"java.configuration.updateBuildConfiguration": "interactive",
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class MyApp extends StatelessWidget {
},
builder: FlutterI18n.rootAppBuilder(),
home: counter == 0
? const OnboardingPage(title: "Welcome to GoKnights")
? const OnboardingPage()
: const CupertinoTabBarDemo(),
));
}
Expand Down
4 changes: 1 addition & 3 deletions lib/onboarding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:back_button_interceptor/back_button_interceptor.dart';

class OnboardingPage extends StatefulWidget {
const OnboardingPage({super.key, required this.title});

final String title;
const OnboardingPage({super.key});

@override
State<OnboardingPage> createState() => _OnboardingPageState();
Expand Down
5 changes: 2 additions & 3 deletions lib/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,8 @@ class _MyOptionsPageState extends State<MyOptionsPage> {
// need to pop the current page (with nav) to go back to onboarding
Navigator.of(context, rootNavigator: true).push(
CupertinoPageRoute(
builder: (context) => OnboardingPage(
title: FlutterI18n.translate(
context, "onboarding.title")))),
builder: (context) =>
const OnboardingPage())),
},
),
CupertinoListTile.notched(
Expand Down
74 changes: 59 additions & 15 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,70 @@
// 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/cupertino.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:goknights/main.dart';
import 'package:goknights/onboarding.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
group('UI TESTS', () {
Widget makeTesteableWidget({required Widget child}) {
return CupertinoApp(
title: 'GoKnights',
debugShowCheckedModeBanner: false,
localizationsDelegates: [
FlutterI18nDelegate(
translationLoader: FileTranslationLoader(
useCountryCode: false,
fallbackFile: 'en',
basePath: 'assets/flutter_i18n'),
missingTranslationHandler: (key, locale) {
print(
"--- Missing Key: $key, languageCode: ${locale?.languageCode}");
},
),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en', 'US'), // English
Locale('es'), // Spanish
Locale('zh'), // Chinese
Locale('he'), // Hebrew
// Locale('it'), // Italian
// Locale('ru'), // Russian
],
localeListResolutionCallback: (allLocales, supportedLocales) {
final locale = allLocales?.first.languageCode;
if (locale == 'en') {
return const Locale('en', 'US');
}
if (locale == 'es') {
return const Locale('es', 'ES');
}
if (locale == 'zh') {
return const Locale('zh', 'CN');
}
if (locale == 'he') {
return const Locale('he', 'IL');
}
// The default locale
return const Locale('en', 'US');
},
builder: FlutterI18n.rootAppBuilder(),
home: child);
}

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
testWidgets('Onboarding page', (WidgetTester tester) async {
// Create the widget by telling the tester to build it.
final widget = makeTesteableWidget(
child: const OnboardingPage(),
);

// 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);
await tester.pumpWidget(widget);
});
});
}

0 comments on commit a60ce56

Please sign in to comment.