feat: alphabet list, change Layout etc
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:kooltap/l10n/app_localizations.dart';
|
||||
import 'package:kooltap/models/product.dart';
|
||||
import 'package:kooltap/views/bar/product_grid.dart';
|
||||
import 'package:kooltap/views/widgets/product_tile.dart';
|
||||
|
||||
final _products = [
|
||||
for (var i = 0; i < 60; i++)
|
||||
Product(
|
||||
id: 'prod-$i',
|
||||
name: 'Product $i',
|
||||
category: 'Drinks',
|
||||
stockQuantity: 10,
|
||||
lowStockThreshold: 2,
|
||||
priceInCents: 300,
|
||||
),
|
||||
];
|
||||
|
||||
void main() {
|
||||
Future<void> pumpGrid(WidgetTester tester, int rows, Size size) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: ProductGrid(
|
||||
products: _products,
|
||||
rows: rows,
|
||||
hasSelectedTab: true,
|
||||
onProductTap: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
for (final size in [const Size(853, 720), const Size(1280, 1000)]) {
|
||||
for (var rows = 2; rows <= 6; rows++) {
|
||||
testWidgets('shows exactly $rows rows at $size', (tester) async {
|
||||
await pumpGrid(tester, rows, size);
|
||||
|
||||
final grid = tester.getRect(find.byType(GridView));
|
||||
final tiles = tester
|
||||
.widgetList(find.byType(ProductTile))
|
||||
.map((tile) => tester.getRect(find.byWidget(tile)))
|
||||
.toList();
|
||||
|
||||
final fullyVisibleRows = {
|
||||
for (final tile in tiles)
|
||||
if (tile.top >= grid.top && tile.bottom <= grid.bottom + 0.5)
|
||||
tile.top.round(),
|
||||
};
|
||||
expect(fullyVisibleRows, hasLength(rows));
|
||||
|
||||
final lastRowBottom = tiles
|
||||
.where((tile) => tile.bottom <= grid.bottom + 0.5)
|
||||
.map((tile) => tile.bottom)
|
||||
.reduce((a, b) => a > b ? a : b);
|
||||
expect(
|
||||
grid.bottom - lastRowBottom,
|
||||
closeTo(16, 1),
|
||||
reason: 'the rows fill the height down to the bottom padding',
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user