feat: build v1 Mews client: reader UI, gestures, Drift store, fetch actor
This commit is contained in:
parent
d5a0fcbf48
commit
01a36e8aee
56 changed files with 7287 additions and 2 deletions
88
app/test/reader_widget_test.dart
Normal file
88
app/test/reader_widget_test.dart
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
import 'dart:io' show File;
|
||||
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:mews/database/database.dart';
|
||||
import 'package:mews/l10n/strings.dart';
|
||||
import 'package:mews/mews/document.dart';
|
||||
import 'package:mews/presentation/app.dart';
|
||||
import 'package:mews/presentation/reader/fob.dart';
|
||||
import 'package:mews/presentation/reader/mews_page_view.dart';
|
||||
import 'package:mews/presentation/reader/palettes.dart';
|
||||
|
||||
Future<MewsApp> _app() async {
|
||||
final strings = Strings();
|
||||
await strings.load();
|
||||
final deps = AppDependencies(database: MewsDatabase.test(NativeDatabase.memory()));
|
||||
return MewsApp(deps: deps, strings: strings);
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('starts with the address bar and no FOB', (tester) async {
|
||||
await tester.pumpWidget(await _app());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(TextField), findsOneWidget);
|
||||
expect(find.text('Enter a web address'), findsOneWidget);
|
||||
// The FOB only appears once the reader scrolls a page; without a page it
|
||||
// stays invisible and untouchable.
|
||||
final fob = tester.widget<Fob>(find.byType(Fob));
|
||||
expect(fob.visible, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('renders a page and follows links', (tester) async {
|
||||
final page = MewsPage(
|
||||
url: 'https://example.com/index.html',
|
||||
title: 'Test page',
|
||||
lang: 'en',
|
||||
direction: TextDirection.ltr,
|
||||
variant: MewsVariant.plain,
|
||||
specVersion: '0.1',
|
||||
entries: const [],
|
||||
body: const [
|
||||
HeadingBlock(1, [MewsText('A heading')]),
|
||||
ParagraphBlock([MewsText('Read on for more.')]),
|
||||
ParagraphBlock([
|
||||
MewsLink('https://example.com/next.html', [MewsText('the next page')]),
|
||||
]),
|
||||
],
|
||||
);
|
||||
|
||||
String? opened;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StringsScope(
|
||||
strings: (await _strings()),
|
||||
child: MewsPageView(
|
||||
page: page,
|
||||
palette: paletteFor(
|
||||
pageVariant: MewsVariant.plain, readerVariant: 'site', dark: false),
|
||||
fontFamily: 'Atkinson Hyperlegible',
|
||||
fontScale: 1.0,
|
||||
visitedUrls: const {},
|
||||
onLinkTap: (url) => opened = url,
|
||||
onFormSubmit: (_, _) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('A heading'), findsOneWidget);
|
||||
expect(find.textContaining('the next page'), findsOneWidget);
|
||||
|
||||
// The paragraph Text stretches the full column width, so tap on the
|
||||
// glyphs of the link itself, not the widget's center.
|
||||
final rect = tester.getRect(find.textContaining('the next page'));
|
||||
await tester.tapAt(rect.topLeft + const Offset(30, 13));
|
||||
await tester.pump();
|
||||
expect(opened, 'https://example.com/next.html');
|
||||
});
|
||||
}
|
||||
|
||||
Future<Strings> _strings() async {
|
||||
final strings = Strings();
|
||||
strings.loadSource(File('locales/en-US/main.ftl').readAsStringSync());
|
||||
return strings;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue