Skip to content

Commit

Permalink
Implement first test
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Oct 25, 2023
1 parent 25e6e75 commit 1207a0b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
6 changes: 2 additions & 4 deletions api/lib/src/converter/legacy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ Archive convertLegacyDataToArchive(Map<String, dynamic> data) {
'fileVersion': 8,
...legacyNoteDataJsonMigrator(data),
};
final archive = Archive();
var reader = NoteData(archive);
var reader = NoteData(Archive());
reader = reader.setAsset(kMetaArchiveFile, utf8.encode(jsonEncode(data)));
NoteFileType type = NoteFileType.document;
try {
Expand Down Expand Up @@ -55,7 +54,7 @@ Archive convertLegacyDataToArchive(Map<String, dynamic> data) {
reader = reader.setThumbnail(data);
}
}
return archive;
return reader.export();
}

Map<String, dynamic> legacyNoteDataJsonMigrator(Map<String, dynamic> data) {
Expand All @@ -78,7 +77,6 @@ Map<String, dynamic> legacyNoteDataJsonMigrator(Map<String, dynamic> data) {

Map<String, dynamic> _legacyDocumentJsonMigrator(
Map<String, dynamic> data, int? fileVersion) {
final fileVersion = data['fileVersion'] as int?;
if (fileVersion != null && fileVersion >= 0) {
if (fileVersion < 4) {
data['palettes'] = List.from(
Expand Down
1 change: 1 addition & 0 deletions api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
json_annotation: ^4.8.1
replay_bloc: ^0.2.4
rxdart: ^0.27.7
test: ^1.24.9
dev_dependencies:
json_serializable: ^6.7.1
build_runner: ^2.4.6
Expand Down
1 change: 1 addition & 0 deletions api/test/assets/document_v1.bfly
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"25/10/2023 18:56","description":"","content":[{"layer":"","points":[{"x":683,"y":193,"pressure":0},{"x":684,"y":199,"pressure":0.5},{"x":686,"y":216,"pressure":0.5},{"x":691,"y":244,"pressure":0.5},{"x":698,"y":282,"pressure":0.5},{"x":708,"y":340,"pressure":0.5},{"x":714,"y":372,"pressure":0.5},{"x":719,"y":403,"pressure":0.5},{"x":721,"y":417,"pressure":0.5},{"x":722,"y":428,"pressure":0.5},{"x":722,"y":431,"pressure":0.5},{"x":721,"y":435,"pressure":0.5},{"x":721,"y":434,"pressure":0.5},{"x":721,"y":425,"pressure":0.5},{"x":720,"y":411,"pressure":0.5},{"x":721,"y":403,"pressure":0.5},{"x":722,"y":384,"pressure":0.5},{"x":724,"y":367,"pressure":0.5},{"x":726,"y":360,"pressure":0.5},{"x":729,"y":346,"pressure":0.5},{"x":733,"y":336,"pressure":0.5},{"x":738,"y":327,"pressure":0.5},{"x":741,"y":323,"pressure":0.5},{"x":744,"y":320,"pressure":0.5},{"x":747,"y":318,"pressure":0.5},{"x":757,"y":316,"pressure":0.5},{"x":764,"y":318,"pressure":0.5},{"x":767,"y":319,"pressure":0.5},{"x":773,"y":325,"pressure":0.5},{"x":777,"y":332,"pressure":0.5},{"x":782,"y":341,"pressure":0.5},{"x":783,"y":346,"pressure":0.5},{"x":785,"y":354,"pressure":0.5},{"x":787,"y":364,"pressure":0.5},{"x":788,"y":374,"pressure":0.5},{"x":789,"y":380,"pressure":0.5},{"x":789,"y":389,"pressure":0.5},{"x":791,"y":396,"pressure":0.5},{"x":792,"y":398,"pressure":0.5},{"x":795,"y":404,"pressure":0.5},{"x":801,"y":408,"pressure":0.5},{"x":804,"y":410,"pressure":0.5},{"x":810,"y":412,"pressure":0.5},{"x":817,"y":412,"pressure":0.5},{"x":824,"y":412,"pressure":0.5},{"x":827,"y":411,"pressure":0.5},{"x":834,"y":408,"pressure":0.5},{"x":842,"y":402,"pressure":0.5},{"x":846,"y":398,"pressure":0.5},{"x":854,"y":388,"pressure":0.5},{"x":861,"y":376,"pressure":0.5},{"x":864,"y":371,"pressure":0.5},{"x":867,"y":365,"pressure":0.5},{"x":869,"y":359,"pressure":0.5},{"x":874,"y":347,"pressure":0.5},{"x":877,"y":333,"pressure":0.5},{"x":877,"y":329,"pressure":0.5},{"x":877,"y":321,"pressure":0.5},{"x":876,"y":316,"pressure":0.5},{"x":876,"y":314,"pressure":0.5},{"x":874,"y":311,"pressure":0.5},{"x":868,"y":309,"pressure":0.5},{"x":865,"y":309,"pressure":0.5},{"x":862,"y":309,"pressure":0.5},{"x":857,"y":309,"pressure":0.5},{"x":848,"y":310,"pressure":0.5},{"x":840,"y":312,"pressure":0.5},{"x":835,"y":314,"pressure":0.5},{"x":828,"y":319,"pressure":0.5},{"x":822,"y":325,"pressure":0.5},{"x":820,"y":329,"pressure":0.5},{"x":815,"y":336,"pressure":0.5},{"x":812,"y":343,"pressure":0.5},{"x":811,"y":347,"pressure":0.5},{"x":811,"y":356,"pressure":0.5},{"x":812,"y":365,"pressure":0.5},{"x":814,"y":370,"pressure":0.5},{"x":818,"y":380,"pressure":0.5},{"x":822,"y":389,"pressure":0.5},{"x":827,"y":396,"pressure":0.5},{"x":830,"y":399,"pressure":0.5},{"x":835,"y":404,"pressure":0.5},{"x":841,"y":407,"pressure":0.5},{"x":844,"y":408,"pressure":0.5},{"x":848,"y":409,"pressure":0.5},{"x":852,"y":409,"pressure":0.5},{"x":861,"y":409,"pressure":0.5},{"x":870,"y":409,"pressure":0.5},{"x":874,"y":409,"pressure":0.5},{"x":883,"y":407,"pressure":0.5},{"x":892,"y":404,"pressure":0.5},{"x":897,"y":402,"pressure":0.5},{"x":906,"y":396,"pressure":0.5},{"x":915,"y":389,"pressure":0.5},{"x":919,"y":385,"pressure":0.5},{"x":922,"y":381,"pressure":0.5},{"x":924,"y":376,"pressure":0.5},{"x":929,"y":369,"pressure":0.5},{"x":932,"y":362,"pressure":0.5},{"x":934,"y":358,"pressure":0.5},{"x":937,"y":351,"pressure":0.5},{"x":940,"y":344,"pressure":0.5},{"x":941,"y":340,"pressure":0.5},{"x":943,"y":334,"pressure":0.5},{"x":944,"y":328,"pressure":0.5},{"x":944,"y":326,"pressure":0.5},{"x":944,"y":322,"pressure":0.5},{"x":944,"y":320,"pressure":0.5},{"x":943,"y":315,"pressure":0.5},{"x":941,"y":312,"pressure":0.5},{"x":941,"y":310,"pressure":0.5},{"x":939,"y":308,"pressure":0.5},{"x":938,"y":305,"pressure":0.5},{"x":937,"y":305,"pressure":0.5},{"x":936,"y":304,"pressure":0.5},{"x":935,"y":304,"pressure":0.5},{"x":934,"y":304,"pressure":0.5},{"x":933,"y":304,"pressure":0.5},{"x":932,"y":305,"pressure":0.5},{"x":931,"y":307,"pressure":0.5},{"x":931,"y":309,"pressure":0.5},{"x":931,"y":312,"pressure":0.5},{"x":931,"y":315,"pressure":0.5},{"x":931,"y":324,"pressure":0.5},{"x":932,"y":333,"pressure":0.5},{"x":932,"y":338,"pressure":0.5},{"x":933,"y":343,"pressure":0.5},{"x":934,"y":347,"pressure":0.5},{"x":937,"y":355,"pressure":0.5},{"x":942,"y":363,"pressure":0.5},{"x":945,"y":366,"pressure":0.5},{"x":953,"y":373,"pressure":0.5},{"x":962,"y":380,"pressure":0.5},{"x":967,"y":382,"pressure":0.5},{"x":978,"y":384,"pressure":0.5},{"x":986,"y":385,"pressure":0.5},{"x":991,"y":385,"pressure":0.5},{"x":1002,"y":383,"pressure":0.5},{"x":1013,"y":380,"pressure":0.5},{"x":1023,"y":377,"pressure":0.5},{"x":1028,"y":374,"pressure":0.5},{"x":1037,"y":369,"pressure":0.5},{"x":1045,"y":364,"pressure":0.5},{"x":1048,"y":362,"pressure":0.5},{"x":1054,"y":355,"pressure":0.5},{"x":1059,"y":349,"pressure":0.5},{"x":1061,"y":345,"pressure":0.5},{"x":1063,"y":341,"pressure":0.5},{"x":1064,"y":335,"pressure":0.5},{"x":1065,"y":327,"pressure":0.5},{"x":1063,"y":319,"pressure":0.5},{"x":1061,"y":314,"pressure":0.5},{"x":1056,"y":305,"pressure":0.5},{"x":1051,"y":299,"pressure":0.5},{"x":1048,"y":296,"pressure":0.5},{"x":1040,"y":291,"pressure":0.5},{"x":1033,"y":287,"pressure":0.5},{"x":1029,"y":286,"pressure":0.5},{"x":1025,"y":285,"pressure":0.5},{"x":1022,"y":285,"pressure":0.5},{"x":1015,"y":285,"pressure":0.5},{"x":1011,"y":286,"pressure":0.5},{"x":1008,"y":288,"pressure":0.5},{"x":1003,"y":291,"pressure":0.5},{"x":998,"y":298,"pressure":0.5},{"x":996,"y":304,"pressure":0.5},{"x":996,"y":311,"pressure":0.5},{"x":996,"y":314,"pressure":0.5},{"x":997,"y":317,"pressure":0.5},{"x":998,"y":321,"pressure":0.5},{"x":1001,"y":329,"pressure":0.5},{"x":1006,"y":336,"pressure":0.5},{"x":1010,"y":340,"pressure":0.5},{"x":1020,"y":349,"pressure":0.5},{"x":1033,"y":357,"pressure":0.5},{"x":1039,"y":361,"pressure":0.5},{"x":1053,"y":370,"pressure":0.5},{"x":1075,"y":387,"pressure":0.5},{"x":1082,"y":393,"pressure":0.5},{"x":1087,"y":398,"pressure":0.5},{"x":1092,"y":403,"pressure":0.5},{"x":1096,"y":409,"pressure":0.5},{"x":1100,"y":415,"pressure":0.5},{"x":1106,"y":427,"pressure":0.5},{"x":1110,"y":441,"pressure":0.5},{"x":1112,"y":454,"pressure":0.5},{"x":1114,"y":460,"pressure":0.5},{"x":1118,"y":473,"pressure":0.5},{"x":1122,"y":485,"pressure":0.5},{"x":1123,"y":492,"pressure":0.5},{"x":1126,"y":503,"pressure":0.5},{"x":1127,"y":512,"pressure":0.5},{"x":1128,"y":521,"pressure":0.5},{"x":1128,"y":525,"pressure":0.5},{"x":1125,"y":528,"pressure":0.5},{"x":1123,"y":530,"pressure":0.5},{"x":1117,"y":533,"pressure":0.5},{"x":1106,"y":536,"pressure":0.5},{"x":1099,"y":537,"pressure":0.5},{"x":1090,"y":538,"pressure":0.5},{"x":1082,"y":539,"pressure":0.5},{"x":1065,"y":538,"pressure":0.5},{"x":1058,"y":538,"pressure":0.5},{"x":1043,"y":535,"pressure":0.5},{"x":1029,"y":532,"pressure":0.5},{"x":1017,"y":527,"pressure":0.5},{"x":1012,"y":523,"pressure":0.5},{"x":1003,"y":514,"pressure":0.5},{"x":996,"y":501,"pressure":0.5},{"x":994,"y":494,"pressure":0.5},{"x":991,"y":482,"pressure":0.5},{"x":992,"y":472,"pressure":0.5},{"x":993,"y":467,"pressure":0.5},{"x":994,"y":462,"pressure":0.5},{"x":996,"y":458,"pressure":0.5},{"x":1002,"y":449,"pressure":0.5},{"x":1009,"y":439,"pressure":0.5},{"x":1013,"y":434,"pressure":0.5},{"x":1022,"y":425,"pressure":0.5},{"x":1032,"y":418,"pressure":0.5},{"x":1037,"y":416,"pressure":0.5},{"x":1047,"y":412,"pressure":0.5},{"x":1059,"y":409,"pressure":0.5},{"x":1064,"y":408,"pressure":0.5},{"x":1070,"y":407,"pressure":0.5},{"x":1075,"y":406,"pressure":0.5},{"x":1085,"y":403,"pressure":0.5},{"x":1093,"y":399,"pressure":0.5},{"x":1097,"y":397,"pressure":0.5},{"x":1105,"y":388,"pressure":0.5},{"x":1112,"y":378,"pressure":0.5},{"x":1115,"y":373,"pressure":0.5},{"x":1121,"y":357,"pressure":0.5},{"x":1126,"y":338,"pressure":0.5},{"x":1129,"y":330,"pressure":0.5},{"x":1131,"y":322,"pressure":0.5}],"property":{"strokeWidth":5,"strokeMultiplier":10,"color":4294967295,"fill":false,"type":"pen"},"type":"pen"},{"layer":"","firstPosition":{"x":605,"y":96},"secondPosition":{"x":1223,"y":601},"property":{"strokeWidth":5,"shape":{"fillColor":0,"topLeftCornerRadius":0,"topRightCornerRadius":0,"bottomLeftCornerRadius":0,"bottomRightCornerRadius":0,"type":"rectangle"},"color":4294967295,"type":"shape"},"type":"shape"}],"background":{"boxWidth":20,"boxHeight":20,"boxXCount":1,"boxYCount":1,"boxXSpace":0,"boxYSpace":0,"boxXColor":4278190335,"boxYColor":4294901760,"boxColor":4278190080,"boxXStroke":0.5,"boxYStroke":0.5,"type":"box"},"palettes":[{"name":"Standardpalette","colors":[4294967295,4293467747,4294198070,4294940672,4294951175,4294961979,4291681337,4283215696,4278228616,4278238420,4278430196,4280391411,4282339765,4284513675,4288423856,4286141768,4288585374,4278190080]},{"name":"Hervorhebung","colors":[1090519039,1089019491,1089749814,1090492416,1090502919,1090513723,1087233081,1078767440,1073780360,1073790164,1073981940,1075943155,1077891509,1080065419,1083975600,1081693512,1084137118,1073741824]}],"waypoints":[{"name":"Waypoint 1","position":{"x":-217.8955078125,"y":-432.262939453125},"scale":1}],"areas":[{"name":"Fläche 1","width":769,"height":485,"position":{"x":574,"y":126}}],"exportPresets":[],"packs":[],"createdAt":"2023-10-25T18:56:37.806","updatedAt":null,"painters":[{"name":"","includeEraser":false,"type":"hand"},{"name":"","zoomDependent":false,"property":{"strokeWidth":5,"strokeMultiplier":10,"color":4294967295,"fill":false,"type":"pen"},"type":"pen"},{"name":"","strokeWidth":5,"includeEraser":false,"deleteWholeStroke":false,"type":"pathEraser"},{"name":"","type":"undo"},{"name":"","type":"redo"},{"name":"","constrainedWidth":0,"constrainedHeight":0,"constrainedAspectRatio":0,"askForName":false,"type":"area"},{"name":"","strokeWidth":5,"layer":"","includeEraser":false,"type":"layer"},{"name":"","zoomDependent":false,"constrainedWidth":0,"constrainedHeight":0,"constrainedAspectRatio":0,"property":{"strokeWidth":5,"shape":{"fillColor":0,"topLeftCornerRadius":0,"topRightCornerRadius":0,"bottomLeftCornerRadius":0,"bottomRightCornerRadius":0,"type":"rectangle"},"color":4294967295,"type":"shape"},"type":"shape"},{"name":"","pack":"","component":0,"type":"stamp"},{"name":"","duration":5,"strokeWidth":5,"strokeMultiplier":10,"color":4294901760,"type":"laser"}],"tool":{"gridColor":0,"gridXSize":20,"gridYSize":20},"fileVersion":6,"type":"document"}
34 changes: 34 additions & 0 deletions api/test/migration_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:io';

import 'package:butterfly_api/butterfly_api.dart';
import 'package:test/test.dart';

void main() {
group('Document migration', () {
test('Migrate from v1', () async {
final bytes = await File('test/assets/document_v1.bfly').readAsBytes();
final data = NoteData.fromData(bytes);
expect(data.getPages().length, 1);

final page = data.getPage();
expect(page, isNotNull);
expect(page!.content.length, 2);
expect(page.content[0], isA<PathElement>());
expect(page.content[1], isA<ShapeElement>());

final info = data.getInfo();
expect(info, isNotNull);
expect(info!.tools.length, 10);
expect(info.tools[0], isA<SelectTool>());
expect(info.tools[1], isA<PenTool>());
expect(info.tools[2], isA<PathEraserTool>());
expect(info.tools[3], isA<UndoTool>());
expect(info.tools[4], isA<RedoTool>());
expect(info.tools[5], isA<AreaTool>());
expect(info.tools[6], isA<LayerTool>());
expect(info.tools[7], isA<ShapeTool>());
expect(info.tools[8], isA<StampTool>());
expect(info.tools[9], isA<LaserTool>());
});
});
}
Binary file removed app/Templates/Dark.bfly
Binary file not shown.
Binary file removed app/Templates/Light.bfly
Binary file not shown.
3 changes: 2 additions & 1 deletion fastlane/metadata/android/en-US/changelogs/76.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Add name to hand tool selection
* Change remote button dropdown to material 3
* Allow more valid file names
* Fix home page header
* Fix home page header ([#510](https://github.com/LinwoodDev/Butterfly/issues/510))
* Fix offset in scaling multiple elements ([#506](https://github.com/LinwoodDev/Butterfly/issues/506))
* Fix opening animation in zoom view
* Fix broken legacy file migrator

View all changes in the blog: https://linwood.dev/butterfly/2.0.0-beta.12

0 comments on commit 1207a0b

Please sign in to comment.