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/mews_page_view.dart'; import 'package:mews/presentation/reader/palettes.dart'; Future _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 its icons', (tester) async { await tester.pumpWidget(await _app()); await tester.pumpAndSettle(); expect(find.byType(TextField), findsOneWidget); expect(find.text('Enter a web address'), findsOneWidget); // Settings opens from the left icon; no floating button remains. expect(find.byIcon(Icons.tune), findsOneWidget); expect(find.byType(FloatingActionButton), findsNothing); }); 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() async { final strings = Strings(); strings.loadSource(File('locales/en-US/main.ftl').readAsStringSync()); return strings; }