Files
cutdex/test/features/projects/project_tabs_controller_test.dart
T
lingjhf abc1868550
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
feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
2026-10-08 18:17:12 +00:00

118 lines
4.1 KiB
Dart

import 'package:cutdex/features/projects/project_tabs_controller.dart';
import 'package:cutdex/workspace/project_state.dart';
import 'package:cutdex/workspace/projects.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
const first = RecentProject(id: 'a', name: 'First', path: '/first');
const second = RecentProject(id: 'b', name: 'Second', path: '/second');
const third = RecentProject(id: 'c', name: 'Recent only', path: '/third');
late _Projects projects;
late ProviderContainer container;
late ProjectTabsController tabs;
setUp(() async {
projects = _Projects(
const ProjectState(activeProject: first, recent: [first, second, third]),
);
container = ProviderContainer(
overrides: [projectsProvider.overrideWith(() => projects)],
);
await container.read(projectsProvider.future);
tabs = container.read(projectTabsProvider.notifier);
});
tearDown(() => container.dispose());
List<RecentProject> opened() => container.read(projectTabsProvider);
test(
'tabs follow successful opens, keep order and exclude recent-only files',
() {
expect(opened(), [first]);
projects.publish(projects._current.copyWith(activeProject: second));
expect(opened(), [first, second]);
projects.publish(projects._current.copyWith(activeProject: first));
expect(opened(), [first, second]);
projects.publish(projects._current.copyWith(projectBusy: true));
expect(opened(), [first, second]);
},
);
test(
'history removal and truncation do not discard opened project metadata',
() {
projects.publish(projects._current.copyWith(activeProject: second));
projects.publish(projects._current.copyWith(recent: const [third]));
expect(opened(), [first, second]);
projects.publish(projects._current.copyWith(activeProject: null));
expect(opened(), [first, second]);
tabs.remove(second.id);
expect(opened(), [first]);
projects.publish(projects._current.copyWith(activeProject: second));
expect(opened(), [first, second]);
},
);
test('metadata changes update tabs without changing their order', () {
projects.publish(projects._current.copyWith(activeProject: second));
final renamed = first.copyWith(name: 'Renamed');
final relocated = second.copyWith(path: '/new-second');
projects.publish(
projects._current.copyWith(
recent: [renamed, relocated, third],
activeProject: relocated,
),
);
expect(opened(), [renamed, relocated]);
projects.publish(projects._current.copyWith(recent: const []));
final renamedAgain = renamed.copyWith(name: 'Renamed outside history');
tabs.updateProject(renamedAgain);
expect(opened(), [renamedAgain, relocated]);
});
test('history updates do not reopen a closed inactive tab', () {
projects.publish(projects._current.copyWith(activeProject: second));
tabs.remove(first.id);
projects.publish(
projects._current.copyWith(
recent: [
first.copyWith(name: 'Updated'),
second,
],
),
);
expect(opened(), [second]);
expect(() => opened().clear(), throwsUnsupportedError);
});
test('all opened projects remain available beyond the twenty-entry history limit', () {
for (var index = 0; index < 25; index++) {
final project = RecentProject(
id: 'extra-$index',
name: 'Project $index',
path: '/extra-$index',
);
projects.publish(
projects._current.copyWith(
activeProject: project,
recent: [project, ...projects._current.recent].take(20).toList(),
),
);
}
expect(projects._current.recent, hasLength(20));
expect(opened(), hasLength(26));
expect(opened().first, first);
expect(opened().last.id, 'extra-24');
});
}
class _Projects extends Projects {
_Projects(this.initial);
final ProjectState initial;
@override
Future<ProjectState> build() async => initial;
ProjectState get _current => state.requireValue;
void publish(ProjectState value) => state = AsyncData(value);
}