Skip to content

Commit

Permalink
feat: add test for list_custom_grouped_checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
liodali committed Oct 12, 2021
1 parent 50f8a50 commit d6ecbc0
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
faker:
dependency: "direct dev"
description:
name: faker
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
faker: ^2.0.0


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
121 changes: 121 additions & 0 deletions test/list_custom_grouped_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import 'package:checkbox_grouped/checkbox_grouped.dart';
import 'package:checkbox_grouped/src/widgets/custom_grouped_checkbox.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() async {
testWidgets(" test list custom grouped ", (tester) async {
final controller =
ListCustomGroupController(isMultipleSelectionPerGroup: [true, false]);
final datas = [
List<int>.generate(
3,
(i) => i + 1,
),
List<String>.generate(
3,
(i) => "name-${i + 1}",
)
];
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ListCustomGroupedCheckbox(
controller: controller,
isScrollable: true,
titleGroupedAlignment: Alignment.centerLeft,
groupTitles: ["Users", "Names"],
children: [
CustomIndexedWidgetBuilder(
itemBuilder: (ctx, index, selected, isDisabled) {
return Card(
margin: EdgeInsets.only(
top: 5.0,
bottom: 5.0,
),
child: ListTile(
tileColor: selected ? Colors.green[300] : Colors.white,
title: Text(
"${datas[0][index]}",
),
trailing: Opacity(
opacity: selected ? 1 : 0,
child: Icon(
Icons.check,
color: Colors.white,
size: 24,
),
),
),
);
},
),
CustomGridIndexedWidgetBuilder(
itemBuilder: (ctx, index, selected, isDisabled) {
return Card(
color: selected ? Colors.green[300] : Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
12.0,
),
),
margin: EdgeInsets.only(
top: 5.0,
bottom: 5.0,
),
child: Stack(
children: [
Center(
child: Text(
datas[1][index] as String,
maxLines: 3,
overflow: TextOverflow.fade,
),
),
Positioned(
top: 5,
right: 8,
child: Opacity(
opacity: selected ? 1 : 0,
child: Icon(
Icons.check,
color: Colors.white,
size: 24,
),
),
),
],
),
);
},
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3, crossAxisSpacing: 5.0)),
],
listValuesByGroup: datas,
),
),
),
Duration(seconds: 30));

await tester.pump();

await tester.tap(find.byType(ItemWidget).first);

await tester.pump(Duration(seconds: 10));
await tester.tap(find.byType(ItemWidget).at(3));
await tester.pump(Duration(seconds: 10));

var result = await controller.allSelectedItemsGrouped;
var actualResult = [
[1],
"name-1"
];
expect(result.length, 2);
expect(result, actualResult);
await tester.tap(find.byType(ItemWidget).first);
await tester.pump(Duration(seconds: 10));
result = await controller.allSelectedItemsGrouped;
actualResult = [[], "name-1"];
expect(result, actualResult);
});
}

0 comments on commit d6ecbc0

Please sign in to comment.