Skip to content

Commit

Permalink
flutter: Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsergio committed Dec 7, 2024
1 parent c7fc4d1 commit 2cdbc27
Show file tree
Hide file tree
Showing 58 changed files with 3,236 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ name: CI

on:
push:
paths-ignore:
# These are built by another workflow
- src/flutter/**
- tests/flutter/**
- examples/flutter/**

branches:
- main
pull_request:
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/flutter-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ jobs:
- name: Run tests
run: |
ls build-dev-flutter/lib
cd src/flutter/dart
flutter pub get
xvfb-run flutter test
flutter test
env:
KDDW_BINDINGS_LIB: ${{ github.workspace }}/build-dev-flutter/lib/libkddockwidgets.so

- name: Run integration tests
run: |
cd tests/flutter/
flutter pub get
xvfb-run flutter test -d linux integration_test/ui_test.dart
env:
KDDW_BINDINGS_LIB: ${{ github.workspace }}/build-dev-flutter/lib/libkddockwidgets.so
18 changes: 9 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ kddockwidgets_example.iml
/src/core/layouting/build/

# Flutter auto generated files
/examples/flutter/linux/flutter/generated_plugin_registrant.cc
/examples/flutter/linux/flutter/generated_plugin_registrant.h
/examples/flutter/linux/flutter/generated_plugins.cmake
/examples/flutter/windows/flutter/generated_plugin_registrant.cc
/examples/flutter/windows/flutter/generated_plugin_registrant.h
/examples/flutter/windows/flutter/generated_plugins.cmake
/tests/flutter_tests_embedder/linux/flutter/generated_plugin_registrant.cc
/tests/flutter_tests_embedder/linux/flutter/generated_plugin_registrant.h
/tests/flutter_tests_embedder/linux/flutter/generated_plugins.cmake
generated_plugin_registrant.cc
generated_plugin_registrant.h
generated_plugins.cmake
.flutter-plugins
.flutter-plugins-dependencies
.metadata
/tests/flutter/build/
/tests/flutter/macos/Podfile
/tests/flutter/macos/Podfile.lock

/docs/book/book/
/book/
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ repos:
rev: v0.6.13
hooks:
- id: cmake-lint
exclude: (.py.cmake|Doxyfile.cmake|examples/flutter/)
exclude: (.py.cmake|Doxyfile.cmake|examples/flutter/|tests/flutter/)
- id: cmake-format
exclude: (.py.cmake|Doxyfile.cmake|examples/flutter/)
exclude: (.py.cmake|Doxyfile.cmake|examples/flutter/|tests/flutter/)
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.15.0
hooks:
Expand Down
16 changes: 15 additions & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ SPDX-License-Identifier = "MIT"
# Flutter
[[annotations]]
path = [
"tests/flutter_tests_embedder/tests_embedder.**",
"examples/flutter/assets/**",
"examples/flutter/macos/Runner/Configs/AppInfo.xcconfig",
"examples/flutter/.metadata",
Expand All @@ -136,6 +135,21 @@ path = [
"examples/flutter/macos/Runner/Release.entitlements",
"examples/flutter/windows/runner/resources/app_icon.ico",
"examples/flutter/windows/runner/runner.exe.manifest",
"tests/flutter/assets/**",
"tests/flutter/macos/Runner/Configs/AppInfo.xcconfig",
"tests/flutter/.metadata",
"tests/flutter/macos/Runner/Assets.xcassets/**",
"tests/flutter/macos/Runner.xcodeproj/**",
"tests/flutter/macos/Flutter/**",
"tests/flutter/macos/Runner.xcworkspace/**",
"tests/flutter/macos/.gitignore",
"tests/flutter/macos/Runner/Configs/**.xcconfig",
"tests/flutter/macos/Runner/Base.lproj/MainMenu.xib",
"tests/flutter/macos/Runner/DebugProfile.entitlements",
"tests/flutter/macos/Runner/Info.plist",
"tests/flutter/macos/Runner/Release.entitlements",
"tests/flutter/windows/runner/resources/app_icon.ico",
"tests/flutter/windows/runner/runner.exe.manifest",
]
precedence = "aggregate"
SPDX-FileCopyrightText = "Copyright 2013-2014 The Flutter Authors"
Expand Down
4 changes: 3 additions & 1 deletion src/flutter/dart/lib/widgets/DropAreaWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class DropAreaWidgetState extends State<DropAreaWidget> {
void scheduleCheckLayoutSize() {
WidgetsBinding.instance.addPostFrameCallback((_) {
final renderBox =
dropArea.key.currentContext?.findRenderObject() as RenderBox;
dropArea.key.currentContext?.findRenderObject() as RenderBox?;

if (renderBox == null) return;

final Size size = renderBox.size;
if (size != oldSize) {
Expand Down
13 changes: 13 additions & 0 deletions tests/flutter/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
#
# SPDX-License-Identifier: BSD-3-Clause

include: package:flutter_lints/flutter.yaml

linter:
rules:
library_prefixes: false
analyzer:
errors:
unused_import: false
file_names: false
Binary file added tests/flutter/assets/KDAB_bubble_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/flutter/assets/KDAB_bubble_fulcolor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions tests/flutter/integration_test/ui_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
This file is part of KDDockWidgets.
SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
Author: Sérgio Martins <[email protected]>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
Contact KDAB at <[email protected]> for commercial licensing options.
*/

import 'dart:io';
import 'dart:ui';

import 'package:KDDockWidgets/models/DockItem.dart';
import 'package:KDDockWidgets/models/DropArea.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:KDDockWidgets/widgets/DropAreaWidget.dart';

Future<Finder?> waitForWidget(WidgetTester tester, Key key,
{int maxTries = 10}) async {
for (int i = 0; i < maxTries; ++i) {
final finder = find.byKey(key);
if (finder.evaluate().isNotEmpty) return finder;
await tester.pump(const Duration(seconds: 1));
}

return null;
}

// Returns true when the widget can't be seen anymore
Future<bool> waitForWidgetToHide(WidgetTester tester, Key key,
{int maxTries = 10}) async {
for (int i = 0; i < maxTries; ++i) {
await tester.pump(const Duration(seconds: 1));
final finder = find.byKey(key);
if (finder.evaluate().isEmpty) return true;
}

return false;
}

Future<void> pumps(WidgetTester tester, int numPumps) async {
for (int i = 0; i < numPumps; ++i) {
await tester.pump(const Duration(seconds: 1));
}
}

class MyApp extends StatelessWidget {
final Widget child;
const MyApp({super.key, required this.child});

@override
Widget build(BuildContext context) {
return MaterialApp(
home: RepaintBoundary(
key: const Key('boundary'),
child: Scaffold(
body: child,
),
));
}
}

void main() async {
testWidgets('Basic test', (WidgetTester tester) async {
final dock1 =
DockItem(uniqueName: "dw1", guestWidget: Container(color: Colors.cyan));
final dock2 =
DockItem(uniqueName: "dw2", guestWidget: Container(color: Colors.cyan));
final dock3 =
DockItem(uniqueName: "dw3", guestWidget: Container(color: Colors.cyan));

final dock11 = DockItem(
uniqueName: "dw11", guestWidget: Container(color: Colors.cyan));
final dock12 = DockItem(
uniqueName: "dw12", guestWidget: Container(color: Colors.cyan));
final dock13 = DockItem(
uniqueName: "dw13", guestWidget: Container(color: Colors.cyan));

final dropArea = DropArea();
dropArea.addDockItem(dock1, Location.LocationOnTop);
dropArea.addDockItem(dock2, Location.LocationOnBottom);
final group = dropArea.groups.first;
group.addDockWidget(dock3);
group.addDockWidget(dock11);
group.addDockWidget(dock12);
group.addDockWidget(dock13);

dropArea.setLayoutSize(700, 700);
final dropAreaWidget = DropAreaWidget(dropArea);

// Build the widget tree
await tester.pumpWidget(MyApp(
child: dropAreaWidget,
));

await tester.pump();

final renderObject = tester.firstRenderObject(find.byType(RepaintBoundary));
final image =
await (renderObject as RenderRepaintBoundary).toImage(pixelRatio: 2);

final byteDataFuture = image.toByteData(format: ImageByteFormat.png);
await tester.pumpAndSettle();

final byteData = await byteDataFuture;
final buffer = byteData!.buffer.asUint8List();

// Save the bytes to a file
final file = File('screenshot.png');
file.writeAsBytesSync(buffer);
await tester.pump();
});
}
Loading

0 comments on commit 2cdbc27

Please sign in to comment.