feat(project): persist catalog snapshot in project data

This commit is contained in:
gary
2026-02-24 21:43:25 +01:00
parent 25d570c779
commit fd72d53d2a
2 changed files with 57 additions and 3 deletions

View File

@@ -4,7 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:korken_mosaic/project_codec.dart';
void main() {
test('MosaicProjectData json roundtrip keeps values', () {
test('MosaicProjectData json roundtrip keeps values including catalog snapshot', () {
final original = MosaicProjectData(
useCapSize: true,
gridWidth: '50',
@@ -16,6 +16,10 @@ void main() {
colorVariation: 0.5,
selectedPreset: 'realistisch',
sourceImageBytes: Uint8List.fromList([1, 2, 3]),
catalogSnapshot: const [
MosaicPaletteSnapshotEntry(name: 'White', colorValue: 0xFFF2F2F2),
MosaicPaletteSnapshotEntry(name: 'Blue', colorValue: 0xFF3F6FD8),
],
savedAt: DateTime.parse('2026-01-01T12:00:00Z'),
);
@@ -28,5 +32,22 @@ void main() {
expect(decoded.selectedPreset, 'realistisch');
expect(decoded.sourceImageBytes, isNotNull);
expect(decoded.sourceImageBytes!, [1, 2, 3]);
expect(decoded.catalogSnapshot.length, 2);
expect(decoded.catalogSnapshot.first.name, 'White');
expect(decoded.catalogSnapshot.last.colorValue, 0xFF3F6FD8);
});
test('MosaicProjectData defaults to empty snapshot when old project has none', () {
final decoded = MosaicProjectData.fromJson({
'useCapSize': false,
'gridWidth': '40',
'gridHeight': '30',
'capSize': '12',
'selectedPreset': 'ausgewogen',
'savedAt': '2026-01-01T12:00:00Z',
});
expect(decoded.catalogSnapshot, isEmpty);
expect(decoded.sourceImageBytes, isNull);
});
}