Skip to content

Commit

Permalink
test: filter+calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
Xazin committed Oct 9, 2024
1 parent 8cf683e commit 61b6629
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:flutter/services.dart';

import 'package:appflowy/plugins/database/grid/presentation/widgets/filter/choicechip/number.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pbenum.dart';
import 'package:flutter/services.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

Expand All @@ -19,9 +22,6 @@ void main() {

// Change one Field to Number
await tester.changeFieldTypeOfFieldWithName('Type', FieldType.Number);

expect(find.text('Calculate'), findsOneWidget);

await tester.changeCalculateAtIndex(1, CalculationType.Sum);

// Enter values in cells
Expand Down Expand Up @@ -55,7 +55,7 @@ void main() {
await tester.changeFieldTypeOfFieldWithName('Type', FieldType.Number);
await tester.changeFieldTypeOfFieldWithName('Done', FieldType.Number);

expect(find.text('Calculate'), findsNWidgets(2));
expect(find.text('Calculate'), findsNWidgets(3));

await tester.changeCalculateAtIndex(1, CalculationType.Sum);
await tester.changeCalculateAtIndex(2, CalculationType.Min);
Expand Down Expand Up @@ -103,5 +103,104 @@ void main() {
expect(find.text('150'), findsNWidgets(2));
expect(find.text('100'), findsNWidgets(2));
});

testWidgets('Calculations with filter', (tester) async {
await tester.initializeAppFlowy();
await tester.tapAnonymousSignInButton();

await tester.createNewPageWithNameUnderParent(layout: ViewLayoutPB.Grid);

// Change two Fields to Number
await tester.changeFieldTypeOfFieldWithName('Type', FieldType.Number);
await tester.changeFieldTypeOfFieldWithName('Done', FieldType.Number);

expect(find.text('Calculate'), findsNWidgets(3));

await tester.changeCalculateAtIndex(1, CalculationType.Sum);
await tester.changeCalculateAtIndex(2, CalculationType.Min);

// Enter values in cells
await tester.editCell(
rowIndex: 0,
fieldType: FieldType.Number,
input: '100',
);
await tester.editCell(
rowIndex: 1,
fieldType: FieldType.Number,
input: '150',
);
await tester.editCell(
rowIndex: 2,
fieldType: FieldType.Number,
input: '100',
);
await tester.editCell(
rowIndex: 0,
fieldType: FieldType.Number,
input: '150',
cellIndex: 1,
);
await tester.editCell(
rowIndex: 1,
fieldType: FieldType.Number,
input: '100',
cellIndex: 1,
);
await tester.editCell(
rowIndex: 2,
fieldType: FieldType.Number,
input: '50',
cellIndex: 1,
);
await tester.pumpAndSettle();

// Dismiss edit cell
await tester.sendKeyDownEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle(const Duration(seconds: 1));

// Expect sum to be 100 + 150 + 100 = 350
expect(find.text('350'), findsOneWidget);

// Expect min to be 50
expect(find.text('50'), findsNWidgets(2));

await tester.tapDatabaseFilterButton();
await tester.tapCreateFilterByFieldType(FieldType.Number, 'Type');
await tester.pumpAndSettle();

await tester.tap(find.byType(NumberFilterChoiceChip));
await tester.pumpAndSettle();

await tester.enterText(
find.descendant(
of: find.byType(NumberFilterEditor),
matching: find.byType(FlowyTextField),
),
'100',
);
await tester.pumpAndSettle(const Duration(seconds: 2));

// Expect the sum to be 100+100 = 200
expect(find.text('200'), findsOneWidget);

// Expect the min to be 50
expect(find.text('50'), findsNWidgets(2));

await tester.enterText(
find.descendant(
of: find.byType(NumberFilterEditor),
matching: find.byType(FlowyTextField),
),
'150',
);
await tester.pumpAndSettle(const Duration(seconds: 2));

// Expect the sum to be 150 (3 times, text field, cell, and calculate cell)
expect(find.text('150'), findsNWidgets(3));

// Expect the min to be 100
expect(find.text('100'), findsNWidgets(2));
});
});
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:integration_test/integration_test.dart';

import 'desktop/document/document_test_runner_2.dart' as document_test_runner_2;
import 'desktop/grid/grid_calculations_test.dart' as grid_calculations_test;
import 'desktop/uncategorized/empty_test.dart' as first_test;

Future<void> main() async {
Expand All @@ -14,4 +15,5 @@ Future<void> runIntegration4OnDesktop() async {
first_test.main();

document_test_runner_2.main();
grid_calculations_test.main();
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:flutter/material.dart';

import 'package:appflowy/plugins/database/application/calculations/calculation_type_ext.dart';
import 'package:appflowy/plugins/database/application/field/field_info.dart';
import 'package:appflowy/plugins/database/application/field/type_option/number_format_bloc.dart';
Expand All @@ -13,7 +15,6 @@ import 'package:appflowy_backend/protobuf/flowy-database2/number_entities.pb.dar
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class CalculateCell extends StatefulWidget {
Expand Down Expand Up @@ -126,7 +127,7 @@ class _CalculateCellState extends State<CalculateCell> {
}

Widget _showCalculateValue(BuildContext context, String? prefix) {
prefix = prefix != null ? '$prefix ' : '';
prefix = prefix != null && prefix.isNotEmpty ? '$prefix ' : '';
final calculateValue =
'$prefix${_withoutTrailingZeros(widget.calculation!.value)}';

Expand Down

0 comments on commit 61b6629

Please sign in to comment.