mirror of
https://github.com/immich-app/immich.git
synced 2024-12-30 11:28:22 +02:00
8708867c1c
* feature(mobile): sync assets, albums & users to local database on device * try to fix tests * move DB sync operations to new SyncService * clear db on user logout * fix reason for endless loading timeline * fix error when deleting album * fix thumbnail of device albums * add a few comments * fix Hive box not open in album service when loading local assets * adjust tests to int IDs * fix bug: show all albums when Recent is selected * update generated api * reworked Recents album isAll handling * guard against wrongly interleaved sync operations * fix: timeline asset ordering (sort asset state by created at) * fix: sort assets in albums by created at
142 lines
3.5 KiB
Dart
142 lines
3.5 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:immich_mobile/modules/home/ui/asset_grid/asset_grid_data_structure.dart';
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
|
|
|
void main() {
|
|
final List<Asset> testAssets = [];
|
|
|
|
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,
|
|
fileName: '',
|
|
isFavorite: false,
|
|
isLocal: false,
|
|
),
|
|
);
|
|
}
|
|
|
|
final List<Asset> assets = [];
|
|
|
|
assets.addAll(
|
|
testAssets.sublist(0, 5).map((e) {
|
|
e.fileCreatedAt = DateTime(2022, 1, 5);
|
|
return e;
|
|
}).toList(),
|
|
);
|
|
assets.addAll(
|
|
testAssets.sublist(5, 10).map((e) {
|
|
e.fileCreatedAt = DateTime(2022, 1, 10);
|
|
return e;
|
|
}).toList(),
|
|
);
|
|
assets.addAll(
|
|
testAssets.sublist(10, 15).map((e) {
|
|
e.fileCreatedAt = DateTime(2022, 2, 17);
|
|
return e;
|
|
}).toList(),
|
|
);
|
|
assets.addAll(
|
|
testAssets.sublist(15, 30).map((e) {
|
|
e.fileCreatedAt = DateTime(2022, 10, 15);
|
|
return e;
|
|
}).toList(),
|
|
);
|
|
|
|
group('Test grouped', () {
|
|
test('test grouped check months', () async {
|
|
final renderList = await RenderList.fromAssets(
|
|
assets,
|
|
AssetGridLayoutParameters(
|
|
3,
|
|
false,
|
|
GroupAssetsBy.day,
|
|
),
|
|
);
|
|
|
|
// Oct
|
|
// Day 1
|
|
// 15 Assets => 5 Rows
|
|
// Feb
|
|
// Day 1
|
|
// 5 Assets => 2 Rows
|
|
// Jan
|
|
// 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);
|
|
});
|
|
|
|
test('test grouped check types', () async {
|
|
final renderList = await RenderList.fromAssets(
|
|
assets,
|
|
AssetGridLayoutParameters(
|
|
5,
|
|
false,
|
|
GroupAssetsBy.day,
|
|
),
|
|
);
|
|
|
|
// Oct
|
|
// Day 1
|
|
// 15 Assets => 3 Rows
|
|
// Feb
|
|
// Day 1
|
|
// 5 Assets => 1 Row
|
|
// Jan
|
|
// Day 2
|
|
// 5 Assets => 1 Row
|
|
// Day 1
|
|
// 5 Assets => 1 Row
|
|
final types = [
|
|
RenderAssetGridElementType.monthTitle,
|
|
RenderAssetGridElementType.groupDividerTitle,
|
|
RenderAssetGridElementType.assetRow,
|
|
RenderAssetGridElementType.assetRow,
|
|
RenderAssetGridElementType.assetRow,
|
|
RenderAssetGridElementType.monthTitle,
|
|
RenderAssetGridElementType.groupDividerTitle,
|
|
RenderAssetGridElementType.assetRow,
|
|
RenderAssetGridElementType.monthTitle,
|
|
RenderAssetGridElementType.groupDividerTitle,
|
|
RenderAssetGridElementType.assetRow,
|
|
RenderAssetGridElementType.groupDividerTitle,
|
|
RenderAssetGridElementType.assetRow,
|
|
];
|
|
|
|
expect(renderList.elements.length, types.length);
|
|
|
|
for (int i = 0; i < renderList.elements.length; i++) {
|
|
expect(renderList.elements[i].type, types[i]);
|
|
}
|
|
});
|
|
});
|
|
}
|