Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:

- uses: subosito/flutter-action@v2
with:
flutter-version: '3.41.5'
channel: stable

- name: Install dependencies
Expand Down
3 changes: 3 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ dependencies:
sdk: flutter
editorjs_flutter:
path: ../

flutter:
uses-material-design: true
32 changes: 30 additions & 2 deletions test/unit/editor_controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,39 @@ void main() {
});

test('respects custom typeRegistry parameter', () {
// Using default registry — header should be parsed
const json =
'{"blocks":[{"type":"header","data":{"text":"Hi","level":1}}]}';
final ctrl = EditorController.fromJson(json);

// Custom registry that alters how header blocks are created
final customRegistry = BlockTypeRegistry()
..register(_PrefixedHeaderMapper('Custom: '));

final ctrl = EditorController.fromJson(
json,
typeRegistry: customRegistry,
);

expect(ctrl.blockCount, 1);
expect(ctrl.blocks.first, isA<HeaderBlock>());
final headerBlock = ctrl.blocks.first as HeaderBlock;
expect(headerBlock.text, 'Custom: Hi');
expect(headerBlock.level, 1);
});
});
}

/// A [BlockMapper] that prefixes header text — used to verify custom
/// registries are respected by [EditorController.fromJson].
class _PrefixedHeaderMapper implements BlockMapper<HeaderBlock> {
final String prefix;
const _PrefixedHeaderMapper(this.prefix);

@override
String get supportedType => 'header';

@override
HeaderBlock fromJson(Map<String, dynamic> data) => HeaderBlock(
text: '$prefix${data['text'] ?? ''}',
level: data['level'] is int ? data['level'] as int : 1,
);
}