diff --git a/lib/features/settings/preferences_extensions_section.dart b/lib/features/settings/preferences_extensions_section.dart index 48073646..cc0b8019 100644 --- a/lib/features/settings/preferences_extensions_section.dart +++ b/lib/features/settings/preferences_extensions_section.dart @@ -96,6 +96,7 @@ class PreferencesExtensionsSectionState @override material.Widget build(material.BuildContext context) { final busy = _installing || _openingFolder; + final wb = context.workbench; return material.Column( crossAxisAlignment: material.CrossAxisAlignment.start, children: [ @@ -126,11 +127,47 @@ class PreferencesExtensionsSectionState ), if (_error != null) ...[ const material.SizedBox(height: 10), - Text(_error!).small().foreground(), + material.Row( + children: [ + material.Icon( + material.Icons.error_outline_rounded, + size: 14, + color: wb.destructive, + ), + const Gap(6), + material.Expanded( + child: material.Text( + _error!, + style: material.TextStyle( + fontSize: 12, + color: wb.destructive, + ), + ), + ), + ], + ), ], if (_success != null) ...[ const material.SizedBox(height: 10), - Text(_success!).muted().small(), + material.Row( + children: [ + material.Icon( + material.Icons.check_circle_outline_rounded, + size: 14, + color: wb.success, + ), + const Gap(6), + material.Expanded( + child: material.Text( + _success!, + style: material.TextStyle( + fontSize: 12, + color: wb.success, + ), + ), + ), + ], + ), ], ], ); diff --git a/test/features/settings/preferences_extensions_section_test.dart b/test/features/settings/preferences_extensions_section_test.dart new file mode 100644 index 00000000..3191d53e --- /dev/null +++ b/test/features/settings/preferences_extensions_section_test.dart @@ -0,0 +1,137 @@ +import 'package:file_selector/file_selector.dart'; +import 'package:flutter/material.dart' as material; +import 'package:flutter_test/flutter_test.dart'; +import 'package:querya_desktop/core/extensions/local_extension_installer.dart'; +import 'package:querya_desktop/core/extensions/models/extension_manifest.dart'; +import 'package:querya_desktop/core/extensions/models/extension_type.dart'; +import 'package:querya_desktop/core/market/marketplace_repository.dart'; +import 'package:querya_desktop/core/theme/querya_theme.dart'; +import 'package:querya_desktop/features/settings/preferences_extensions_section.dart'; + +import '../../support/querya_theme_test_shell.dart'; + +class _FakeLocalExtensionInstaller extends LocalExtensionInstaller { + _FakeLocalExtensionInstaller({ + this.manifestToReturn, + this.exceptionToThrow, + }); + + final ExtensionManifest? manifestToReturn; + final Exception? exceptionToThrow; + + @override + Future installFromPath( + String path, { + String? expectedSha256, + void Function(double progress)? onProgress, + }) async { + if (exceptionToThrow != null) throw exceptionToThrow!; + return manifestToReturn!; + } +} + +void main() { + group('PreferencesExtensionsSection', () { + testWidgets('renders section title, hint and action buttons', (tester) async { + await tester.pumpWidget( + queryaThemeTestShell( + child: const material.Scaffold( + body: PreferencesExtensionsSection(), + ), + ), + ); + await tester.pumpAndSettle(); + + expect(find.text('Extensions'), findsOneWidget); + expect(find.text('Install from file…'), findsOneWidget); + expect(find.text('Open extensions folder'), findsOneWidget); + }); + + testWidgets('renders installation error with wb.destructive and error icon (#1651)', + (tester) async { + final installer = _FakeLocalExtensionInstaller( + exceptionToThrow: MarketplaceException('Corrupt zip archive.'), + ); + + await tester.pumpWidget( + queryaThemeTestShell( + data: QueryaTheme.darkDefault, + child: material.Scaffold( + body: PreferencesExtensionsSection( + installer: installer, + filePicker: () async => XFile('sample.zip'), + ), + ), + ), + ); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Install from file…')); + await tester.pumpAndSettle(); + + expect(find.text('Corrupt zip archive.'), findsOneWidget); + final errorText = tester.widget(find.text('Corrupt zip archive.')); + expect( + errorText.style?.color, + QueryaTheme.darkDefault.workbench.destructive, + ); + + final errorIcon = tester.widget( + find.byIcon(material.Icons.error_outline_rounded), + ); + expect( + errorIcon.color, + QueryaTheme.darkDefault.workbench.destructive, + ); + }); + + testWidgets( + 'renders installation success with wb.success and checkmark icon (#1651)', + (tester) async { + const manifest = ExtensionManifest( + id: 'corp.clickhouse', + name: 'ClickHouse Driver', + version: '1.2.0', + publisher: 'Corp', + type: ExtensionType.databaseDriver, + engines: {'querya': '^1.0.0'}, + ); + final installer = _FakeLocalExtensionInstaller( + manifestToReturn: manifest, + ); + + await tester.pumpWidget( + queryaThemeTestShell( + data: QueryaTheme.lightDefault, + child: material.Scaffold( + body: PreferencesExtensionsSection( + installer: installer, + filePicker: () async => XFile('clickhouse.qext'), + ), + ), + ), + ); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Install from file…')); + await tester.pumpAndSettle(); + + const expectedMsg = 'Installed "ClickHouse Driver" (corp.clickhouse) v1.2.0.'; + expect(find.text(expectedMsg), findsOneWidget); + + final successText = tester.widget(find.text(expectedMsg)); + expect( + successText.style?.color, + QueryaTheme.lightDefault.workbench.success, + ); + + final successIcon = tester.widget( + find.byIcon(material.Icons.check_circle_outline_rounded), + ); + expect( + successIcon.color, + QueryaTheme.lightDefault.workbench.success, + ); + }); + }); +}