feat: offer a non-Mews web page as a simplified view or in the browser

This commit is contained in:
randogoth 2026-10-12 11:13:34 +03:00
parent cea66fbb42
commit 00e42c925c
24 changed files with 863 additions and 152 deletions

View file

@ -8,7 +8,7 @@ import 'package:flutter/rendering.dart' show RenderParagraph;
import 'package:flutter_test/flutter_test.dart';
import 'package:mews/application/controllers/browser_controller.dart'
show BrokenPage, LoadFailed;
show LoadFailed;
import 'package:mews/database/database.dart';
import 'package:mews/l10n/strings.dart';
import 'package:mews/mews/document.dart';
@ -116,16 +116,67 @@ void main() {
expect(find.textContaining('Sign guestbook'), findsOneWidget);
});
testWidgets('shows the broken-page error and its text view', (tester) async {
await pumpApp(tester);
deps.browser.currentPage.value = null;
deps.browser.error.value = const BrokenPage('<p>Half a page &amp; more');
testWidgets('offers a web page simplified or in the browser', (tester) async {
// Ordinary HTML: unclosed tags, text loose in a div, a script to ignore.
// Nothing here is a markup error, it is simply not a Mews page.
const webPage = '''
<!DOCTYPE html>
<html><head><title>A Journal</title></head>
<body>
<script>ignore.me()</script>
<div>Loose text in a div.
<h2>A heading</h2>
<ul><li>First<li>Second</ul>
<p>Never closed
</body></html>
''';
final stubDeps = AppDependencies(
database: MewsDatabase.test(NativeDatabase.memory()),
fetch: FakeFetch(const {'https://example.com/journal': webPage}),
strings: strings,
);
await tester.pumpWidget(MewsApp(deps: stubDeps, strings: strings));
await tester.pumpAndSettle();
await stubDeps.browser.open('https://example.com/journal');
await tester.pumpAndSettle();
expect(find.textContaining('not a Mews page'), findsOneWidget);
expect(find.textContaining('markup error'), findsNothing);
expect(find.textContaining('Open in a web browser'), findsOneWidget);
await tester.tap(find.textContaining('Show a simplified version'));
await tester.pumpAndSettle();
// The structure survives, and what Mews cannot show is left out.
expect(find.textContaining('A heading'), findsOneWidget);
expect(find.textContaining('Loose text in a div'), findsOneWidget);
expect(find.textContaining('Never closed'), findsOneWidget);
expect(find.textContaining('Second'), findsWidgets);
expect(find.textContaining('ignore.me'), findsNothing);
expect(find.textContaining('simplified version'), findsWidgets);
});
testWidgets('calls a page that claims Mews and will not parse broken',
(tester) async {
const claimed = '''
<html><head><title>Claimed</title>
<meta name="mews-profile" content="0.1"></head>
<body><p>Never closed</body></html>
''';
final stubDeps = AppDependencies(
database: MewsDatabase.test(NativeDatabase.memory()),
fetch: FakeFetch(const {'https://example.com/claimed': claimed}),
strings: strings,
);
await tester.pumpWidget(MewsApp(deps: stubDeps, strings: strings));
await tester.pumpAndSettle();
await stubDeps.browser.open('https://example.com/claimed');
await tester.pumpAndSettle();
expect(find.textContaining('markup error'), findsOneWidget);
await tester.tap(find.textContaining('Show page text'));
await tester.pumpAndSettle();
expect(find.textContaining('Half a page & more'), findsOneWidget);
expect(find.textContaining('not a Mews page'), findsNothing);
});
testWidgets('shows the load-failed error page', (tester) async {