Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
bosskmk committed Dec 2, 2022
2 parents 07db5ab + ca7b6d3 commit 5a18b12
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [5.4.7] - 2022. 12. 2

* Fix sorting bug.
Fixed sorting issue with pagination applied.
https://github.com/bosskmk/pluto_grid/issues/668

## [5.4.6] - 2022. 11. 30

* Fix keepAlive.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## PlutoGrid for flutter - v5.4.6
## PlutoGrid for flutter - v5.4.7

[![Awesome Flutter](https://img.shields.io/badge/Awesome-Flutter-blue.svg)](https://github.com/Solido/awesome-flutter)
[![codecov](https://codecov.io/gh/bosskmk/pluto_grid/branch/master/graph/badge.svg)](https://codecov.io/gh/bosskmk/pluto_grid)
Expand Down
4 changes: 4 additions & 0 deletions lib/src/model/pluto_cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class PlutoCell {
return _value;
}

if (_needToApplyFormatOnInit) {
_applyFormatOnInit();
}

return _column!.type.makeCompareValue(_value);
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pluto_grid
description: PlutoGrid is a dataGrid that can be controlled by the keyboard on desktop and web. Of course, it works well on Android and IOS. (DataGrid, DataTable, Data Grid, Data Table, Sticky)
version: 5.4.6
version: 5.4.7
homepage: https://pluto.weblaze.dev
repository: https://github.com/bosskmk/pluto_grid

Expand Down
231 changes: 231 additions & 0 deletions test/scenario/paginate_rows/sorting_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluto_grid/pluto_grid.dart';
import 'package:pluto_grid/src/ui/pluto_base_cell.dart';

void main() {
late PlutoGridStateManager stateManager;

late List<PlutoColumn> columns;

late List<PlutoRow> rows;

Future<void> buildGrid(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Material(
child: PlutoGrid(
columns: columns,
rows: rows,
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
},
createFooter: (s) {
s.setPageSize(3);
return PlutoPagination(s);
},
),
),
));
}

Future<List<PlutoBaseCell>> getCells(WidgetTester tester, {int? page}) async {
if (page != null) {
await tester.tap(find.text('$page'));
await tester.pump();
}

final cells = find
.byType(PlutoBaseCell)
.evaluate()
.map((e) => e.widget)
.cast<PlutoBaseCell>()
.toList();

return cells;
}

group('date 컬럼 정렬.', () {
setUp(() {
columns = [
PlutoColumn(
title: 'date',
field: 'date',
type: PlutoColumnType.date(format: 'dd/MM/yyyy'),
),
];

rows = [
PlutoRow(cells: {'date': PlutoCell(value: DateTime(2022, 4, 1))}),
PlutoRow(cells: {'date': PlutoCell(value: DateTime(2022, 2, 10))}),
PlutoRow(cells: {'date': PlutoCell(value: DateTime(2022, 2, 2))}),
PlutoRow(cells: {'date': PlutoCell(value: DateTime(2022, 2, 3))}),
PlutoRow(cells: {'date': PlutoCell(value: DateTime(2022, 4, 3))}),
PlutoRow(cells: {'date': PlutoCell(value: DateTime(2022, 3, 1))}),
PlutoRow(cells: {'date': PlutoCell(value: DateTime(2022, 5, 1))}),
PlutoRow(cells: {'date': PlutoCell(value: DateTime(2022, 1, 20))}),
PlutoRow(cells: {'date': PlutoCell(value: DateTime(2022, 8, 2))}),
PlutoRow(cells: {'date': PlutoCell(value: DateTime(2022, 8, 1))}),
];
});

group('컬럼을 탭하여 정렬.', () {
testWidgets('dd/MM/yyyy 포멧이 적용되어 ascending 정렬 되어야 한다.', (tester) async {
await buildGrid(tester);
await tester.tap(find.text('date'));
await tester.pump();

final List<PlutoBaseCell> cells = [];

cells.addAll(await getCells(tester));
cells.addAll(await getCells(tester, page: 2));
cells.addAll(await getCells(tester, page: 3));
cells.addAll(await getCells(tester, page: 4));

expect(cells.length, 10);
expect(cells[0].cell.value, '20/01/2022');
expect(cells[1].cell.value, '02/02/2022');
expect(cells[2].cell.value, '03/02/2022');
expect(cells[3].cell.value, '10/02/2022');
expect(cells[4].cell.value, '01/03/2022');
expect(cells[5].cell.value, '01/04/2022');
expect(cells[6].cell.value, '03/04/2022');
expect(cells[7].cell.value, '01/05/2022');
expect(cells[8].cell.value, '01/08/2022');
expect(cells[9].cell.value, '02/08/2022');
});

testWidgets('dd/MM/yyyy 포멧이 적용되어 descending 정렬 되어야 한다.', (tester) async {
await buildGrid(tester);
await tester.tap(find.text('date'));
await tester.tap(find.text('date')); // descending
await tester.pump();

final List<PlutoBaseCell> cells = [];

cells.addAll(await getCells(tester));
cells.addAll(await getCells(tester, page: 2));
cells.addAll(await getCells(tester, page: 3));
cells.addAll(await getCells(tester, page: 4));

expect(cells.length, 10);
expect(cells[0].cell.value, '02/08/2022');
expect(cells[1].cell.value, '01/08/2022');
expect(cells[2].cell.value, '01/05/2022');
expect(cells[3].cell.value, '03/04/2022');
expect(cells[4].cell.value, '01/04/2022');
expect(cells[5].cell.value, '01/03/2022');
expect(cells[6].cell.value, '10/02/2022');
expect(cells[7].cell.value, '03/02/2022');
expect(cells[8].cell.value, '02/02/2022');
expect(cells[9].cell.value, '20/01/2022');
});

testWidgets('dd/MM/yyyy 포멧이 적용되어 descending 후 다시 원래 순서로 정렬 되어야 한다.',
(tester) async {
await buildGrid(tester);
await tester.tap(find.text('date'));
await tester.tap(find.text('date')); // descending
await tester.tap(find.text('date')); // none
await tester.pump();

final List<PlutoBaseCell> cells = [];

cells.addAll(await getCells(tester));
cells.addAll(await getCells(tester, page: 2));
cells.addAll(await getCells(tester, page: 3));
cells.addAll(await getCells(tester, page: 4));

expect(cells.length, 10);
expect(cells[0].cell.value, '01/04/2022');
expect(cells[1].cell.value, '10/02/2022');
expect(cells[2].cell.value, '02/02/2022');
expect(cells[3].cell.value, '03/02/2022');
expect(cells[4].cell.value, '03/04/2022');
expect(cells[5].cell.value, '01/03/2022');
expect(cells[6].cell.value, '01/05/2022');
expect(cells[7].cell.value, '20/01/2022');
expect(cells[8].cell.value, '02/08/2022');
expect(cells[9].cell.value, '01/08/2022');
});
});

group('stateManager 로 정렬.', () {
testWidgets('dd/MM/yyyy 포멧이 적용되어 ascending 정렬 되어야 한다.', (tester) async {
await buildGrid(tester);
stateManager.sortAscending(stateManager.columns.first);
await tester.pump();

final List<PlutoBaseCell> cells = [];

cells.addAll(await getCells(tester));
cells.addAll(await getCells(tester, page: 2));
cells.addAll(await getCells(tester, page: 3));
cells.addAll(await getCells(tester, page: 4));

expect(cells.length, 10);
expect(cells[0].cell.value, '20/01/2022');
expect(cells[1].cell.value, '02/02/2022');
expect(cells[2].cell.value, '03/02/2022');
expect(cells[3].cell.value, '10/02/2022');
expect(cells[4].cell.value, '01/03/2022');
expect(cells[5].cell.value, '01/04/2022');
expect(cells[6].cell.value, '03/04/2022');
expect(cells[7].cell.value, '01/05/2022');
expect(cells[8].cell.value, '01/08/2022');
expect(cells[9].cell.value, '02/08/2022');
});

testWidgets('dd/MM/yyyy 포멧이 적용되어 descending 정렬 되어야 한다.', (tester) async {
await buildGrid(tester);
stateManager.sortDescending(stateManager.columns.first);
await tester.pump();

final List<PlutoBaseCell> cells = [];

cells.addAll(await getCells(tester));
cells.addAll(await getCells(tester, page: 2));
cells.addAll(await getCells(tester, page: 3));
cells.addAll(await getCells(tester, page: 4));

expect(cells.length, 10);
expect(cells[0].cell.value, '02/08/2022');
expect(cells[1].cell.value, '01/08/2022');
expect(cells[2].cell.value, '01/05/2022');
expect(cells[3].cell.value, '03/04/2022');
expect(cells[4].cell.value, '01/04/2022');
expect(cells[5].cell.value, '01/03/2022');
expect(cells[6].cell.value, '10/02/2022');
expect(cells[7].cell.value, '03/02/2022');
expect(cells[8].cell.value, '02/02/2022');
expect(cells[9].cell.value, '20/01/2022');
});

testWidgets('dd/MM/yyyy 포멧이 적용되어 descending 후 다시 원래 순서로 정렬 되어야 한다.',
(tester) async {
await buildGrid(tester);
stateManager.sortDescending(stateManager.columns.first);
stateManager.toggleSortColumn(stateManager.columns.first);
await tester.pump();

final List<PlutoBaseCell> cells = [];

cells.addAll(await getCells(tester));
cells.addAll(await getCells(tester, page: 2));
cells.addAll(await getCells(tester, page: 3));
cells.addAll(await getCells(tester, page: 4));

expect(cells.length, 10);
expect(cells[0].cell.value, '01/04/2022');
expect(cells[1].cell.value, '10/02/2022');
expect(cells[2].cell.value, '02/02/2022');
expect(cells[3].cell.value, '03/02/2022');
expect(cells[4].cell.value, '03/04/2022');
expect(cells[5].cell.value, '01/03/2022');
expect(cells[6].cell.value, '01/05/2022');
expect(cells[7].cell.value, '20/01/2022');
expect(cells[8].cell.value, '02/08/2022');
expect(cells[9].cell.value, '01/08/2022');
});
});
});
}

0 comments on commit 5a18b12

Please sign in to comment.