feat(app): 添加 EditorBloc.LoadJournal event — 加载已有日记数据
- LoadJournal event: 原子加载 title/mood/tags/strokes/elements/lastSavedAt - _onLoadJournal handler: 不触发 auto-save (isDirty=false) - 单元测试: 验证 LoadJournal 正确还原所有状态字段 - mood_bloc: linter 补充 foundation.dart import
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:nuanji_app/data/models/journal_entry.dart';
|
||||
import 'package:nuanji_app/data/models/journal_element.dart';
|
||||
import 'package:nuanji_app/features/editor/bloc/editor_bloc.dart';
|
||||
import 'package:nuanji_app/features/editor/widgets/stroke_model.dart';
|
||||
@@ -262,5 +263,35 @@ void main() {
|
||||
|
||||
bloc.close();
|
||||
});
|
||||
|
||||
// ===== LoadJournal 原子加载 =====
|
||||
|
||||
test('LoadJournal 还原已有日记数据', () async {
|
||||
final strokes = [_testStroke(id: 's1')];
|
||||
final elements = [
|
||||
JournalElement.createSticker(
|
||||
journalId: 'j1',
|
||||
emoji: '😊',
|
||||
position: Offset.zero,
|
||||
),
|
||||
];
|
||||
|
||||
final state = await dispatch(LoadJournal(
|
||||
title: '测试日记',
|
||||
mood: Mood.happy,
|
||||
tags: const ['开心', '学校'],
|
||||
strokes: strokes,
|
||||
elements: elements,
|
||||
lastSavedAt: DateTime(2026, 6, 1),
|
||||
));
|
||||
|
||||
expect(state.title, '测试日记');
|
||||
expect(state.selectedMood, Mood.happy);
|
||||
expect(state.tags, ['开心', '学校']);
|
||||
expect(state.strokes.length, 1);
|
||||
expect(state.elements.length, 1);
|
||||
expect(state.lastSavedAt, DateTime(2026, 6, 1));
|
||||
expect(state.isDirty, isFalse, reason: 'LoadJournal 不应标记为 dirty');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user