Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
143 lines
4.5 KiB
Dart
143 lines
4.5 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:cutdex/app/editor_theme.dart';
|
|
import 'package:cutdex/diagnostics/app_diagnostics.dart';
|
|
import 'package:cutdex/diagnostics/diagnostic_store.dart';
|
|
import 'package:cutdex/features/settings/diagnostic_settings.dart';
|
|
import 'package:cutdex/integrations/platform/file_picker.dart';
|
|
import 'package:cutdex/l10n/app_localizations.dart';
|
|
import 'package:cutdex/settings/settings_operation.dart';
|
|
import 'package:cutdex_native_flutter/cutdex_native_flutter.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
class _Picker extends AppFilePicker {
|
|
_Picker(this.destination);
|
|
final String? destination;
|
|
@override
|
|
Future<String?> pickDirectory({
|
|
String? initialDirectory,
|
|
String? confirmButtonText,
|
|
}) async => destination;
|
|
}
|
|
|
|
void main() {
|
|
late Directory root;
|
|
setUp(() {
|
|
root = Directory.systemTemp.createTempSync('cutdex-export-ui-');
|
|
AppDiagnostics.instance = AppDiagnostics(
|
|
DiagnosticStore(Directory('${root.path}/logs')),
|
|
);
|
|
});
|
|
tearDown(() async {
|
|
await AppDiagnostics.instance?.store.flush();
|
|
AppDiagnostics.instance = null;
|
|
await root.delete(recursive: true);
|
|
});
|
|
Future<ProviderContainer> show(
|
|
WidgetTester tester,
|
|
String? destination,
|
|
) async {
|
|
final container = ProviderContainer(
|
|
overrides: [filePickerProvider.overrideWithValue(_Picker(destination))],
|
|
);
|
|
addTearDown(container.dispose);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(
|
|
container: container,
|
|
child: MaterialApp(
|
|
theme: EditorTheme.penLight,
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: const Scaffold(body: DiagnosticSettings()),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
return container;
|
|
}
|
|
|
|
Future<void> click(WidgetTester tester, ProviderContainer container) async {
|
|
await tester.runAsync(() async {
|
|
await tester.tap(find.byKey(const Key('export-diagnostics')));
|
|
for (
|
|
var i = 0;
|
|
i < 2000 &&
|
|
container
|
|
.read(settingsOperationProvider('diagnosticsExport'))
|
|
.isLoading;
|
|
i++
|
|
) {
|
|
await Future<void>.delayed(const Duration(milliseconds: 1));
|
|
}
|
|
expect(
|
|
container
|
|
.read(settingsOperationProvider('diagnosticsExport'))
|
|
.isLoading,
|
|
isFalse,
|
|
);
|
|
});
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
testWidgets('exports a diagnostic package into the selected directory', (
|
|
tester,
|
|
) async {
|
|
final container = await show(tester, '${root.path}/export');
|
|
await tester.runAsync(() async {
|
|
AppDiagnostics.report(
|
|
const DiagnosticEvent(
|
|
component: 'preview',
|
|
operation: 'test',
|
|
error: 'Bearer PRIVATE',
|
|
),
|
|
);
|
|
await AppDiagnostics.instance!.store.flush();
|
|
});
|
|
await click(tester, container);
|
|
expect(find.text('Diagnostic package saved.'), findsOneWidget);
|
|
final directory = Directory('${root.path}/export');
|
|
final files = directory.listSync().cast<File>().toList();
|
|
expect(files, hasLength(1));
|
|
final contents = files.single.readAsStringSync();
|
|
expect(jsonDecode(contents)['events'], hasLength(1));
|
|
expect(contents, isNot(contains('PRIVATE')));
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets(
|
|
'canceling directory selection leaves no success message or export',
|
|
(tester) async {
|
|
final container = await show(tester, null);
|
|
await click(tester, container);
|
|
expect(find.text('Diagnostic package saved.'), findsNothing);
|
|
expect(
|
|
container.read(settingsOperationProvider('diagnosticsExport')).hasError,
|
|
isFalse,
|
|
);
|
|
expect(root.listSync(), isEmpty);
|
|
},
|
|
);
|
|
|
|
testWidgets('export failures show feedback and leave the button usable', (
|
|
tester,
|
|
) async {
|
|
final blocked = File('${root.path}/blocked')..writeAsStringSync('file');
|
|
final container = await show(tester, blocked.path);
|
|
await click(tester, container);
|
|
expect(
|
|
find.text('Could not export diagnostics. Please try again.'),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
tester
|
|
.widget<OutlinedButton>(find.byKey(const Key('export-diagnostics')))
|
|
.onPressed,
|
|
isNotNull,
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|