80 lines
2.6 KiB
Dart
80 lines
2.6 KiB
Dart
import 'package:drift/native.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:timetrack/core/database/app_database.dart';
|
|
import 'package:timetrack/features/projects/data/drift_projects_repository.dart';
|
|
|
|
import '../../helpers/sqlite_test_helper.dart';
|
|
|
|
void main() {
|
|
setUpAll(configureSqliteForTests);
|
|
|
|
late AppDatabase database;
|
|
late DriftProjectsRepository repo;
|
|
|
|
setUp(() {
|
|
database = AppDatabase(NativeDatabase.memory());
|
|
repo = DriftProjectsRepository(database);
|
|
});
|
|
|
|
tearDown(() => database.close());
|
|
|
|
group('ProjectsRepository', () {
|
|
test('create and watchAll', () async {
|
|
await repo.create(name: 'Alpha', colorValue: 0xFF0000FF);
|
|
await repo.create(name: 'Beta', colorValue: 0xFF00FF00);
|
|
|
|
final projects = await repo.watchAll().first;
|
|
expect(projects, hasLength(2));
|
|
expect(projects.map((p) => p.name), containsAll(['Alpha', 'Beta']));
|
|
});
|
|
|
|
test('watchActive excludes archived', () async {
|
|
await repo.create(name: 'Active', colorValue: 0xFFFF0000);
|
|
final id = await repo.create(name: 'Archived', colorValue: 0xFF000000);
|
|
await repo.archive(id);
|
|
|
|
final active = await repo.watchActive().first;
|
|
expect(active, hasLength(1));
|
|
expect(active.first.name, equals('Active'));
|
|
});
|
|
|
|
test('getById returns correct project', () async {
|
|
final id = await repo.create(name: 'FindMe', colorValue: 0xFF123456);
|
|
final project = await repo.getById(id);
|
|
expect(project, isNotNull);
|
|
expect(project!.name, equals('FindMe'));
|
|
});
|
|
|
|
test('update modifies project', () async {
|
|
final id = await repo.create(name: 'Old', colorValue: 0xFF111111);
|
|
final project = (await repo.getById(id))!;
|
|
await repo.update(project.copyWith(name: 'New'));
|
|
|
|
final updated = await repo.getById(id);
|
|
expect(updated!.name, equals('New'));
|
|
});
|
|
|
|
test('archive sets archivedAt', () async {
|
|
final id = await repo.create(name: 'ToArchive', colorValue: 0xFF222222);
|
|
await repo.archive(id);
|
|
final project = await repo.getById(id);
|
|
expect(project!.archivedAt, isNotNull);
|
|
});
|
|
|
|
test('unarchive clears archivedAt', () async {
|
|
final id = await repo.create(name: 'UnArchive', colorValue: 0xFF333333);
|
|
await repo.archive(id);
|
|
await repo.unarchive(id);
|
|
final project = await repo.getById(id);
|
|
expect(project!.archivedAt, isNull);
|
|
});
|
|
|
|
test('delete removes project', () async {
|
|
final id = await repo.create(name: 'Delete', colorValue: 0xFF444444);
|
|
await repo.delete(id);
|
|
final all = await repo.watchAll().first;
|
|
expect(all, isEmpty);
|
|
});
|
|
});
|
|
}
|