Skip to content

Convenient test #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: final
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@
],
"program": "lib/main_dev.dart"
},
{
"name": "convenient_test_android",
"request": "launch",
"type": "dart",
"codeLens": {
"for": [
"run-file",
"debug-file"
],
"path": "conv_test",
"title": "${debugType} Conv Test"
},
"args": [
"--flavor",
"dev",
"--disable-service-auth-codes",
"--dart-define",
"CONVENIENT_TEST_MANAGER_HOST=10.0.2.2",
"--dart-define",
"CONVENIENT_TEST_APP_CODE_DIR=lib/main_dev.dart -d 'emulator-5554'",
],
"vmAdditionalArgs": [
"--host-vmservice-port=9753",
],
"program": "conv_test/main_test.dart",
},
{
"name": "dev Profile",
"request": "launch",
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ run-stage-profile:
run-prod-profile:
flutter run --profile --flavor prod -t lib/main_prod.dart

# Convinient Test Android
test-convenient-android:
flutter run conv_test/main_test.dart --flavor dev --host-vmservice-port 9753 --disable-service-auth-codes --dart-define CONVENIENT_TEST_MANAGER_HOST=10.0.2.2 --dart-define CONVENIENT_TEST_APP_CODE_DIR=$PWD -d "emulator-5554"

# Release Builds
run-dev-release:
flutter run --release --flavor dev -t lib/main_dev.dart
Expand Down
77 changes: 77 additions & 0 deletions conv_test/main_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import 'package:convenient_test_dev/convenient_test_dev.dart';
import 'package:convenient_test_dev/src/support/get_it.dart';
import 'package:counter_workshop/main.dart' as main_app;
import 'package:counter_workshop/src/core/routing/router.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';

void main() {
convenientTestMain(MyConvenientTestSlot(), () {
group('add überstunden', () {
tTestWidgets('Open Überstunden', (t) async {
await find.text('Überstunden').should(findsOneWidget);
await find.text('Überstunden').tap();
await t.get('counter_text_Überstunden').should(findsOneWidget);
await find.byIcon(Icons.add).should(findsOneWidget);
await find.byIcon(Icons.add).tap();
await find.byIcon(Icons.add).tap();
await find.byIcon(Icons.add).tap();
await find.textContaining('24').should(findsOneWidget);
await t.pageBack();
await find.text('Überstunden').should(findsOneWidget);
await find.textContaining('24').should(findsOneWidget);
});
});

group('open settings', () {
tTestWidgets('Open Settings Check English', (t) async {
await find.byIcon(Icons.settings).should(findsOneWidget);
await find.byIcon(Icons.settings).tap();
await find.text('German').should(findsOneWidget);
await find.text('German').tap();
await find.text('Deutsch').should(findsOneWidget);
await find.text('German').should(findsNothing);
});
});

group('open add dialog', () {
tTestWidgets('should open page', (t) async {
await t.goRouteCommand('counters');
await find.byIcon(Icons.add).should(findsOneWidget);
await find.byIcon(Icons.add).tap();
});
});

group('my custom test group', () {
tTestWidgets('calling custom method', (t) async {
await t.myCustomCommand();
});
});
});
}

class MyConvenientTestSlot extends ConvenientTestSlot {
@override
Future<void> appMain(AppMainExecuteMode mode) async => main_app.main();

@override
BuildContext? getNavContext(ConvenientTest t) {
return router.routerDelegate.navigatorKey.currentContext!;
}
}

extension on ConvenientTest {
Future<void> myCustomCommand() async {
// Do anything you like... This is just a normal function
debugPrint('Hello, world!');
}

Future<void> goRouteCommand(name) async {
await pump();
// If await, will wait forever until the page is popped - surely we do not want that
// ignore: use_build_context_synchronously
myGetIt.get<ConvenientTestSlot>().getNavContext(this)!.goNamed(name);
await pumpAndSettle();
}
}
27 changes: 15 additions & 12 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:convenient_test/convenient_test.dart';
import 'package:counter_workshop/flavors.dart';
import 'package:counter_workshop/src/core/routing/router.dart';
import 'package:counter_workshop/src/core/theme/app.theme.dart';
Expand Down Expand Up @@ -67,18 +68,20 @@ class AppView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final appTheme = AppTheme();
return MaterialApp.router(
title: F.title,
locale: locale,
theme: appTheme.light,
darkTheme: appTheme.dark,
themeMode: ThemeMode.system,
debugShowCheckedModeBanner: false,
routeInformationProvider: router.routeInformationProvider,
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
return ConvenientTestWrapperWidget(
child: MaterialApp.router(
title: F.title,
locale: locale,
theme: appTheme.light,
darkTheme: appTheme.dark,
themeMode: ThemeMode.system,
debugShowCheckedModeBanner: false,
routeInformationProvider: router.routeInformationProvider,
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
),
);
}
}
1 change: 1 addition & 0 deletions lib/src/core/routing/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ final router = GoRouter(
initialLocation: '/counters',
routes: [
GoRoute(
name: 'counters',
path: '/counters',
builder: (context, state) => const DashboardPage(),
routes: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ class CounterView extends StatelessWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CounterText(counterValue: state.counterModel.value),
CounterText(
counterValue: state.counterModel.value,
counterName: state.counterModel.name,
),
Text(state.counterModel.name, style: theme.textTheme.caption),
],
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import 'package:convenient_test/convenient_test.dart';
import 'package:flutter/material.dart';

class CounterText extends StatelessWidget {
const CounterText({super.key, required this.counterValue});
const CounterText({
super.key,
required this.counterValue,
required this.counterName,
});
final int counterValue;
final String counterName;

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Text(
'$counterValue',
style: theme.textTheme.headlineLarge,
return Mark(
name: 'counter_text_$counterName',
child: Text(
'$counterValue',
style: theme.textTheme.headlineLarge,
),
);
}
}
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import FlutterMacOS
import Foundation

import path_provider_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
}
Loading