From b212c1d684e961475dcc684a1cc89b6aa6ab5914 Mon Sep 17 00:00:00 2001 From: sawel24 Date: Fri, 7 Oct 2022 17:12:31 +0300 Subject: [PATCH 1/2] Add widget tests for MaterialFlatBottomTabBar --- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 27 +-- .../contents.xcworkspacedata | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 2 + example/pubspec.lock | 117 ++++--------- example/test/widget_tests.dart | 165 ++++++++++++++++++ pubspec.lock | 109 ++++-------- 8 files changed, 240 insertions(+), 186 deletions(-) create mode 100644 example/test/widget_tests.dart diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 6b4c0f7..4f8d4d2 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 11.0 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 53b1cd4..9ab9155 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,17 +3,13 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 50; objects = { /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; @@ -26,8 +22,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -38,13 +32,11 @@ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; - 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -57,8 +49,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -68,9 +58,7 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, - 9740EEBA1CF902C7004384FC /* Flutter.framework */, 9740EEB21CF90195004384FC /* Debug.xcconfig */, 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 9740EEB31CF90195004384FC /* Generated.xcconfig */, @@ -147,7 +135,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -201,7 +189,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; @@ -253,7 +241,6 @@ /* Begin XCBuildConfiguration section */ 249021D3217E4FDB00AE95B9 /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -293,7 +280,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -330,7 +317,6 @@ }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -376,7 +362,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -386,7 +372,6 @@ }; 97C147041CF9000F007C117D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -426,7 +411,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a1..919434a 100644 --- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index b0d6bf6..827b874 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + diff --git a/example/pubspec.lock b/example/pubspec.lock index 80df913..26ea9a6 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,62 +1,41 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.9.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.2" - collection: + version: "2.1.0" + characters: dependency: transitive description: - name: collection + name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: + version: "1.2.1" + clock: dependency: transitive description: - name: convert + name: clock url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: + version: "1.1.1" + collection: dependency: transitive description: - name: crypto + name: collection url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "1.16.0" cupertino_icons: dependency: "direct main" description: @@ -64,6 +43,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.3" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -74,20 +60,20 @@ packages: description: flutter source: sdk version: "0.0.0" - image: + matcher: dependency: transitive description: - name: image + name: matcher url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" - matcher: + version: "0.12.12" + material_color_utilities: dependency: transitive description: - name: matcher + name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.1.5" material_flat_bottom_bar: dependency: "direct main" description: @@ -101,35 +87,14 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.8.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" + version: "1.8.2" sky_engine: dependency: transitive description: flutter @@ -141,62 +106,48 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.9.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.6" + version: "0.4.12" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" + version: "2.1.2" sdks: - dart: ">=2.4.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" diff --git a/example/test/widget_tests.dart b/example/test/widget_tests.dart new file mode 100644 index 0000000..591cf9f --- /dev/null +++ b/example/test/widget_tests.dart @@ -0,0 +1,165 @@ +import 'dart:core'; + +import 'package:example/screens/generated_screen.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:material_flat_bottom_bar/material_flat_bottom_bar.dart'; + +void main() { + const currentColor = Color.fromRGBO(91, 54, 183, 1); + const blackColor = Colors.black; + + const homeIconData = Icons.home; + const homeText = 'Home'; + + const peopleIconData = Icons.people; + const peopleText = 'Friends'; + + final List tabs = [ + GeneratedScreen( + name: homeText, + inheritedScreenName: 'Profile', + icon: homeIconData, + ), + GeneratedScreen( + name: peopleText, + inheritedScreenName: 'Friend Profile', + icon: peopleIconData, + ), + ]; + + testWidgets('Floating Action Button Test', (tester) async { + bool value = false; + Color testColor = currentColor; + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + floatingActionButton: FloatingActionButton( + onPressed: () { + value = true; + testColor = Colors.black; + }, + backgroundColor: currentColor, + child: Icon(Icons.add), + ), + ), + ), + ); + + final floatingActionButtonFinder = find.byType(FloatingActionButton); + + expect(floatingActionButtonFinder, findsOneWidget); + + final floatingActionButtonWidget = + tester.widget(floatingActionButtonFinder); + + expect(floatingActionButtonWidget.backgroundColor, currentColor); + + await tester.tap(floatingActionButtonFinder); + await tester.pump(); + + expect(testColor, blackColor); + expect(value, isTrue); + }); + + testWidgets('Material Flat Bottom Tab Bar Test', (tester) async { + await tester.pumpWidget( + MaterialApp( + home: MaterialFlatBottomBarScaffold( + tabBuilder: (BuildContext context, int index) { + return CupertinoTabView( + builder: (BuildContext context) => tabs[index]); + }, + tabBar: MaterialFlatBottomTabBar( + items: [ + buildItem( + title: homeText, + iconData: homeIconData, + currentColor: currentColor, + ), + buildItem( + title: peopleText, + iconData: peopleIconData, + currentColor: currentColor, + ), + ], + ), + ), + ), + ); + + final tapBarFinder = find.byType(MaterialFlatBottomTabBar); + expect(tapBarFinder, findsOneWidget); + + final activeTapBarIconFinder = find.descendant( + of: tapBarFinder, + matching: find.byIcon(homeIconData), + ); + final activeTapBarTextFinder = find.descendant( + of: tapBarFinder, + matching: find.text(homeText), + ); + + final activeTapBarIconWidget = tester.widget(activeTapBarIconFinder); + final activeTapBarTextWidget = tester.widget(activeTapBarTextFinder); + + expect(activeTapBarIconWidget.color, currentColor); + expect(activeTapBarTextWidget.style.color, currentColor); + + final notActiveTapBarIconFinder = find.descendant( + of: tapBarFinder, + matching: find.byIcon(peopleIconData), + ); + final notActiveTapBarTextFinder = find.descendant( + of: tapBarFinder, + matching: find.text(peopleText), + ); + + final notActiveTapBarIconWidget = + tester.widget(notActiveTapBarIconFinder); + final notActiveTapBarTextWidget = + tester.widget(notActiveTapBarTextFinder); + + expect(notActiveTapBarIconWidget.color, blackColor); + expect(notActiveTapBarTextWidget.style.color, blackColor); + + await tester.tap(notActiveTapBarIconFinder); + await tester.pump(); + + final tappedTapBarIconWidget = + tester.widget(notActiveTapBarIconFinder); + + expect(tappedTapBarIconWidget.color, currentColor); + }); +} + +MaterialFlatBottomTabBarItem buildItem({ + @required String title, + @required IconData iconData, + @required Color currentColor, +}) { + return MaterialFlatBottomTabBarItem( + titleBuilder: (bool current) { + return Text( + title, + style: TextStyle( + color: current ? currentColor : Colors.black, + fontWeight: current ? FontWeight.bold : FontWeight.w400, + fontSize: current ? 12 : 10, + ), + ); + }, + iconBuilder: (bool current) { + return Icon( + iconData, + color: current ? currentColor : Colors.black, + size: 24, + ); + }, + backgroundColor: (bool current) { + return current ? Color.fromRGBO(224, 215, 244, 1) : Colors.white; + }, + ); +} diff --git a/pubspec.lock b/pubspec.lock index 67a7df1..e15edce 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,62 +1,48 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.9.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" - charcode: + version: "2.1.0" + characters: dependency: transitive description: - name: charcode + name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" - collection: + version: "1.2.1" + clock: dependency: transitive description: - name: collection + name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: + version: "1.1.1" + collection: dependency: transitive description: - name: convert + name: collection url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: + version: "1.16.0" + fake_async: dependency: transitive description: - name: crypto + name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -67,55 +53,34 @@ packages: description: flutter source: sdk version: "0.0.0" - image: + matcher: dependency: transitive description: - name: image + name: matcher url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" - matcher: + version: "0.12.12" + material_color_utilities: dependency: transitive description: - name: matcher + name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.8.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" + version: "1.8.2" sky_engine: dependency: transitive description: flutter @@ -127,62 +92,48 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.9.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.6" + version: "0.4.12" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" + version: "2.1.2" sdks: - dart: ">=2.4.0 <3.0.0" + dart: ">=2.17.0-0 <3.0.0" From 27f522602c95f8a1d927a2263e7a57ce8a08ee38 Mon Sep 17 00:00:00 2001 From: sawel24 Date: Thu, 13 Oct 2022 18:55:59 +0300 Subject: [PATCH 2/2] fix: change widget tests for material flat bottom bar --- example/test/widget_tests.dart | 165 ------------------------------ test/widget_tests.dart | 182 +++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+), 165 deletions(-) delete mode 100644 example/test/widget_tests.dart create mode 100644 test/widget_tests.dart diff --git a/example/test/widget_tests.dart b/example/test/widget_tests.dart deleted file mode 100644 index 591cf9f..0000000 --- a/example/test/widget_tests.dart +++ /dev/null @@ -1,165 +0,0 @@ -import 'dart:core'; - -import 'package:example/screens/generated_screen.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:material_flat_bottom_bar/material_flat_bottom_bar.dart'; - -void main() { - const currentColor = Color.fromRGBO(91, 54, 183, 1); - const blackColor = Colors.black; - - const homeIconData = Icons.home; - const homeText = 'Home'; - - const peopleIconData = Icons.people; - const peopleText = 'Friends'; - - final List tabs = [ - GeneratedScreen( - name: homeText, - inheritedScreenName: 'Profile', - icon: homeIconData, - ), - GeneratedScreen( - name: peopleText, - inheritedScreenName: 'Friend Profile', - icon: peopleIconData, - ), - ]; - - testWidgets('Floating Action Button Test', (tester) async { - bool value = false; - Color testColor = currentColor; - - await tester.pumpWidget( - MaterialApp( - home: Scaffold( - floatingActionButton: FloatingActionButton( - onPressed: () { - value = true; - testColor = Colors.black; - }, - backgroundColor: currentColor, - child: Icon(Icons.add), - ), - ), - ), - ); - - final floatingActionButtonFinder = find.byType(FloatingActionButton); - - expect(floatingActionButtonFinder, findsOneWidget); - - final floatingActionButtonWidget = - tester.widget(floatingActionButtonFinder); - - expect(floatingActionButtonWidget.backgroundColor, currentColor); - - await tester.tap(floatingActionButtonFinder); - await tester.pump(); - - expect(testColor, blackColor); - expect(value, isTrue); - }); - - testWidgets('Material Flat Bottom Tab Bar Test', (tester) async { - await tester.pumpWidget( - MaterialApp( - home: MaterialFlatBottomBarScaffold( - tabBuilder: (BuildContext context, int index) { - return CupertinoTabView( - builder: (BuildContext context) => tabs[index]); - }, - tabBar: MaterialFlatBottomTabBar( - items: [ - buildItem( - title: homeText, - iconData: homeIconData, - currentColor: currentColor, - ), - buildItem( - title: peopleText, - iconData: peopleIconData, - currentColor: currentColor, - ), - ], - ), - ), - ), - ); - - final tapBarFinder = find.byType(MaterialFlatBottomTabBar); - expect(tapBarFinder, findsOneWidget); - - final activeTapBarIconFinder = find.descendant( - of: tapBarFinder, - matching: find.byIcon(homeIconData), - ); - final activeTapBarTextFinder = find.descendant( - of: tapBarFinder, - matching: find.text(homeText), - ); - - final activeTapBarIconWidget = tester.widget(activeTapBarIconFinder); - final activeTapBarTextWidget = tester.widget(activeTapBarTextFinder); - - expect(activeTapBarIconWidget.color, currentColor); - expect(activeTapBarTextWidget.style.color, currentColor); - - final notActiveTapBarIconFinder = find.descendant( - of: tapBarFinder, - matching: find.byIcon(peopleIconData), - ); - final notActiveTapBarTextFinder = find.descendant( - of: tapBarFinder, - matching: find.text(peopleText), - ); - - final notActiveTapBarIconWidget = - tester.widget(notActiveTapBarIconFinder); - final notActiveTapBarTextWidget = - tester.widget(notActiveTapBarTextFinder); - - expect(notActiveTapBarIconWidget.color, blackColor); - expect(notActiveTapBarTextWidget.style.color, blackColor); - - await tester.tap(notActiveTapBarIconFinder); - await tester.pump(); - - final tappedTapBarIconWidget = - tester.widget(notActiveTapBarIconFinder); - - expect(tappedTapBarIconWidget.color, currentColor); - }); -} - -MaterialFlatBottomTabBarItem buildItem({ - @required String title, - @required IconData iconData, - @required Color currentColor, -}) { - return MaterialFlatBottomTabBarItem( - titleBuilder: (bool current) { - return Text( - title, - style: TextStyle( - color: current ? currentColor : Colors.black, - fontWeight: current ? FontWeight.bold : FontWeight.w400, - fontSize: current ? 12 : 10, - ), - ); - }, - iconBuilder: (bool current) { - return Icon( - iconData, - color: current ? currentColor : Colors.black, - size: 24, - ); - }, - backgroundColor: (bool current) { - return current ? Color.fromRGBO(224, 215, 244, 1) : Colors.white; - }, - ); -} diff --git a/test/widget_tests.dart b/test/widget_tests.dart new file mode 100644 index 0000000..4005820 --- /dev/null +++ b/test/widget_tests.dart @@ -0,0 +1,182 @@ +import 'dart:core'; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:material_flat_bottom_bar/material_flat_bottom_bar.dart'; + +void main() { + group('Material Flat Bottom Bar tests', () { + const currentColor = Color.fromRGBO(91, 54, 183, 1); + + const homeIconData = Icons.home; + const homeText = 'Home'; + + const peopleIconData = Icons.people; + const peopleText = 'Friends'; + + final List tabs = [Container(), Container()]; + + bool isPressed = false; + final materialFlatBottomBarScaffold = MaterialFlatBottomBarScaffold( + tabBuilder: (BuildContext context, int index) { + return CupertinoTabView(builder: (BuildContext context) => tabs[index]); + }, + floatingActionButton: FloatingActionButton( + onPressed: () { + isPressed = true; + }, + backgroundColor: currentColor, + child: Icon(Icons.add), + ), + tabBar: MaterialFlatBottomTabBar( + items: [ + buildItem( + title: homeText, + iconData: homeIconData, + currentColor: currentColor, + ), + buildItem( + title: peopleText, + iconData: peopleIconData, + currentColor: currentColor, + ), + ], + ), + ); + + testWidgets('FloatingActionButton should render correctly', (tester) async { + await tester + .pumpWidget(_wrapWithMaterialApp(materialFlatBottomBarScaffold)); + + expect(find.byType(FloatingActionButton), findsOneWidget); + }); + + testWidgets('FloatingActionButton content should match', (tester) async { + await tester + .pumpWidget(_wrapWithMaterialApp(materialFlatBottomBarScaffold)); + + final floatingActionButtonFinder = + find.widgetWithIcon(FloatingActionButton, Icons.add); + final floatingActionButton = + tester.widget(floatingActionButtonFinder); + + expect(floatingActionButtonFinder, findsOneWidget); + expect(floatingActionButton.backgroundColor, currentColor); + }); + + testWidgets('FloatingActionButton onTap is called', (tester) async { + await tester + .pumpWidget(_wrapWithMaterialApp(materialFlatBottomBarScaffold)); + + await tester.tap(find.byType(FloatingActionButton)); + expect(isPressed, true); + }); + + testWidgets('MaterialFlatBottomTabBar should render correctly', + (tester) async { + await tester + .pumpWidget(_wrapWithMaterialApp(materialFlatBottomBarScaffold)); + + expect(find.byType(MaterialFlatBottomTabBar), findsOneWidget); + }); + + testWidgets('MaterialFlatBottomTabBar content should match', + (tester) async { + await tester + .pumpWidget(_wrapWithMaterialApp(materialFlatBottomBarScaffold)); + + expect(find.text(homeText), findsOneWidget); + expect(find.byIcon(homeIconData), findsOneWidget); + + expect(find.text(peopleText), findsOneWidget); + expect(find.byIcon(peopleIconData), findsOneWidget); + }); + + testWidgets('MaterialFlatBottomTabBar item onTap is called', + (tester) async { + await tester + .pumpWidget(_wrapWithMaterialApp(materialFlatBottomBarScaffold)); + final peopleIconFinder = find.byIcon(peopleIconData); + + await tester.tap(peopleIconFinder); + await tester.pump(); + + final iconWidget = tester.widget(peopleIconFinder); + expect(iconWidget.color, currentColor); + }); + + testWidgets('MarkedBottomNavigation item selected style should match', + (tester) async { + await tester + .pumpWidget(_wrapWithMaterialApp(materialFlatBottomBarScaffold)); + + final selectedIconFinder = find.byIcon(homeIconData); + expect(selectedIconFinder, findsOneWidget); + + final iconWidget = tester.widget(selectedIconFinder); + + final selectedTextFinder = find.text(homeText); + + final textWidget = tester.widget(selectedTextFinder); + + expect(iconWidget.color, currentColor); + expect(textWidget.style.color, currentColor); + expect(textWidget.style.fontWeight, FontWeight.bold); + expect(textWidget.style.fontSize, 12); + }); + + testWidgets('MarkedBottomNavigation item unselected style should match', + (tester) async { + await tester + .pumpWidget(_wrapWithMaterialApp(materialFlatBottomBarScaffold)); + + final unselectedIconFinder = find.byIcon(peopleIconData); + expect(unselectedIconFinder, findsOneWidget); + + final iconWidget = tester.widget(unselectedIconFinder); + + final unselectedTextFinder = find.text(peopleText); + + final textWidget = tester.widget(unselectedTextFinder); + + expect(iconWidget.color, Colors.black); + expect(textWidget.style.color, Colors.black); + expect(textWidget.style.fontWeight, FontWeight.w400); + expect(textWidget.style.fontSize, 10); + }); + }); +} + +Widget _wrapWithMaterialApp(Widget testWidget) { + return MaterialApp(home: testWidget); +} + +MaterialFlatBottomTabBarItem buildItem({ + @required String title, + @required IconData iconData, + @required Color currentColor, +}) { + return MaterialFlatBottomTabBarItem( + titleBuilder: (bool current) { + return Text( + title, + style: TextStyle( + color: current ? currentColor : Colors.black, + fontWeight: current ? FontWeight.bold : FontWeight.w400, + fontSize: current ? 12 : 10, + ), + ); + }, + iconBuilder: (bool current) { + return Icon( + iconData, + color: current ? currentColor : Colors.black, + size: 24, + ); + }, + backgroundColor: (bool current) { + return current ? Color.fromRGBO(224, 215, 244, 1) : Colors.white; + }, + ); +}