From 9b181609751c801db71d875257b9b05bd85ad886 Mon Sep 17 00:00:00 2001 From: kmk Date: Thu, 20 May 2021 21:45:20 +0900 Subject: [PATCH] Add tests. --- example/pubspec.lock | 2 +- lib/src/manager/pluto_grid_key_manager.dart | 3 +- test/src/widgets/pluto_loading_test.dart | 94 +++++++++++++++++++ .../widgets/pluto_scaled_checkbox_test.dart | 61 ++++++++++++ .../widgets/pluto_shadow_container_test.dart | 25 +++++ 5 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 test/src/widgets/pluto_loading_test.dart create mode 100644 test/src/widgets/pluto_scaled_checkbox_test.dart create mode 100644 test/src/widgets/pluto_shadow_container_test.dart diff --git a/example/pubspec.lock b/example/pubspec.lock index 93bb474d2..a54a4a50b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -155,7 +155,7 @@ packages: path: ".." relative: true source: path - version: "2.0.0" + version: "2.1.0" rainbow_color: dependency: "direct main" description: diff --git a/lib/src/manager/pluto_grid_key_manager.dart b/lib/src/manager/pluto_grid_key_manager.dart index 6cf62a88a..e18cd1c71 100644 --- a/lib/src/manager/pluto_grid_key_manager.dart +++ b/lib/src/manager/pluto_grid_key_manager.dart @@ -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, diff --git a/test/src/widgets/pluto_loading_test.dart b/test/src/widgets/pluto_loading_test.dart new file mode 100644 index 000000000..a56db1d0d --- /dev/null +++ b/test/src/widgets/pluto_loading_test.dart @@ -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); + }, + ); +} diff --git a/test/src/widgets/pluto_scaled_checkbox_test.dart b/test/src/widgets/pluto_scaled_checkbox_test.dart new file mode 100644 index 000000000..606bb03f4 --- /dev/null +++ b/test/src/widgets/pluto_scaled_checkbox_test.dart @@ -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); + }, + ); +} diff --git a/test/src/widgets/pluto_shadow_container_test.dart b/test/src/widgets/pluto_shadow_container_test.dart new file mode 100644 index 000000000..54e7aed7a --- /dev/null +++ b/test/src/widgets/pluto_shadow_container_test.dart @@ -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); + }, + ); +}