Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bosskmk committed May 20, 2021
1 parent 17d3525 commit 9b18160
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 2 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.0"
version: "2.1.0"
rainbow_color:
dependency: "direct main"
description:
Expand Down
3 changes: 2 additions & 1 deletion lib/src/manager/pluto_grid_key_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ class PlutoGridKeyManager {
lastChildContext is StatefulElement &&
lastChildContext.state.widget is Focus &&
(lastChildContext.state.widget as Focus).focusNode?.hasPrimaryFocus ==
false) {
false &&
stateManager.currentColumn?.type! is PlutoColumnTypeText) {
PlutoLog(
'Enter twice when entering Korean on the web.',
type: PlutoLogType.todo,
Expand Down
94 changes: 94 additions & 0 deletions test/src/widgets/pluto_loading_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluto_grid/pluto_grid.dart';

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

void main() {
final buildWidget = ({
Color? backgroundColor,
Color? indicatorColor,
String? indicatorText,
double? indicatorSize,
}) {
return PlutoWidgetTestHelper('build widget.', (tester) async {
final widget = PlutoLoading(
backgroundColor: backgroundColor,
indicatorColor: indicatorColor,
indicatorText: indicatorText,
indicatorSize: indicatorSize,
);

await tester.pumpWidget(
MaterialApp(
home: Material(
child: widget,
),
),
);
});
};

buildWidget().test(
'Parameter 를 전달 하지 않는 경우 기본 값으로 위젯이 생성 되어야 한다.',
(tester) async {
final text = find.byType(Text).evaluate().first.widget as Text;
final coloredBox =
find.byType(ColoredBox).evaluate().first.widget as ColoredBox;
final container =
find.byType(Container).evaluate().first.widget as Container;
final decoration = container.decoration as BoxDecoration;

expect(text.data, 'Loading...');
expect(coloredBox.color, Colors.white);
expect(decoration.color, Colors.white);
expect(decoration.border!.top.color, Colors.black);
expect(decoration.border!.bottom.color, Colors.black);
},
);

buildWidget(backgroundColor: Colors.green).test(
'backgroundColor 를 전달 하면 배경 색이 변경 되어야 한다.',
(tester) async {
final coloredBox =
find.byType(ColoredBox).evaluate().first.widget as ColoredBox;
final container =
find.byType(Container).evaluate().first.widget as Container;
final decoration = container.decoration as BoxDecoration;

expect(coloredBox.color, Colors.green);
expect(decoration.color, Colors.green);
},
);

buildWidget(indicatorColor: Colors.red).test(
'indicatorColor 를 전달 하면 텍스트와 border color 가 변경 되어야 한다.',
(tester) async {
final text = find.byType(Text).evaluate().first.widget as Text;
final container =
find.byType(Container).evaluate().first.widget as Container;
final decoration = container.decoration as BoxDecoration;

expect(text.style!.color, Colors.red);
expect(decoration.border!.top.color, Colors.red);
},
);

buildWidget(indicatorText: '로딩중...').test(
'indicatorText 를 전달 하면 텍스트가 변경 되어야 한다.',
(tester) async {
final text = find.byType(Text).evaluate().first.widget as Text;

expect(text.data, '로딩중...');
},
);

buildWidget(indicatorSize: 20.0).test(
'indicatorSize 를 전달 하면 텍스트 크기가 변경 되어야 한다.',
(tester) async {
final text = find.byType(Text).evaluate().first.widget as Text;

expect(text.style!.fontSize, 20.0);
},
);
}
61 changes: 61 additions & 0 deletions test/src/widgets/pluto_scaled_checkbox_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluto_grid/pluto_grid.dart';

void main() {
testWidgets(
'checkbox 가 렌더링 되어야 한다.',
(WidgetTester tester) async {
// given
final bool value = false;

final handleOnChanged = (bool? changed) {};

// when
await tester.pumpWidget(
MaterialApp(
home: Material(
child: PlutoScaledCheckbox(
value: value,
handleOnChanged: handleOnChanged,
),
),
),
);

// then
expect(find.byType(Checkbox), findsOneWidget);
},
);

testWidgets(
'checkbox 를 탭하면 handleOnChanged 가 호출 되어야 한다.',
(WidgetTester tester) async {
// given
bool? value = false;

final handleOnChanged = (bool? changed) {
value = changed;
};

// when
await tester.pumpWidget(
MaterialApp(
home: Material(
child: PlutoScaledCheckbox(
value: value,
handleOnChanged: handleOnChanged,
),
),
),
);

expect(value, isFalse);

// then
await tester.tap(find.byType(Checkbox));

expect(value, isTrue);
},
);
}
25 changes: 25 additions & 0 deletions test/src/widgets/pluto_shadow_container_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluto_grid/pluto_grid.dart';

void main() {
testWidgets(
'child 가 렌더링 되어야 한다.',
(WidgetTester tester) async {
// given
final child = const Text('child widget');

// when
await tester.pumpWidget(
MaterialApp(
home: Material(
child: PlutoShadowContainer(width: 100, height: 50, child: child),
),
),
);

// then
expect(find.text('child widget'), findsOneWidget);
},
);
}

0 comments on commit 9b18160

Please sign in to comment.