|
@@ -12,38 +12,42 @@ void main() {
|
|
late AppFlowyUnitTest test;
|
|
late AppFlowyUnitTest test;
|
|
late AppPB app;
|
|
late AppPB app;
|
|
late AppBloc appBloc;
|
|
late AppBloc appBloc;
|
|
- late List<ViewPB> allViews;
|
|
|
|
|
|
+ late TrashBloc trashBloc;
|
|
setUpAll(() async {
|
|
setUpAll(() async {
|
|
test = await AppFlowyUnitTest.ensureInitialized();
|
|
test = await AppFlowyUnitTest.ensureInitialized();
|
|
-
|
|
|
|
- /// Create a new app with three documents
|
|
|
|
- app = await test.createTestApp();
|
|
|
|
- appBloc = AppBloc(app: app)
|
|
|
|
- ..add(const AppEvent.initial())
|
|
|
|
- ..add(AppEvent.createView(
|
|
|
|
- "Document 1",
|
|
|
|
- DocumentPluginBuilder(),
|
|
|
|
- ))
|
|
|
|
- ..add(AppEvent.createView(
|
|
|
|
- "Document 2",
|
|
|
|
- DocumentPluginBuilder(),
|
|
|
|
- ))
|
|
|
|
- ..add(
|
|
|
|
- AppEvent.createView(
|
|
|
|
- "Document 3",
|
|
|
|
- DocumentPluginBuilder(),
|
|
|
|
- ),
|
|
|
|
- );
|
|
|
|
- await blocResponseFuture(millisecond: 200);
|
|
|
|
- allViews = [...appBloc.state.app.belongings.items];
|
|
|
|
- assert(allViews.length == 3);
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ // 1. Create three views
|
|
|
|
+ // 2. Delete a view and check the state
|
|
|
|
+ // 3. Delete all views and check the state
|
|
|
|
+ // 4. Put back a view
|
|
|
|
+ // 5. Put back all views
|
|
group('$TrashBloc', () {
|
|
group('$TrashBloc', () {
|
|
- late TrashBloc trashBloc;
|
|
|
|
late ViewPB deletedView;
|
|
late ViewPB deletedView;
|
|
-
|
|
|
|
- setUpAll(() {});
|
|
|
|
|
|
+ late List<ViewPB> allViews;
|
|
|
|
+ setUpAll(() async {
|
|
|
|
+ /// Create a new app with three documents
|
|
|
|
+ app = await test.createTestApp();
|
|
|
|
+ appBloc = AppBloc(app: app)
|
|
|
|
+ ..add(const AppEvent.initial())
|
|
|
|
+ ..add(AppEvent.createView(
|
|
|
|
+ "Document 1",
|
|
|
|
+ DocumentPluginBuilder(),
|
|
|
|
+ ))
|
|
|
|
+ ..add(AppEvent.createView(
|
|
|
|
+ "Document 2",
|
|
|
|
+ DocumentPluginBuilder(),
|
|
|
|
+ ))
|
|
|
|
+ ..add(
|
|
|
|
+ AppEvent.createView(
|
|
|
|
+ "Document 3",
|
|
|
|
+ DocumentPluginBuilder(),
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ await blocResponseFuture(millisecond: 200);
|
|
|
|
+ allViews = [...appBloc.state.app.belongings.items];
|
|
|
|
+ assert(allViews.length == 3);
|
|
|
|
+ });
|
|
|
|
|
|
setUp(() async {
|
|
setUp(() async {
|
|
trashBloc = TrashBloc()..add(const TrashEvent.initial());
|
|
trashBloc = TrashBloc()..add(const TrashEvent.initial());
|
|
@@ -51,7 +55,7 @@ void main() {
|
|
});
|
|
});
|
|
|
|
|
|
blocTest<TrashBloc, TrashState>(
|
|
blocTest<TrashBloc, TrashState>(
|
|
- "delete view",
|
|
|
|
|
|
+ "delete a view",
|
|
build: () => trashBloc,
|
|
build: () => trashBloc,
|
|
act: (bloc) async {
|
|
act: (bloc) async {
|
|
deletedView = appBloc.state.app.belongings.items[0];
|
|
deletedView = appBloc.state.app.belongings.items[0];
|
|
@@ -82,7 +86,7 @@ void main() {
|
|
},
|
|
},
|
|
);
|
|
);
|
|
blocTest<TrashBloc, TrashState>(
|
|
blocTest<TrashBloc, TrashState>(
|
|
- "put back",
|
|
|
|
|
|
+ "put back a trash",
|
|
build: () => trashBloc,
|
|
build: () => trashBloc,
|
|
act: (bloc) async {
|
|
act: (bloc) async {
|
|
bloc.add(TrashEvent.putback(allViews[0].id));
|
|
bloc.add(TrashEvent.putback(allViews[0].id));
|
|
@@ -94,7 +98,7 @@ void main() {
|
|
},
|
|
},
|
|
);
|
|
);
|
|
blocTest<TrashBloc, TrashState>(
|
|
blocTest<TrashBloc, TrashState>(
|
|
- "put back all",
|
|
|
|
|
|
+ "put back all trash",
|
|
build: () => trashBloc,
|
|
build: () => trashBloc,
|
|
act: (bloc) async {
|
|
act: (bloc) async {
|
|
bloc.add(const TrashEvent.restoreAll());
|
|
bloc.add(const TrashEvent.restoreAll());
|
|
@@ -107,4 +111,69 @@ void main() {
|
|
);
|
|
);
|
|
//
|
|
//
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+ // 1. Create three views
|
|
|
|
+ // 2. Delete a trash permanently and check the state
|
|
|
|
+ // 3. Delete all views permanently
|
|
|
|
+ group('$TrashBloc', () {
|
|
|
|
+ setUpAll(() async {
|
|
|
|
+ /// Create a new app with three documents
|
|
|
|
+ app = await test.createTestApp();
|
|
|
|
+ appBloc = AppBloc(app: app)
|
|
|
|
+ ..add(const AppEvent.initial())
|
|
|
|
+ ..add(AppEvent.createView(
|
|
|
|
+ "Document 1",
|
|
|
|
+ DocumentPluginBuilder(),
|
|
|
|
+ ))
|
|
|
|
+ ..add(AppEvent.createView(
|
|
|
|
+ "Document 2",
|
|
|
|
+ DocumentPluginBuilder(),
|
|
|
|
+ ))
|
|
|
|
+ ..add(
|
|
|
|
+ AppEvent.createView(
|
|
|
|
+ "Document 3",
|
|
|
|
+ DocumentPluginBuilder(),
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ await blocResponseFuture(millisecond: 200);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ setUp(() async {
|
|
|
|
+ trashBloc = TrashBloc()..add(const TrashEvent.initial());
|
|
|
|
+ await blocResponseFuture();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ blocTest<TrashBloc, TrashState>(
|
|
|
|
+ "delete a view permanently",
|
|
|
|
+ build: () => trashBloc,
|
|
|
|
+ act: (bloc) async {
|
|
|
|
+ final view = appBloc.state.app.belongings.items[0];
|
|
|
|
+ appBloc.add(AppEvent.deleteView(view.id));
|
|
|
|
+ await blocResponseFuture();
|
|
|
|
+
|
|
|
|
+ trashBloc.add(TrashEvent.delete(trashBloc.state.objects[0]));
|
|
|
|
+ },
|
|
|
|
+ wait: blocResponseDuration(),
|
|
|
|
+ verify: (bloc) {
|
|
|
|
+ assert(appBloc.state.app.belongings.items.length == 2);
|
|
|
|
+ assert(bloc.state.objects.isEmpty);
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ blocTest<TrashBloc, TrashState>(
|
|
|
|
+ "delete all view permanently",
|
|
|
|
+ build: () => trashBloc,
|
|
|
|
+ act: (bloc) async {
|
|
|
|
+ for (final view in appBloc.state.app.belongings.items) {
|
|
|
|
+ appBloc.add(AppEvent.deleteView(view.id));
|
|
|
|
+ }
|
|
|
|
+ await blocResponseFuture();
|
|
|
|
+ trashBloc.add(const TrashEvent.deleteAll());
|
|
|
|
+ },
|
|
|
|
+ wait: blocResponseDuration(),
|
|
|
|
+ verify: (bloc) {
|
|
|
|
+ assert(appBloc.state.app.belongings.items.isEmpty);
|
|
|
|
+ assert(bloc.state.objects.isEmpty);
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ });
|
|
}
|
|
}
|