1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-30 11:28:22 +02:00
immich/mobile/test/asset_grid_data_structure_test.dart

144 lines
3.6 KiB
Dart
Raw Normal View History

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';
import 'package:immich_mobile/shared/models/asset.dart';
2022-09-30 11:38:00 +02:00
void main() {
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);
testAssets.add(
Asset(
localId: '$i',
deviceId: 1,
ownerId: 1,
fileCreatedAt: date,
fileModifiedAt: date,
updatedAt: date,
durationInSeconds: 0,
type: AssetType.image,
fileName: '',
isFavorite: false,
isLocal: false,
isArchived: false,
),
);
2022-09-30 11:38:00 +02:00
}
final List<Asset> assets = [];
assets.addAll(
testAssets.sublist(0, 5).map((e) {
e.fileCreatedAt = DateTime(2022, 1, 5);
2022-09-30 11:38:00 +02:00
return e;
}).toList(),
);
assets.addAll(
testAssets.sublist(5, 10).map((e) {
e.fileCreatedAt = DateTime(2022, 1, 10);
2022-09-30 11:38:00 +02:00
return e;
}).toList(),
);
assets.addAll(
testAssets.sublist(10, 15).map((e) {
e.fileCreatedAt = DateTime(2022, 2, 17);
2022-09-30 11:38:00 +02:00
return e;
}).toList(),
);
assets.addAll(
testAssets.sublist(15, 30).map((e) {
e.fileCreatedAt = DateTime(2022, 10, 15);
2022-09-30 11:38:00 +02:00
return e;
}).toList(),
);
2022-09-30 11:38:00 +02:00
group('Test grouped', () {
test('test grouped check months', () async {
final renderList = await RenderList.fromAssets(
assets,
AssetGridLayoutParameters(
3,
false,
GroupAssetsBy.day,
),
);
2022-09-30 11:38:00 +02:00
// Oct
// Day 1
// 15 Assets => 5 Rows
// Feb
2022-09-30 11:38:00 +02:00
// Day 1
// 5 Assets => 2 Rows
// Jan
2022-09-30 11:38:00 +02:00
// Day 2
// 5 Assets => 2 Rows
// Day 1
// 5 Assets => 2 Rows
expect(renderList.elements.length, 18);
expect(
renderList.elements[0].type,
RenderAssetGridElementType.monthTitle,
);
expect(renderList.elements[0].date.month, 10);
expect(
renderList.elements[7].type,
RenderAssetGridElementType.monthTitle,
);
expect(renderList.elements[7].date.month, 2);
expect(
renderList.elements[11].type,
RenderAssetGridElementType.monthTitle,
);
expect(renderList.elements[11].date.month, 1);
2022-09-30 11:38:00 +02:00
});
test('test grouped check types', () async {
final renderList = await RenderList.fromAssets(
assets,
AssetGridLayoutParameters(
5,
false,
GroupAssetsBy.day,
),
);
2022-09-30 11:38:00 +02:00
// Oct
2022-09-30 11:38:00 +02:00
// Day 1
// 15 Assets => 3 Rows
2022-09-30 11:38:00 +02:00
// Feb
// Day 1
// 5 Assets => 1 Row
// Jan
// Day 2
// 5 Assets => 1 Row
2022-09-30 11:38:00 +02:00
// Day 1
// 5 Assets => 1 Row
2022-09-30 11:38:00 +02:00
final types = [
RenderAssetGridElementType.monthTitle,
RenderAssetGridElementType.groupDividerTitle,
RenderAssetGridElementType.assetRow,
2022-09-30 11:38:00 +02:00
RenderAssetGridElementType.assetRow,
RenderAssetGridElementType.assetRow,
RenderAssetGridElementType.monthTitle,
RenderAssetGridElementType.groupDividerTitle,
2022-09-30 11:38:00 +02:00
RenderAssetGridElementType.assetRow,
RenderAssetGridElementType.monthTitle,
RenderAssetGridElementType.groupDividerTitle,
2022-09-30 11:38:00 +02:00
RenderAssetGridElementType.assetRow,
RenderAssetGridElementType.groupDividerTitle,
2022-09-30 11:38:00 +02:00
RenderAssetGridElementType.assetRow,
];
expect(renderList.elements.length, types.length);
2022-09-30 11:38:00 +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
}
});
});
}