Skip to content

Commit 22fb72a

Browse files
authored
Merge pull request #28 from RZEROSTERN/copilot/sub-pr-27
Address PR review: custom typeRegistry test, CI Flutter version pin, example pubspec material design flag
2 parents 4f7aba0 + bd2aed1 commit 22fb72a

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515

1616
- uses: subosito/flutter-action@v2
1717
with:
18+
flutter-version: '3.41.5'
1819
channel: stable
1920

2021
- name: Install dependencies

example/pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ dependencies:
1111
sdk: flutter
1212
editorjs_flutter:
1313
path: ../
14+
15+
flutter:
16+
uses-material-design: true

test/unit/editor_controller_test.dart

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,39 @@ void main() {
253253
});
254254

255255
test('respects custom typeRegistry parameter', () {
256-
// Using default registry — header should be parsed
257256
const json =
258257
'{"blocks":[{"type":"header","data":{"text":"Hi","level":1}}]}';
259-
final ctrl = EditorController.fromJson(json);
258+
259+
// Custom registry that alters how header blocks are created
260+
final customRegistry = BlockTypeRegistry()
261+
..register(_PrefixedHeaderMapper('Custom: '));
262+
263+
final ctrl = EditorController.fromJson(
264+
json,
265+
typeRegistry: customRegistry,
266+
);
267+
260268
expect(ctrl.blockCount, 1);
269+
expect(ctrl.blocks.first, isA<HeaderBlock>());
270+
final headerBlock = ctrl.blocks.first as HeaderBlock;
271+
expect(headerBlock.text, 'Custom: Hi');
272+
expect(headerBlock.level, 1);
261273
});
262274
});
263275
}
276+
277+
/// A [BlockMapper] that prefixes header text — used to verify custom
278+
/// registries are respected by [EditorController.fromJson].
279+
class _PrefixedHeaderMapper implements BlockMapper<HeaderBlock> {
280+
final String prefix;
281+
const _PrefixedHeaderMapper(this.prefix);
282+
283+
@override
284+
String get supportedType => 'header';
285+
286+
@override
287+
HeaderBlock fromJson(Map<String, dynamic> data) => HeaderBlock(
288+
text: '$prefix${data['text'] ?? ''}',
289+
level: data['level'] is int ? data['level'] as int : 1,
290+
);
291+
}

0 commit comments

Comments
 (0)