mirror of
https://github.com/AppFlowy-IO/AppFlowy
synced 2026-05-23 17:18:31 +00:00
chore: add app bloc test (#1344)
* chore: add app bloc test * chore: add wait Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
parent
da3d575295
commit
5a6103f5d6
2 changed files with 39 additions and 0 deletions
|
|
@ -67,6 +67,34 @@ void main() {
|
|||
},
|
||||
);
|
||||
|
||||
group('$AppBloc', () {
|
||||
late AppPB app;
|
||||
setUpAll(() async {
|
||||
app = await test.createTestApp();
|
||||
});
|
||||
|
||||
blocTest<AppBloc, AppState>(
|
||||
"rename the app",
|
||||
build: () => AppBloc(app: app)..add(const AppEvent.initial()),
|
||||
wait: blocResponseDuration(),
|
||||
act: (bloc) => bloc.add(const AppEvent.rename('Hello world')),
|
||||
verify: (bloc) {
|
||||
assert(bloc.state.app.name == 'Hello world');
|
||||
},
|
||||
);
|
||||
|
||||
blocTest<AppBloc, AppState>(
|
||||
"delete the app",
|
||||
build: () => AppBloc(app: app)..add(const AppEvent.initial()),
|
||||
wait: blocResponseDuration(),
|
||||
act: (bloc) => bloc.add(const AppEvent.delete()),
|
||||
verify: (bloc) async {
|
||||
final apps = await test.loadApps();
|
||||
assert(apps.where((element) => element.id == app.id).isEmpty);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('$AppBloc', () {
|
||||
late ViewPB view;
|
||||
late AppPB app;
|
||||
|
|
@ -86,10 +114,12 @@ void main() {
|
|||
view = bloc.state.views.last;
|
||||
},
|
||||
);
|
||||
|
||||
blocTest<AppBloc, AppState>(
|
||||
"delete the document",
|
||||
build: () => AppBloc(app: app)..add(const AppEvent.initial()),
|
||||
act: (bloc) => bloc.add(AppEvent.deleteView(view.id)),
|
||||
wait: blocResponseDuration(),
|
||||
verify: (bloc) {
|
||||
assert(bloc.state.views.isEmpty);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -87,6 +87,15 @@ class AppFlowyUnitTest {
|
|||
(error) => throw Exception(error),
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<AppPB>> loadApps() async {
|
||||
final result = await workspaceService.getApps();
|
||||
|
||||
return result.fold(
|
||||
(apps) => apps,
|
||||
(error) => throw Exception(error),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _pathProviderInitialized() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue