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(
|
|
|
|
deviceAssetId: '$i',
|
|
|
|
deviceId: '',
|
|
|
|
ownerId: '',
|
|
|
|
createdAt: date,
|
|
|
|
modifiedAt: date,
|
|
|
|
durationInSeconds: 0,
|
|
|
|
fileName: '',
|
2022-11-08 19:00:24 +02:00
|
|
|
),
|
|
|
|
);
|
2022-09-30 11:38:00 +02:00
|
|
|
}
|
|
|
|
|
2022-11-08 19:00:24 +02:00
|
|
|
final Map<String, List<Asset>> groups = {
|
2022-09-30 11:38:00 +02:00
|
|
|
'2022-01-05': testAssets.sublist(0, 5).map((e) {
|
2022-11-08 19:00:24 +02:00
|
|
|
e.createdAt = DateTime(2022, 1, 5);
|
2022-09-30 11:38:00 +02:00
|
|
|
return e;
|
|
|
|
}).toList(),
|
|
|
|
'2022-01-10': testAssets.sublist(5, 10).map((e) {
|
2022-11-08 19:00:24 +02:00
|
|
|
e.createdAt = DateTime(2022, 1, 10);
|
2022-09-30 11:38:00 +02:00
|
|
|
return e;
|
|
|
|
}).toList(),
|
|
|
|
'2022-02-17': testAssets.sublist(10, 15).map((e) {
|
2022-11-08 19:00:24 +02:00
|
|
|
e.createdAt = DateTime(2022, 2, 17);
|
2022-09-30 11:38:00 +02:00
|
|
|
return e;
|
|
|
|
}).toList(),
|
|
|
|
'2022-10-15': testAssets.sublist(15, 30).map((e) {
|
2022-11-08 19:00:24 +02:00
|
|
|
e.createdAt = DateTime(2022, 10, 15);
|
2022-09-30 11:38:00 +02:00
|
|
|
return e;
|
|
|
|
}).toList()
|
|
|
|
};
|
|
|
|
|
|
|
|
group('Test grouped', () {
|
2023-01-18 17:59:23 +02:00
|
|
|
test('test grouped check months', () async {
|
|
|
|
final renderList = await RenderList.fromAssetGroups(groups, 3);
|
2022-09-30 11:38:00 +02:00
|
|
|
|
|
|
|
// Jan
|
|
|
|
// Day 1
|
|
|
|
// 5 Assets => 2 Rows
|
|
|
|
// Day 2
|
|
|
|
// 5 Assets => 2 Rows
|
|
|
|
// Feb
|
|
|
|
// Day 1
|
|
|
|
// 5 Assets => 2 Rows
|
|
|
|
// Oct
|
|
|
|
// Day 1
|
|
|
|
// 15 Assets => 5 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-01-18 17:59:23 +02:00
|
|
|
expect(renderList.elements[0].date.month, 1);
|
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-01-18 17:59:23 +02:00
|
|
|
expect(renderList.elements[11].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 {
|
|
|
|
final renderList = await RenderList.fromAssetGroups(groups, 5);
|
2022-09-30 11:38:00 +02:00
|
|
|
|
|
|
|
// Jan
|
|
|
|
// Day 1
|
|
|
|
// 5 Assets
|
|
|
|
// Day 2
|
|
|
|
// 5 Assets
|
|
|
|
// Feb
|
|
|
|
// Day 1
|
|
|
|
// 5 Assets
|
|
|
|
// Oct
|
|
|
|
// Day 1
|
|
|
|
// 15 Assets => 3 Rows
|
|
|
|
|
|
|
|
final types = [
|
|
|
|
RenderAssetGridElementType.monthTitle,
|
|
|
|
RenderAssetGridElementType.dayTitle,
|
|
|
|
RenderAssetGridElementType.assetRow,
|
|
|
|
RenderAssetGridElementType.dayTitle,
|
|
|
|
RenderAssetGridElementType.assetRow,
|
|
|
|
RenderAssetGridElementType.monthTitle,
|
|
|
|
RenderAssetGridElementType.dayTitle,
|
|
|
|
RenderAssetGridElementType.assetRow,
|
|
|
|
RenderAssetGridElementType.monthTitle,
|
|
|
|
RenderAssetGridElementType.dayTitle,
|
|
|
|
RenderAssetGridElementType.assetRow,
|
|
|
|
RenderAssetGridElementType.assetRow,
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|