mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-07-18 22:46:57 +00:00

* feat: initial calculation controller * fix: entities * feat: calculations * fix: review comments and support floats * fix: abstract business logic into calculations service * fix: clean calculation entities after merge * feat: react to changes to row/cell/field_type * chore: changes after merging main * feat: handle delete field * test: add grid calculations tests * fix: add validation + format numbers * refactor: get cell number * chore: bump collab * chore: fix clippy * chore: update docs * chore: update docs * chore: fmt * chore: fix flutter * chore: collab rev * fix: cleanup and hover to show * fix: localization * test: add basic rust test * fix: clippy * fix: support updating calculation on duplicate row --------- Co-authored-by: nathan <nathan@appflowy.io>
108 lines
3.1 KiB
Dart
108 lines
3.1 KiB
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:flutter_test/flutter_test.dart';
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
import '../util/database_test_op.dart';
|
|
import '../util/util.dart';
|
|
|
|
void main() {
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
group('Grid Calculations', () {
|
|
testWidgets('add calculation and update cell', (tester) async {
|
|
await tester.initializeAppFlowy();
|
|
await tester.tapGoButton();
|
|
|
|
await tester.createNewPageWithNameUnderParent(layout: ViewLayoutPB.Grid);
|
|
|
|
// 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
|
|
await tester.editCell(
|
|
rowIndex: 0,
|
|
fieldType: FieldType.Number,
|
|
input: '100',
|
|
);
|
|
|
|
await tester.editCell(
|
|
rowIndex: 1,
|
|
fieldType: FieldType.Number,
|
|
input: '100',
|
|
);
|
|
|
|
// Dismiss edit cell
|
|
await tester.sendKeyDownEvent(LogicalKeyboardKey.enter);
|
|
|
|
await tester.pumpAndSettle(const Duration(seconds: 1));
|
|
|
|
expect(find.text('200'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('add calculations and remove row', (tester) async {
|
|
await tester.initializeAppFlowy();
|
|
await tester.tapGoButton();
|
|
|
|
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(2));
|
|
|
|
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: 0,
|
|
fieldType: FieldType.Number,
|
|
input: '50',
|
|
cellIndex: 1,
|
|
);
|
|
await tester.editCell(
|
|
rowIndex: 1,
|
|
fieldType: FieldType.Number,
|
|
input: '100',
|
|
cellIndex: 1,
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
// Dismiss edit cell
|
|
await tester.sendKeyDownEvent(LogicalKeyboardKey.enter);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('250'), findsOneWidget);
|
|
expect(find.text('50'), findsNWidgets(2));
|
|
|
|
// Delete 1st row
|
|
await tester.hoverOnFirstRowOfGrid();
|
|
await tester.tapRowMenuButtonInGrid();
|
|
await tester.tapDeleteOnRowMenu();
|
|
|
|
await tester.pumpAndSettle(const Duration(seconds: 1));
|
|
|
|
expect(find.text('150'), findsNWidgets(2));
|
|
expect(find.text('100'), findsNWidgets(2));
|
|
});
|
|
});
|
|
}
|