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