Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions lib/features/settings/preferences_extensions_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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,
),
),
),
],
),
],
],
);
Expand Down
137 changes: 137 additions & 0 deletions test/features/settings/preferences_extensions_section_test.dart
Original file line number Diff line number Diff line change
@@ -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<ExtensionManifest> 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<material.Text>(find.text('Corrupt zip archive.'));
expect(
errorText.style?.color,
QueryaTheme.darkDefault.workbench.destructive,
);

final errorIcon = tester.widget<material.Icon>(
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<material.Text>(find.text(expectedMsg));
expect(
successText.style?.color,
QueryaTheme.lightDefault.workbench.success,
);

final successIcon = tester.widget<material.Icon>(
find.byIcon(material.Icons.check_circle_outline_rounded),
);
expect(
successIcon.color,
QueryaTheme.lightDefault.workbench.success,
);
});
});
}
Loading