Skip to content

Commit

Permalink
test: add basic integration test for snaps
Browse files Browse the repository at this point in the history
  • Loading branch information
d-loose committed Oct 5, 2023
1 parent 312a2b6 commit 967e00f
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Integration Test

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
integration:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.10.6'
- run: sudo apt update
- run: sudo apt install -y clang cmake libblkid-dev libglib2.0-dev libgtk-3-dev liblzma-dev network-manager ninja-build packagekit pkg-config polkitd xvfb
- run: sudo cp integration_test/assets/snapd-ci.pkla /var/lib/polkit-1/localauthority/50-local.d/
- run: LANG=en_US.UTF-8 xvfb-run -a -s '-screen 0 1024x768x24 +extension GLX' flutter test integration_test
78 changes: 78 additions & 0 deletions integration_test/app_center_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import 'dart:io';

import 'package:app_center/main.dart' as app;
import 'package:app_center/src/store/store_app.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:ubuntu_test/ubuntu_test.dart';
import 'package:yaru_icons/yaru_icons.dart';
import 'package:yaru_test/yaru_test.dart';

import '../test/test_utils.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('install and remove a snap', (tester) async {
final file = File('/snap/bin/hello');
await app.main([]);
await tester.pumpUntil(find.byType(StoreApp));
await tester.pumpAndSettle();
await testSearchSnap(tester, packageName: 'hello');
await testInstallSnap(tester, installedFile: file);
await testRemoveSnap(tester, installedFile: file);
});
}

Future<void> testSearchSnap(
WidgetTester tester, {
required String packageName,
}) async {
final searchField = find.textField(tester.l10n.searchFieldSearchHint);
expectSync(searchField, findsOneWidget);
await tester.enterText(searchField, packageName);
await tester.pumpAndSettle();

final dropdownEntry = find.widgetWithText(ListTile, packageName);
await tester.pumpUntil(dropdownEntry);
expectSync(dropdownEntry, findsOneWidget);

await tester.tap(dropdownEntry);
await tester.pumpAndSettle();
}

Future<void> testInstallSnap(
WidgetTester tester, {
required File installedFile,
}) async {
expect(installedFile.existsSync(), isFalse);

final installButton = find.button(tester.l10n.snapActionInstallLabel);
final openButton = find.button(tester.l10n.snapActionOpenLabel);
expectSync(installButton, findsOneWidget);
expectSync(openButton, findsNothing);

await tester.tap(installButton);
await tester.pumpUntil(openButton);

expectSync(openButton, findsOneWidget);
expectSync(installButton, findsNothing);

expectSync(installedFile.existsSync(), isTrue);
}

Future<void> testRemoveSnap(
WidgetTester tester, {
required File installedFile,
}) async {
final installButton = find.button(tester.l10n.snapActionInstallLabel);
expect(installButton, findsNothing);

await tester.tap(find.iconButton(YaruIcons.view_more_horizontal));
await tester.pumpAndSettle();
await tester.tap(find.button(tester.l10n.snapActionRemoveLabel));
await tester.pumpUntil(installButton);

expect(installedFile.existsSync(), isFalse);
}
4 changes: 4 additions & 0 deletions integration_test/assets/snapd-ci.pkla
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Allow privileged snapd actions without prompting, for use in integration tests in destructive CI environments only]
Identity=unix-user:*
Action=io.snapcraft.snapd.manage
ResultAny=yes
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ dev_dependencies:
flutter_lints: ^2.0.0
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
melos: ^3.0.0
mockito: 5.4.2

Expand Down

0 comments on commit 967e00f

Please sign in to comment.