Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/screenshots/issue-6192/after-dark-1200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/issue-6192/after-dark-360.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/issue-6192/after-light-1200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/issue-6192/after-light-360.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/issue-6192/after-white-360.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/issue-6192/before-dark-1200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/issue-6192/before-dark-360.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/issue-6192/before-light-1200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/issue-6192/before-light-360.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/issue-6192/before-white-1200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/issue-6192/before-white-360.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions lib/library/view/grid_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ class _BookGridTextColumn extends StatelessWidget {

return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
LibraryOverflowTooltipText(
Expand Down
168 changes: 168 additions & 0 deletions test/library/view/library_card_alignment_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:otzaria/data/data_providers/file_system_data_provider.dart';
import 'package:otzaria/library/models/library.dart';
import 'package:otzaria/library/view/grid_items.dart';
import 'package:otzaria/models/book_source.dart';
import 'package:otzaria/models/books.dart';
import 'package:otzaria/settings/engine/app_settings_store.dart';
import 'package:otzaria/text_book/utils/book_versions_action.dart';
import 'package:otzaria/theme/app_seed_colors.dart';
import 'package:otzaria/theme/app_theme_data.dart';

import '../../support/golden_fonts.dart';
import '../../test_helpers/memory_cache_provider.dart';

class _ReadOnlyFileSystemData extends FileSystemData {
@override
Future<bool> canDeleteUserBookFromLibrary({
required String title,
int? categoryId,
String fileType = 'txt',
required BookSource source,
}) async => false;
}

Future<void> _pumpGrid(
WidgetTester tester, {
required double width,
required Book book,
bool showTopics = false,
VoidCallback? onBookTap,
}) async {
tester.view.physicalSize = Size(width, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
theme: AppThemeData.light(
AppThemeData.createColorScheme(
AppSeedColors.defaultLight,
Brightness.light,
),
compactMenuMode: false,
),
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaler: const TextScaler.linear(1.3),
),
child: Directionality(
textDirection: TextDirection.rtl,
child: child!,
),
),
home: Scaffold(
body: MyGridView(
leadingCategoryCount: 1,
items: [
CategoryGridItem(
category: Category(
title: 'ספרים חיצונים',
description: '',
shortDescription: '',
order: 0,
subCategories: [],
books: [],
parent: null,
),
onCategoryClickCallback: () {},
),
BookGridItem(
book: book,
showTopics: showTopics,
onBookClickCallback: onBookTap ?? () {},
),
],
),
),
),
);
await tester.pumpAndSettle();
}

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUpAll(() async {
await Settings.init(cacheProvider: MemoryCacheProvider());
await loadGoldenFonts();
});
setUp(() {
final originalFileSystem = FileSystemData.instance;
final originalVersionsProbe = bookVersionsProbeForTesting;
FileSystemData.instance = _ReadOnlyFileSystemData();
bookVersionsProbeForTesting = (_) async => false;
addTearDown(() {
FileSystemData.instance = originalFileSystem;
bookVersionsProbeForTesting = originalVersionsProbe;
});
});

for (final width in [360.0, 1200.0]) {
testWidgets('כותרת ספר יחידה ממורכזת כמו תיקייה, ברוחב $width', (
tester,
) async {
final book = TextBook(title: 'מגילת תענית');
var opened = false;
await _pumpGrid(
tester,
width: width,
book: book,
onBookTap: () => opened = true,
);
for (final (card, title) in [
(find.byType(CategoryGridItem), 'ספרים חיצונים'),
(find.byType(BookGridItem), book.title),
]) {
expect(
tester.getCenter(find.text(title)).dy,
closeTo(tester.getCenter(card).dy, 0.5),
reason: title,
);
}
await tester.tap(find.text(book.title));
expect(opened, isTrue);
expect(tester.takeException(), isNull);
}, variant: TargetPlatformVariant.only(TargetPlatform.windows));

testWidgets('כותרת ומחבר ארוכים נשארים קבוצה ממורכזת ברוחב $width', (
tester,
) async {
final book = TextBook(
title: 'שאלות ותשובות בענייני תפילה וברכות ומנהגי קהילות ישראל',
author: 'מאת הרב המחבר פירושים והערות לספרי הראשונים והאחרונים',
);
await _pumpGrid(tester, width: width, book: book);
final card = tester.getRect(find.byType(BookGridItem));
final title = tester.getRect(find.text(book.title));
final author = tester.getRect(find.text(book.author!));
final text = title.expandToInclude(author);
expect(author.top, greaterThan(title.bottom));
expect(text.top, greaterThanOrEqualTo(card.top));
expect(text.bottom, lessThanOrEqualTo(card.bottom));
expect(text.center.dy, closeTo(card.center.dy, 0.5));
expect(tester.takeException(), isNull);
}, variant: TargetPlatformVariant.only(TargetPlatform.windows));

testWidgets('תוצאת חיפוש שומרת כותרת למעלה ונתיב למטה ברוחב $width', (
tester,
) async {
final book = TextBook(
title: 'תוצאת חיפוש',
author: 'מחבר הספר',
topics: 'נושא שאינו נתיב',
categoryPath: 'תורה, בראשית',
);
await _pumpGrid(tester, width: width, book: book, showTopics: true);
final card = tester.getRect(find.byType(BookGridItem));
final title = tester.getRect(find.text(book.title));
final author = tester.getRect(find.text(book.author!));
final path = tester.getRect(find.text(book.categoryPath!));
expect(title.top - card.top, closeTo(10, 0.5));
expect(card.bottom - path.bottom, closeTo(10, 0.5));
expect(author.top, greaterThan(title.bottom));
expect(path.top, greaterThan(author.bottom));
expect(find.text(book.topics), findsNothing);
expect(tester.takeException(), isNull);
}, variant: TargetPlatformVariant.only(TargetPlatform.windows));
}
}
Loading