immich/mobile/test/asset_grid_data_structure_test.dart

133 lines
3.2 KiB
Dart
Raw Normal View History

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';
import 'package:immich_mobile/shared/models/asset.dart';
2022-09-30 09:38:00 +00:00
void main() {
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);
testAssets.add(
Asset(
checksum: "",
localId: '$i',
ownerId: 1,
fileCreatedAt: date,
fileModifiedAt: date,
updatedAt: date,
durationInSeconds: 0,
type: AssetType.image,
fileName: '',
isFavorite: false,
isArchived: false,
feat(server): trash asset (#4015) * refactor(server): delete assets endpoint * fix: formatting * chore: cleanup * chore: open api * chore(mobile): replace DeleteAssetDTO with BulkIdsDTOs * feat: trash an asset * chore(server): formatting * chore: open api * chore: wording * chore: open-api * feat(server): add withDeleted to getAssets queries * WIP: mobile-recycle-bin * feat(server): recycle-bin to system config * feat(web): use recycle-bin system config * chore(server): domain assetcore removed * chore(server): rename recycle-bin to trash * chore(web): rename recycle-bin to trash * chore(server): always send soft deleted assets for getAllByUserId * chore(web): formatting * feat(server): permanent delete assets older than trashed period * feat(web): trash empty placeholder image * feat(server): empty trash * feat(web): empty trash * WIP: mobile-recycle-bin * refactor(server): empty / restore trash to separate endpoint * test(server): handle failures * test(server): fix e2e server-info test * test(server): deletion test refactor * feat(mobile): use map settings from server-config to enable / disable map * feat(mobile): trash asset * fix(server): operations on assets in trash * feat(web): show trash statistics * fix(web): handle trash enabled * fix(mobile): restore updates from trash * fix(server): ignore trashed assets for person * fix(server): add / remove search index when trashed / restored * chore(web): format * fix(server): asset service test * fix(server): include trashed assts for duplicates from uploads * feat(mobile): no dialog for trash, always dialog for permanent delete * refactor(mobile): use isar where instead of dart filter * refactor(mobile): asset provide - handle deletes in single db txn * chore(mobile): review changes * feat(web): confirmation before empty trash * server: review changes * fix(server): handle library changes * fix: filter external assets from getting trashed / deleted * fix(server): empty-bin * feat: broadcast config update events through ws * change order of trash button on mobile * styling * fix(mobile): do not show trashed toast for local only assets --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-10-06 07:01:14 +00:00
isTrashed: false,
2023-10-22 02:38:07 +00:00
stackCount: 0,
),
);
2022-09-30 09:38:00 +00:00
}
final List<Asset> assets = [];
assets.addAll(
testAssets.sublist(0, 5).map((e) {
e.fileCreatedAt = DateTime(2022, 1, 5);
2022-09-30 09:38:00 +00:00
return e;
}).toList(),
);
assets.addAll(
testAssets.sublist(5, 10).map((e) {
e.fileCreatedAt = DateTime(2022, 1, 10);
2022-09-30 09:38:00 +00:00
return e;
}).toList(),
);
assets.addAll(
testAssets.sublist(10, 15).map((e) {
e.fileCreatedAt = DateTime(2022, 2, 17);
2022-09-30 09:38:00 +00:00
return e;
}).toList(),
);
assets.addAll(
testAssets.sublist(15, 30).map((e) {
e.fileCreatedAt = DateTime(2022, 10, 15);
2022-09-30 09:38:00 +00:00
return e;
}).toList(),
);
2022-09-30 09:38:00 +00:00
group('Test grouped', () {
test('test grouped check months', () async {
final renderList = await RenderList.fromAssets(
assets,
GroupAssetsBy.day,
);
2022-09-30 09:38:00 +00:00
// Oct
// Day 1
// 15 Assets => 5 Rows
// Feb
2022-09-30 09:38:00 +00:00
// Day 1
// 5 Assets => 2 Rows
// Jan
2022-09-30 09:38:00 +00:00
// Day 2
// 5 Assets => 2 Rows
// Day 1
// 5 Assets => 2 Rows
expect(renderList.elements.length, 4);
expect(
renderList.elements[0].type,
RenderAssetGridElementType.monthTitle,
);
expect(renderList.elements[0].date.month, 1);
expect(
renderList.elements[1].type,
RenderAssetGridElementType.groupDividerTitle,
);
expect(renderList.elements[1].date.month, 1);
expect(
renderList.elements[2].type,
RenderAssetGridElementType.monthTitle,
);
expect(renderList.elements[2].date.month, 2);
expect(
renderList.elements[3].type,
RenderAssetGridElementType.monthTitle,
);
expect(renderList.elements[3].date.month, 10);
2022-09-30 09:38:00 +00:00
});
test('test grouped check types', () async {
final renderList = await RenderList.fromAssets(
assets,
GroupAssetsBy.day,
);
2022-09-30 09:38:00 +00:00
// Oct
2022-09-30 09:38:00 +00:00
// Day 1
// 15 Assets => 3 Rows
2022-09-30 09:38:00 +00:00
// Feb
// Day 1
// 5 Assets => 1 Row
// Jan
// Day 2
// 5 Assets => 1 Row
2022-09-30 09:38:00 +00:00
// Day 1
// 5 Assets => 1 Row
2022-09-30 09:38:00 +00:00
final types = [
RenderAssetGridElementType.monthTitle,
RenderAssetGridElementType.groupDividerTitle,
2022-09-30 09:38:00 +00:00
RenderAssetGridElementType.monthTitle,
RenderAssetGridElementType.monthTitle,
];
expect(renderList.elements.length, types.length);
2022-09-30 09:38:00 +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
}
});
});
}