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-06-10 20:13:59 +02:00
|
|
|
checksum: "",
|
2023-03-04 00:38:30 +02:00
|
|
|
localId: '$i',
|
|
|
|
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-04-17 07:02:07 +02:00
|
|
|
isArchived: false,
|
2023-10-06 09:01:14 +02:00
|
|
|
isTrashed: false,
|
2023-10-22 04:38:07 +02:00
|
|
|
stackCount: 0,
|
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,
|
2023-05-17 19:36:02 +02:00
|
|
|
GroupAssetsBy.day,
|
2023-02-09 19:35:44 +02:00
|
|
|
);
|
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
|
2024-01-05 07:20:55 +02:00
|
|
|
expect(renderList.elements, hasLength(4));
|
2023-02-04 22:42:42 +02:00
|
|
|
expect(
|
|
|
|
renderList.elements[0].type,
|
|
|
|
RenderAssetGridElementType.monthTitle,
|
|
|
|
);
|
2023-05-17 19:36:02 +02:00
|
|
|
expect(renderList.elements[0].date.month, 1);
|
2023-02-04 22:42:42 +02:00
|
|
|
expect(
|
2023-05-17 19:36:02 +02:00
|
|
|
renderList.elements[1].type,
|
|
|
|
RenderAssetGridElementType.groupDividerTitle,
|
|
|
|
);
|
|
|
|
expect(renderList.elements[1].date.month, 1);
|
|
|
|
expect(
|
|
|
|
renderList.elements[2].type,
|
2023-02-04 22:42:42 +02:00
|
|
|
RenderAssetGridElementType.monthTitle,
|
|
|
|
);
|
2023-05-17 19:36:02 +02:00
|
|
|
expect(renderList.elements[2].date.month, 2);
|
2023-02-04 22:42:42 +02:00
|
|
|
expect(
|
2023-05-17 19:36:02 +02:00
|
|
|
renderList.elements[3].type,
|
2023-02-04 22:42:42 +02:00
|
|
|
RenderAssetGridElementType.monthTitle,
|
|
|
|
);
|
2023-05-17 19:36:02 +02:00
|
|
|
expect(renderList.elements[3].date.month, 10);
|
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,
|
2023-05-17 19:36:02 +02:00
|
|
|
GroupAssetsBy.day,
|
2023-02-09 19:35:44 +02:00
|
|
|
);
|
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,
|
2022-09-30 11:38:00 +02:00
|
|
|
RenderAssetGridElementType.monthTitle,
|
|
|
|
RenderAssetGridElementType.monthTitle,
|
|
|
|
];
|
|
|
|
|
2024-01-05 07:20:55 +02:00
|
|
|
expect(renderList.elements, hasLength(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
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|