Skip to content

Commit

Permalink
Merge pull request bosskmk#128 from bosskmk/develop
Browse files Browse the repository at this point in the history
Add tests.
  • Loading branch information
bosskmk authored Jan 16, 2021
2 parents a0491df + 017adfb commit 4e5776e
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.1.0] - 2021. 1. 16

* Add hide columns.

## [1.0.0] - 2020. 12. 30

* Class name change. Just like changing PlutoConfiguration to PlutoGridConfiguration, the word Grid was added in the middle.
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 - v1.0.0
## PlutoGrid for flutter - v1.1.0

[![codecov](https://codecov.io/gh/bosskmk/pluto_grid/branch/master/graph/badge.svg)](https://codecov.io/gh/bosskmk/pluto_grid)

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.0"
version: "1.1.0"
pluto_inside:
dependency: transitive
description:
Expand Down
10 changes: 5 additions & 5 deletions lib/src/manager/state/column_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ mixin ColumnState implements IPlutoGridState {
}

void showSetColumnsPopup(BuildContext context) {
const columnField = 'field';

var columns = [
PlutoColumn(
title: configuration.localeText.setColumnsTitle,
Expand All @@ -505,7 +507,7 @@ mixin ColumnState implements IPlutoGridState {
),
PlutoColumn(
title: 'column field',
field: 'field',
field: columnField,
type: PlutoColumnType.text(),
hide: true,
),
Expand All @@ -515,7 +517,7 @@ mixin ColumnState implements IPlutoGridState {
return PlutoRow(
cells: {
'title': PlutoCell(value: c.title),
'field': PlutoCell(value: c.field),
columnField: PlutoCell(value: c.field),
},
checked: !c.hide,
);
Expand All @@ -528,7 +530,7 @@ mixin ColumnState implements IPlutoGridState {
var handleLister = () {
stateManager.refRows.forEach((row) {
var found = refColumns.originalList.firstWhere(
(column) => column.field == row.cells['field'].value.toString(),
(column) => column.field == row.cells[columnField].value.toString(),
orElse: () => null,
);

Expand All @@ -537,8 +539,6 @@ mixin ColumnState implements IPlutoGridState {
}
});

resetCurrentState(notify: false);

notifyListeners();
};

Expand Down
6 changes: 4 additions & 2 deletions lib/src/pluto_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import 'package:flutter/material.dart';
import 'package:linked_scroll_controller/linked_scroll_controller.dart';
import 'package:pluto_grid/pluto_grid.dart';

typedef PlutoOnLoadedEventCallback = void Function(PlutoGridOnLoadedEvent event);
typedef PlutoOnLoadedEventCallback = void Function(
PlutoGridOnLoadedEvent event);

typedef PlutoOnChangedEventCallback = void Function(PlutoGridOnChangedEvent event);
typedef PlutoOnChangedEventCallback = void Function(
PlutoGridOnChangedEvent event);

typedef PlutoOnSelectedEventCallback = void Function(
PlutoGridOnSelectedEvent event);
Expand Down
57 changes: 29 additions & 28 deletions lib/src/pluto_grid_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,35 @@ class PlutoGridPopup {
}

Future<void> open() async {
PlutoGridOnSelectedEvent selected = await showDialog<PlutoGridOnSelectedEvent>(
context: context,
builder: (BuildContext ctx) {
return Dialog(
child: LayoutBuilder(
builder: (ctx, size) {
return Container(
width: (width ?? size.maxWidth) +
PlutoGridSettings.gridInnerSpacing,
height: height ?? size.maxHeight,
child: PlutoGrid(
columns: columns,
rows: rows,
mode: mode,
onLoaded: onLoaded,
onChanged: onChanged,
onSelected: (PlutoGridOnSelectedEvent event) {
Navigator.pop(ctx, event);
},
createHeader: createHeader,
createFooter: createFooter,
configuration: configuration,
),
);
},
),
);
});
PlutoGridOnSelectedEvent selected =
await showDialog<PlutoGridOnSelectedEvent>(
context: context,
builder: (BuildContext ctx) {
return Dialog(
child: LayoutBuilder(
builder: (ctx, size) {
return Container(
width: (width ?? size.maxWidth) +
PlutoGridSettings.gridInnerSpacing,
height: height ?? size.maxHeight,
child: PlutoGrid(
columns: columns,
rows: rows,
mode: mode,
onLoaded: onLoaded,
onChanged: onChanged,
onSelected: (PlutoGridOnSelectedEvent event) {
Navigator.pop(ctx, event);
},
createHeader: createHeader,
createFooter: createFooter,
configuration: configuration,
),
);
},
),
);
});
if (onSelected != null) {
onSelected(selected);
}
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: 1.0.0
version: 1.1.0
homepage: https://bosskmk.github.io
repository: https://github.com/bosskmk/pluto_grid

Expand Down
130 changes: 130 additions & 0 deletions test/scenario/hide_columns/hide_column_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluto_grid/pluto_grid.dart';

import '../../helper/column_helper.dart';
import '../../helper/pluto_widget_test_helper.dart';
import '../../helper/row_helper.dart';

void main() {
group('숨김 컬럼이 없는 상태에서', () {
List<PlutoColumn> columns;

List<PlutoRow> rows;

PlutoGridStateManager stateManager;

final withTenColumns = PlutoWidgetTestHelper(
'10개의 컬럼을 생성',
(tester) async {
columns = [
...ColumnHelper.textColumn('header', count: 10),
];

rows = RowHelper.count(10, columns);

await tester.pumpWidget(
MaterialApp(
home: Material(
child: Container(
child: PlutoGrid(
columns: columns,
rows: rows,
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
},
),
),
),
),
);
},
);

withTenColumns.test(
'hideColumn 으로 header1 을 숨기면 header1 컬럼이 숨겨져야 한다.',
(tester) async {
var column = find.text('header1');

expect(column, findsOneWidget);

stateManager.hideColumn(columns[1].key, true);

await tester.pumpAndSettle(const Duration(milliseconds: 300));

expect(column, findsNothing);
},
);

withTenColumns.test(
'showSetColumnsPopup 을 호출 하면 컬럼 설정 팝업이 호출 되어야 한다.',
(tester) async {
stateManager.showSetColumnsPopup(stateManager.gridFocusNode.context);

await tester.pumpAndSettle(const Duration(milliseconds: 300));

var columnTitleOfPopup = find.text(
stateManager.configuration.localeText.setColumnsTitle,
);

expect(columnTitleOfPopup, findsOneWidget);
},
);
});

group('숨김 컬럼이 없는 상태에서', () {
List<PlutoColumn> columns;

List<PlutoRow> rows;

PlutoGridStateManager stateManager;

final withTenColumns = PlutoWidgetTestHelper(
'10개의 컬럼을 생성하고 0, 5번 컬럼을 숨김',
(tester) async {
columns = [
...ColumnHelper.textColumn('header', count: 10),
];

rows = RowHelper.count(10, columns);

await tester.pumpWidget(
MaterialApp(
home: Material(
child: Container(
child: PlutoGrid(
columns: columns,
rows: rows,
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
},
),
),
),
),
);

stateManager.hideColumn(columns[0].key, true, notify: false);
stateManager.hideColumn(columns[5].key, true);
},
);

withTenColumns.test(
'hideColumn 으로 header0 을 숨김 해제 하면 컬럼이 나타나야 한다.',
(tester) async {
var column = find.text('header0');

expect(column, findsNothing);

stateManager.hideColumn(
stateManager.refColumns.originalList[0].key,
false,
);

await tester.pumpAndSettle(const Duration(milliseconds: 300));

expect(column, findsOneWidget);
},
);
});
}
Loading

0 comments on commit 4e5776e

Please sign in to comment.