worldhopper/test/services/server_software/entry_progress_test.dart
Felipe M. 58a562abe8
feat: refactor server software abstraction with Kavita REST API integration
Rename all OPDS-prefixed models to generic names (Server, Feed, Entry,
Link, StreamLink), expand the ServerSoftware interface to cover all
server interactions, and implement a full Kavita REST API client that
replaces the OPDS delegation.

- Rename OPDS* models to generic names across ~60 files
- Add database migrations 13 (opds_id → entry_id) and 14 (unify credentials)
- Create OPDSServerSoftware wrapping existing OPDS services
- Create KavitaApiClient for direct Kavita REST API calls
- Create KavitaFeedMapper to convert Kavita JSON to Feed/Entry models
- Rewrite KavitaServerSoftware to use native API (no OPDS delegation)
- Unify server credentials (remove softwareUsername/softwarePassword)
- Simplify add/edit server UI to single auth section
- Add test connection button to server add/edit screens
- Add progress indicator to PublicationCard using local and server data
- Eliminate softwareType branching in reader screens
- Add EntryProgress and fetchEntryProgress to ServerSoftware interface
- Fix Entry.acquisitionLink crash on empty links
- Add 59 new tests covering models, services, and providers
2026-04-06 17:46:48 +02:00

71 lines
1.8 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:worldhopper/services/server_software/server_software.dart';
void main() {
group('EntryProgress', () {
test('percentage is calculated correctly', () {
const progress = EntryProgress(
entryId: 'e1',
currentPage: 4,
totalPages: 10,
);
// (4 + 1) / 10 = 0.5
expect(progress.percentage, 0.5);
});
test('percentage is 0 when totalPages is 0', () {
const progress = EntryProgress(
entryId: 'e1',
currentPage: 0,
totalPages: 0,
);
expect(progress.percentage, 0.0);
});
test('percentage is 1.0 when on last page', () {
const progress = EntryProgress(
entryId: 'e1',
currentPage: 9,
totalPages: 10,
);
expect(progress.percentage, 1.0);
});
test('isCompleted is true when on last page', () {
const progress = EntryProgress(
entryId: 'e1',
currentPage: 9,
totalPages: 10,
);
expect(progress.isCompleted, isTrue);
});
test('isCompleted is false when not on last page', () {
const progress = EntryProgress(
entryId: 'e1',
currentPage: 5,
totalPages: 10,
);
expect(progress.isCompleted, isFalse);
});
test('isCompleted is false when totalPages is 0', () {
const progress = EntryProgress(
entryId: 'e1',
currentPage: 0,
totalPages: 0,
);
expect(progress.isCompleted, isFalse);
});
test('percentage for single page publication', () {
const progress = EntryProgress(
entryId: 'e1',
currentPage: 0,
totalPages: 1,
);
expect(progress.percentage, 1.0);
expect(progress.isCompleted, isTrue);
});
});
}