diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa66287..e0ed498 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,7 @@ jobs: - uses: subosito/flutter-action@v2 with: + flutter-version: '3.41.5' channel: stable - name: Install dependencies diff --git a/example/pubspec.yaml b/example/pubspec.yaml index fc650fb..0200ead 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -11,3 +11,6 @@ dependencies: sdk: flutter editorjs_flutter: path: ../ + +flutter: + uses-material-design: true diff --git a/test/unit/editor_controller_test.dart b/test/unit/editor_controller_test.dart index ddea793..8a065d8 100644 --- a/test/unit/editor_controller_test.dart +++ b/test/unit/editor_controller_test.dart @@ -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()); + 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 { + final String prefix; + const _PrefixedHeaderMapper(this.prefix); + + @override + String get supportedType => 'header'; + + @override + HeaderBlock fromJson(Map data) => HeaderBlock( + text: '$prefix${data['text'] ?? ''}', + level: data['level'] is int ? data['level'] as int : 1, + ); +}