Skip to content
This repository was archived by the owner on Feb 25, 2024. It is now read-only.

Commit b845efc

Browse files
committed
Add golden test
Ref: #315
1 parent 0ddefad commit b845efc

28 files changed

+151
-0
lines changed

.github/workflows/flutter-ci.yml

+29
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,35 @@ jobs:
5858
- name: Check for any formatting issues
5959
run: dart format --set-exit-if-changed .
6060

61+
integration:
62+
runs-on: ubuntu-22.04
63+
steps:
64+
65+
- uses: actions/checkout@v2
66+
- uses: subosito/flutter-action@v2
67+
with:
68+
channel: 'stable'
69+
flutter-version: '3.10.x'
70+
71+
- name: Install dependencies
72+
run: |
73+
sudo apt update
74+
sudo apt -y install clang cmake curl libgtk-3-dev ninja-build pkg-config unzip xvfb
75+
sudo apt -y install fonts-noto-cjk fonts-ubuntu fonts-tibetan-machine
76+
77+
- name: Get dependencies
78+
run: flutter pub get
79+
80+
- name: Run integration tests
81+
run: xvfb-run -a -s '-screen 0 1280x800x24 +extension GLX' flutter test -d linux integration_test
82+
working-directory: example/
83+
84+
- uses: actions/upload-artifact@v3
85+
if: failure()
86+
with:
87+
name: failures
88+
path: example/integration_test/failures
89+
6190
pub:
6291
runs-on: ubuntu-20.04
6392
steps:

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.PHONY: goldens
2+
goldens:
3+
cd example && GDK_BACKEND=x11 GDK_SCALE=1 flutter test integration_test --update-goldens -d linux
+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:integration_test/integration_test.dart';
4+
import 'package:yaru/yaru.dart';
5+
import 'package:yaru_example/main.dart' as app;
6+
import 'package:yaru_example/main.dart';
7+
import 'package:yaru_example/view/home_page.dart';
8+
9+
// NOTE: run `flutter test --update-goldens integration_test` to update screenshots
10+
11+
Future<void> main() async {
12+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
13+
14+
testWidgets('fonts', (tester) async {
15+
tester.runApp();
16+
await tester.pumpAndSettle();
17+
await tester.takeScreenshots('fonts');
18+
});
19+
20+
testWidgets('buttons', (tester) async {
21+
tester.runApp();
22+
await tester.pumpAndSettle();
23+
await tester.tap(find.text('Controls'));
24+
await tester.pump();
25+
await tester.takeScreenshots('buttons');
26+
});
27+
28+
testWidgets('checks', (tester) async {
29+
tester.runApp();
30+
await tester.pumpAndSettle();
31+
await tester.tap(find.text('Controls'));
32+
await tester.pump();
33+
await tester.tap(find.text('Checks'));
34+
await tester.pump();
35+
await tester.takeScreenshots('checks');
36+
});
37+
38+
testWidgets('switches', (tester) async {
39+
tester.runApp();
40+
await tester.pumpAndSettle();
41+
await tester.tap(find.text('Controls'));
42+
await tester.pump();
43+
await tester.tap(find.text('Switches'));
44+
await tester.pump();
45+
await tester.takeScreenshots('switches');
46+
});
47+
48+
testWidgets('text fields', (tester) async {
49+
tester.runApp();
50+
await tester.pumpAndSettle();
51+
await tester.tap(find.text('Text Fields'));
52+
await tester.pump();
53+
primaryFocus?.unfocus();
54+
await tester.pump();
55+
await tester.takeScreenshots('text-fields');
56+
});
57+
58+
testWidgets('containers', (tester) async {
59+
tester.runApp();
60+
await tester.pumpAndSettle();
61+
await tester.tap(find.text('Containers'));
62+
await tester.pump();
63+
await tester.takeScreenshots('containers');
64+
});
65+
}
66+
67+
extension on WidgetTester {
68+
void runApp() {
69+
view.devicePixelRatio = 1;
70+
view.physicalSize = const Size(600, 700);
71+
app.main();
72+
}
73+
74+
void selectTheme({
75+
YaruVariant? variant,
76+
bool? highContrast,
77+
ThemeMode? themeMode,
78+
}) async {
79+
final context = element(find.byType(HomePage));
80+
AppTheme.apply(
81+
context,
82+
variant: variant,
83+
highContrast: highContrast,
84+
themeMode: themeMode,
85+
);
86+
}
87+
88+
Future<void> takeScreenshots(String screen) async {
89+
for (final themeMode in [ThemeMode.light, ThemeMode.dark]) {
90+
selectTheme(
91+
variant: YaruVariant.orange,
92+
themeMode: themeMode,
93+
highContrast: false,
94+
);
95+
await pumpAndSettle();
96+
await takeScreenshot(screen);
97+
98+
selectTheme(themeMode: themeMode, highContrast: true);
99+
await pumpAndSettle();
100+
await takeScreenshot(screen);
101+
}
102+
}
103+
104+
Future<void> takeScreenshot(String screen) async {
105+
final context = element(find.byType(HomePage));
106+
final theme = AppTheme.of(context);
107+
final suffix = [
108+
if (theme.highContrast == true) 'high-contrast' else theme.variant?.name,
109+
theme.themeMode?.name,
110+
].join('-');
111+
112+
await expectLater(
113+
find.byType(MaterialApp),
114+
matchesGoldenFile('goldens/$screen-$suffix.png'),
115+
);
116+
}
117+
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

example/pubspec.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ dev_dependencies:
1818
flutter_lints: ^2.0.1
1919
flutter_test:
2020
sdk: flutter
21+
integration_test:
22+
sdk: flutter
2123

2224
flutter:
2325
uses-material-design: true

0 commit comments

Comments
 (0)