Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
111 lines
3.2 KiB
Dart
111 lines
3.2 KiB
Dart
import 'package:cutdex/features/media/media_browser_body.dart';
|
|
import 'package:cutdex/features/media/media_browser_controller.dart';
|
|
import 'package:cutdex/l10n/app_localizations.dart';
|
|
import 'package:cutdex/workspace/project_state.dart';
|
|
import 'package:cutdex/workspace/projects.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
testWidgets('local browsing updates keep provider subscriptions bounded', (
|
|
tester,
|
|
) async {
|
|
final container = ProviderContainer(
|
|
overrides: [projectsProvider.overrideWith(_Projects.new)],
|
|
);
|
|
addTearDown(container.dispose);
|
|
await container.read(projectsProvider.future);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(
|
|
container: container,
|
|
child: const MaterialApp(
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: Scaffold(
|
|
body: MediaBrowserBody(
|
|
projectId: 'project',
|
|
grid: true,
|
|
desktop: true,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
final projects = container.read(projectsProvider.notifier) as _Projects;
|
|
Future<int> subscriptionWork() async {
|
|
projects._project.idReads = 0;
|
|
projects.publishUnselectedChange();
|
|
await tester.pumpAndSettle();
|
|
return projects._project.idReads;
|
|
}
|
|
|
|
final before = await subscriptionWork();
|
|
expect(before, greaterThan(0));
|
|
final browser = container.read(mediaBrowserProvider('project'));
|
|
for (var i = 0; i < 20; i++) {
|
|
browser.query = 'query $i';
|
|
browser.filter = MediaFilter.values[i % MediaFilter.values.length];
|
|
browser.sort = MediaSort.values[i % MediaSort.values.length];
|
|
browser.gridSize = MediaGridSize.values[i % MediaGridSize.values.length];
|
|
await tester.pump();
|
|
expect(await subscriptionWork(), before);
|
|
}
|
|
expect(tester.takeException(), isNull);
|
|
await tester.pumpWidget(const SizedBox());
|
|
});
|
|
}
|
|
|
|
class _Projects extends Projects {
|
|
final _project = _CountingProject();
|
|
var _revision = 0;
|
|
|
|
@override
|
|
Future<ProjectState> build() async => ProjectState(activeProject: _project);
|
|
|
|
void publishUnselectedChange() {
|
|
state = AsyncData(
|
|
state.requireValue.copyWith(
|
|
recent: [
|
|
RecentProject(
|
|
id: 'recent-${_revision++}',
|
|
name: 'Recent',
|
|
path: '/Recent.cutdex',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// Count selector evaluations through the public state model. Extra provider
|
|
// subscriptions increase this work even when the selected values stay equal.
|
|
class _CountingProject implements RecentProject {
|
|
final _value = const RecentProject(
|
|
id: 'project',
|
|
name: 'Project',
|
|
path: '/Project.cutdex',
|
|
);
|
|
int idReads = 0;
|
|
|
|
@override
|
|
String get id {
|
|
idReads++;
|
|
return _value.id;
|
|
}
|
|
|
|
@override
|
|
String get name => _value.name;
|
|
|
|
@override
|
|
String get path => _value.path;
|
|
|
|
@override
|
|
ProjectAvailability get availability => _value.availability;
|
|
|
|
@override
|
|
$RecentProjectCopyWith<RecentProject> get copyWith => _value.copyWith;
|
|
}
|