2022-09-30 11:38:00 +02:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
2022-10-01 10:33:06 +02:00
|
|
|
import 'package:immich_mobile/modules/home/ui/asset_grid/asset_grid_data_structure.dart';
|
2022-11-08 19:00:24 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
2022-09-30 11:38:00 +02:00
|
|
|
|
|
|
|
void main() {
|
2022-11-08 19:00:24 +02:00
|
|
|
final List<Asset> testAssets = [];
|
2022-09-30 11:38:00 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 150; i++) {
|
|
|
|
int month = i ~/ 31;
|
|
|
|
int day = (i % 31).toInt();
|
|
|
|
|
|
|
|
DateTime date = DateTime(2022, month, day);
|
|
|
|
|
2022-11-08 19:00:24 +02:00
|
|
|
testAssets.add(
|
2023-02-04 22:42:42 +02:00
|
|
|
Asset(
|
2023-03-04 00:38:30 +02:00
|
|
|
localId: '$i',
|
|
|
|
deviceId: 1,
|
|
|
|
ownerId: 1,
|
2023-02-19 18:44:53 +02:00
|
|
|
fileCreatedAt: date,
|
|
|
|
fileModifiedAt: date,
|
2023-03-04 00:38:30 +02:00
|
|
|
updatedAt: date,
|
2023-02-04 22:42:42 +02:00
|
|
|
durationInSeconds: 0,
|
2023-03-27 04:35:52 +02:00
|
|
|
type: AssetType.image,
|
2023-02-04 22:42:42 +02:00
|
|
|
fileName: '',
|
2023-02-05 05:25:11 +02:00
|
|
|
isFavorite: false,
|
2023-03-04 00:38:30 +02:00
|
|
|
isLocal: false,
|
2022-11-08 19:00:24 +02:00
|
|
|
),
|
|
|
|
);
|
2022-09-30 11:38:00 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 19:35:44 +02:00
|
|
|
final List<Asset> assets = [];
|
|
|
|
|
|
|
|
assets.addAll(
|
|
|
|
testAssets.sublist(0, 5).map((e) {
|
2023-02-19 18:44:53 +02:00
|
|
|
e.fileCreatedAt = DateTime(2022, 1, 5);
|
2022-09-30 11:38:00 +02:00
|
|
|
return e;
|
|
|
|
}).toList(),
|
2023-02-09 19:35:44 +02:00
|
|
|
);
|
|
|
|
assets.addAll(
|
|
|
|
testAssets.sublist(5, 10).map((e) {
|
2023-02-19 18:44:53 +02:00
|
|
|
e.fileCreatedAt = DateTime(2022, 1, 10);
|
2022-09-30 11:38:00 +02:00
|
|
|
return e;
|
|
|
|
}).toList(),
|
2023-02-09 19:35:44 +02:00
|
|
|
);
|
|
|
|
assets.addAll(
|
|
|
|
testAssets.sublist(10, 15).map((e) {
|
2023-02-19 18:44:53 +02:00
|
|
|
e.fileCreatedAt = DateTime(2022, 2, 17);
|
2022-09-30 11:38:00 +02:00
|
|
|
return e;
|
|
|
|
}).toList(),
|
2023-02-09 19:35:44 +02:00
|
|
|
);
|
|
|
|
assets.addAll(
|
|
|
|
testAssets.sublist(15, 30).map((e) {
|
2023-02-19 18:44:53 +02:00
|
|
|
e.fileCreatedAt = DateTime(2022, 10, 15);
|
2022-09-30 11:38:00 +02:00
|
|
|
return e;
|
2023-02-09 19:35:44 +02:00
|
|
|
}).toList(),
|
|
|
|
);
|
2022-09-30 11:38:00 +02:00
|
|
|
|
|
|
|
group('Test grouped', () {
|
2023-01-18 17:59:23 +02:00
|
|
|
test('test grouped check months', () async {
|
2023-02-09 19:35:44 +02:00
|
|
|
final renderList = await RenderList.fromAssets(
|
|
|
|
assets,
|
|
|
|
AssetGridLayoutParameters(
|
|
|
|
3,
|
|
|
|
false,
|
|
|
|
GroupAssetsBy.day,
|
|
|
|
),
|
|
|
|
);
|
2022-09-30 11:38:00 +02:00
|
|
|
|
2023-02-09 19:35:44 +02:00
|
|
|
// Oct
|
|
|
|
// Day 1
|
|
|
|
// 15 Assets => 5 Rows
|
|
|
|
// Feb
|
2022-09-30 11:38:00 +02:00
|
|
|
// Day 1
|
|
|
|
// 5 Assets => 2 Rows
|
2023-02-09 19:35:44 +02:00
|
|
|
// Jan
|
2022-09-30 11:38:00 +02:00
|
|
|
// Day 2
|
|
|
|
// 5 Assets => 2 Rows
|
|
|
|
// Day 1
|
|
|
|
// 5 Assets => 2 Rows
|
2023-01-18 17:59:23 +02:00
|
|
|
expect(renderList.elements.length, 18);
|
2023-02-04 22:42:42 +02:00
|
|
|
expect(
|
|
|
|
renderList.elements[0].type,
|
|
|
|
RenderAssetGridElementType.monthTitle,
|
|
|
|
);
|
2023-02-09 19:35:44 +02:00
|
|
|
expect(renderList.elements[0].date.month, 10);
|
2023-02-04 22:42:42 +02:00
|
|
|
expect(
|
|
|
|
renderList.elements[7].type,
|
|
|
|
RenderAssetGridElementType.monthTitle,
|
|
|
|
);
|
2023-01-18 17:59:23 +02:00
|
|
|
expect(renderList.elements[7].date.month, 2);
|
2023-02-04 22:42:42 +02:00
|
|
|
expect(
|
|
|
|
renderList.elements[11].type,
|
|
|
|
RenderAssetGridElementType.monthTitle,
|
|
|
|
);
|
2023-02-09 19:35:44 +02:00
|
|
|
expect(renderList.elements[11].date.month, 1);
|
2022-09-30 11:38:00 +02:00
|
|
|
});
|
|
|
|
|
2023-01-18 17:59:23 +02:00
|
|
|
test('test grouped check types', () async {
|
2023-02-09 19:35:44 +02:00
|
|
|
final renderList = await RenderList.fromAssets(
|
|
|
|
assets,
|
|
|
|
AssetGridLayoutParameters(
|
|
|
|
5,
|
|
|
|
false,
|
|
|
|
GroupAssetsBy.day,
|
|
|
|
),
|
|
|
|
);
|
2022-09-30 11:38:00 +02:00
|
|
|
|
2023-02-09 19:35:44 +02:00
|
|
|
// Oct
|
2022-09-30 11:38:00 +02:00
|
|
|
// Day 1
|
2023-02-09 19:35:44 +02:00
|
|
|
// 15 Assets => 3 Rows
|
2022-09-30 11:38:00 +02:00
|
|
|
// Feb
|
|
|
|
// Day 1
|
2023-02-09 19:35:44 +02:00
|
|
|
// 5 Assets => 1 Row
|
|
|
|
// Jan
|
|
|
|
// Day 2
|
|
|
|
// 5 Assets => 1 Row
|
2022-09-30 11:38:00 +02:00
|
|
|
// Day 1
|
2023-02-09 19:35:44 +02:00
|
|
|
// 5 Assets => 1 Row
|
2022-09-30 11:38:00 +02:00
|
|
|
final types = [
|
|
|
|
RenderAssetGridElementType.monthTitle,
|
2023-02-09 19:35:44 +02:00
|
|
|
RenderAssetGridElementType.groupDividerTitle,
|
|
|
|
RenderAssetGridElementType.assetRow,
|
2022-09-30 11:38:00 +02:00
|
|
|
RenderAssetGridElementType.assetRow,
|
|
|
|
RenderAssetGridElementType.assetRow,
|
|
|
|
RenderAssetGridElementType.monthTitle,
|
2023-02-09 19:35:44 +02:00
|
|
|
RenderAssetGridElementType.groupDividerTitle,
|
2022-09-30 11:38:00 +02:00
|
|
|
RenderAssetGridElementType.assetRow,
|
|
|
|
RenderAssetGridElementType.monthTitle,
|
2023-02-09 19:35:44 +02:00
|
|
|
RenderAssetGridElementType.groupDividerTitle,
|
2022-09-30 11:38:00 +02:00
|
|
|
RenderAssetGridElementType.assetRow,
|
2023-02-09 19:35:44 +02:00
|
|
|
RenderAssetGridElementType.groupDividerTitle,
|
2022-09-30 11:38:00 +02:00
|
|
|
RenderAssetGridElementType.assetRow,
|
|
|
|
];
|
|
|
|
|
2023-01-18 17:59:23 +02:00
|
|
|
expect(renderList.elements.length, types.length);
|
2022-09-30 11:38:00 +02:00
|
|
|
|
2023-01-18 17:59:23 +02:00
|
|
|
for (int i = 0; i < renderList.elements.length; i++) {
|
|
|
|
expect(renderList.elements[i].type, types[i]);
|
2022-09-30 11:38:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|