42 lines
1.4 KiB
Dart
42 lines
1.4 KiB
Dart
|
|
// test/note_background_test.dart
|
||
|
|
//
|
||
|
|
// Covers the NoteBackground template enum decode (back-compat: missing/unknown →
|
||
|
|
// blank) and the painter's shouldRepaint reacting to a background change.
|
||
|
|
|
||
|
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
|
||
|
|
import 'package:badnote/editor/canvas/note_background.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
group('noteBackgroundFromName', () {
|
||
|
|
test('decodes each enum name round-trip', () {
|
||
|
|
for (final b in NoteBackground.values) {
|
||
|
|
expect(noteBackgroundFromName(b.name), b);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('null → blank (back-compat for legacy sidecars)', () {
|
||
|
|
expect(noteBackgroundFromName(null), NoteBackground.blank);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('unknown name → blank (forward-compat)', () {
|
||
|
|
expect(noteBackgroundFromName('isometric'), NoteBackground.blank);
|
||
|
|
expect(noteBackgroundFromName(''), NoteBackground.blank);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
group('NoteBackgroundPainter.shouldRepaint', () {
|
||
|
|
test('repaints when the background changes', () {
|
||
|
|
const a = NoteBackgroundPainter(NoteBackground.blank);
|
||
|
|
const b = NoteBackgroundPainter(NoteBackground.dots);
|
||
|
|
expect(a.shouldRepaint(b), isTrue);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('does not repaint when the background is identical', () {
|
||
|
|
const a = NoteBackgroundPainter(NoteBackground.grid);
|
||
|
|
const b = NoteBackgroundPainter(NoteBackground.grid);
|
||
|
|
expect(a.shouldRepaint(b), isFalse);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|