From bf0e95921501d7c7f444afe0b1268b84bc0d8747 Mon Sep 17 00:00:00 2001 From: DenserMeerkat Date: Tue, 30 Jul 2024 21:16:34 +0530 Subject: [PATCH] wip: widget tests --- lib/extensions/string_extensions.dart | 3 + lib/widgets/popup_menu_codegen.dart | 11 +- lib/widgets/popup_menu_env.dart | 10 +- lib/widgets/popup_menu_history.dart | 11 +- lib/widgets/popup_menu_uri.dart | 10 +- test/extensions/context_extensions_test.dart | 113 ++++++++ test/extensions/string_extensions_test.dart | 62 +++++ test/utils/envvar_utils_test.dart | 15 +- test/utils/ui_utils_test.dart | 15 ++ test/widgets/button_clear_response_test.dart | 21 ++ test/widgets/button_copy_test.dart | 53 ++++ test/widgets/button_discord_test.dart | 22 ++ test/widgets/button_repo_test.dart | 44 +++ test/widgets/button_save_download_test.dart | 79 ++++++ test/widgets/button_send_test.dart | 58 ++++ test/widgets/buttons_test.dart | 250 ------------------ test/widgets/card_request_details.dart | 18 ++ .../card_sidebar_environment_test.dart | 206 +++++++++++++++ ...st.dart => card_sidebar_request_test.dart} | 14 +- test/widgets/envvar__indicator_test.dart | 94 +++++++ test/widgets/envvar_popover_test.dart | 36 +++ test/widgets/popup_menu_codegen_test.dart | 76 ++++++ test/widgets/popup_menu_env_test.dart | 118 +++++++++ test/widgets/popup_menu_uri_test.dart | 75 ++++++ test/widgets/sidebar_save_button_test.dart | 24 ++ test/widgets/splitview_dashboard_test.dart | 25 ++ test/widgets/splitview_drawer_test.dart | 97 +++++++ ...ws_test.dart => splitview_equal_test.dart} | 17 -- test/widgets/tabs_test.dart | 43 +++ 29 files changed, 1326 insertions(+), 294 deletions(-) create mode 100644 test/extensions/context_extensions_test.dart create mode 100644 test/extensions/string_extensions_test.dart create mode 100644 test/widgets/button_clear_response_test.dart create mode 100644 test/widgets/button_copy_test.dart create mode 100644 test/widgets/button_discord_test.dart create mode 100644 test/widgets/button_repo_test.dart create mode 100644 test/widgets/button_save_download_test.dart create mode 100644 test/widgets/button_send_test.dart delete mode 100644 test/widgets/buttons_test.dart create mode 100644 test/widgets/card_request_details.dart create mode 100644 test/widgets/card_sidebar_environment_test.dart rename test/widgets/{cards_test.dart => card_sidebar_request_test.dart} (88%) create mode 100644 test/widgets/envvar__indicator_test.dart create mode 100644 test/widgets/envvar_popover_test.dart create mode 100644 test/widgets/popup_menu_codegen_test.dart create mode 100644 test/widgets/popup_menu_env_test.dart create mode 100644 test/widgets/popup_menu_uri_test.dart create mode 100644 test/widgets/sidebar_save_button_test.dart create mode 100644 test/widgets/splitview_dashboard_test.dart create mode 100644 test/widgets/splitview_drawer_test.dart rename test/widgets/{splitviews_test.dart => splitview_equal_test.dart} (60%) create mode 100644 test/widgets/tabs_test.dart diff --git a/lib/extensions/string_extensions.dart b/lib/extensions/string_extensions.dart index 37632a2f..86813788 100644 --- a/lib/extensions/string_extensions.dart +++ b/lib/extensions/string_extensions.dart @@ -10,6 +10,9 @@ extension StringExtension on String { } String clip(int limit) { + if (limit < 0) { + return '...'; + } if (length <= limit) { return this; } diff --git a/lib/widgets/popup_menu_codegen.dart b/lib/widgets/popup_menu_codegen.dart index 421d1ce7..9d1c3bc4 100644 --- a/lib/widgets/popup_menu_codegen.dart +++ b/lib/widgets/popup_menu_codegen.dart @@ -15,7 +15,6 @@ class CodegenPopupMenu extends StatelessWidget { final List? items; @override Widget build(BuildContext context) { - final textClipLength = context.isCompactWindow ? 12 : 22; final double boxLength = context.isCompactWindow ? 150 : 220; return PopupMenuButton( tooltip: "Select Code Generation Language", @@ -37,9 +36,13 @@ class CodegenPopupMenu extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( - value.label.clip(textClipLength), - style: kTextStylePopupMenuItem, + Expanded( + child: Text( + value.label, + style: kTextStylePopupMenuItem, + softWrap: false, + overflow: TextOverflow.ellipsis, + ), ), const Icon( Icons.unfold_more, diff --git a/lib/widgets/popup_menu_env.dart b/lib/widgets/popup_menu_env.dart index d61be5b4..63b6034e 100644 --- a/lib/widgets/popup_menu_env.dart +++ b/lib/widgets/popup_menu_env.dart @@ -19,7 +19,6 @@ class EnvironmentPopupMenu extends StatelessWidget { @override Widget build(BuildContext context) { final valueName = getEnvironmentTitle(value?.name); - final textClipLength = context.isCompactWindow ? 6 : 10; final double boxLength = context.isCompactWindow ? 100 : 130; return PopupMenuButton( tooltip: "Select Environment", @@ -54,9 +53,12 @@ class EnvironmentPopupMenu extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( - value == null ? "None" : valueName.clip(textClipLength), - softWrap: false, + Expanded( + child: Text( + value == null ? "None" : valueName, + softWrap: false, + overflow: TextOverflow.ellipsis, + ), ), const Icon( Icons.unfold_more, diff --git a/lib/widgets/popup_menu_history.dart b/lib/widgets/popup_menu_history.dart index 72398bb3..4dfba84b 100644 --- a/lib/widgets/popup_menu_history.dart +++ b/lib/widgets/popup_menu_history.dart @@ -40,10 +40,13 @@ class HistoryRetentionPopupMenu extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( - value.label, - style: kTextStylePopupMenuItem, - overflow: TextOverflow.ellipsis, + Expanded( + child: Text( + value.label, + style: kTextStylePopupMenuItem, + softWrap: false, + overflow: TextOverflow.ellipsis, + ), ), const Icon( Icons.unfold_more, diff --git a/lib/widgets/popup_menu_uri.dart b/lib/widgets/popup_menu_uri.dart index 5a62c97e..418c6a71 100644 --- a/lib/widgets/popup_menu_uri.dart +++ b/lib/widgets/popup_menu_uri.dart @@ -36,9 +36,13 @@ class URIPopupMenu extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text( - value, - style: kTextStylePopupMenuItem, + Expanded( + child: Text( + value, + style: kTextStylePopupMenuItem, + softWrap: false, + overflow: TextOverflow.ellipsis, + ), ), const Icon( Icons.unfold_more, diff --git a/test/extensions/context_extensions_test.dart b/test/extensions/context_extensions_test.dart new file mode 100644 index 00000000..6b305b07 --- /dev/null +++ b/test/extensions/context_extensions_test.dart @@ -0,0 +1,113 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/consts.dart'; +import 'package:apidash/extensions/context_extensions.dart'; + +void main() { + group('Testing MediaQueryExtension', () { + testWidgets('isCompactWindow returns true for compact window size', + (tester) async { + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(size: Size(kCompactWindowWidth - 1, 800)), + child: Builder( + builder: (context) { + expect(context.isCompactWindow, isTrue); + return Container(); + }, + ), + ), + ); + }); + + testWidgets('isMediumWindow returns true for medium window size', + (tester) async { + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(size: Size(kMediumWindowWidth - 1, 800)), + child: Builder( + builder: (context) { + expect(context.isMediumWindow, isTrue); + return Container(); + }, + ), + ), + ); + }); + + testWidgets('isExpandedWindow returns true for expanded window size', + (tester) async { + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(size: Size(kExpandedWindowWidth - 1, 800)), + child: Builder( + builder: (context) { + expect(context.isExpandedWindow, isTrue); + return Container(); + }, + ), + ), + ); + }); + + testWidgets('isLargeWindow returns true for large window size', + (tester) async { + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(size: Size(kLargeWindowWidth - 1, 800)), + child: Builder( + builder: (context) { + expect(context.isLargeWindow, isTrue); + return Container(); + }, + ), + ), + ); + }); + + testWidgets('isExtraLargeWindow returns true for extra large window size', + (tester) async { + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(size: Size(kLargeWindowWidth + 1, 800)), + child: Builder( + builder: (context) { + expect(context.isExtraLargeWindow, isTrue); + return Container(); + }, + ), + ), + ); + }); + + testWidgets('width returns correct width', (tester) async { + const double testWidth = 1024; + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(size: Size(testWidth, 800)), + child: Builder( + builder: (context) { + expect(context.width, testWidth); + return Container(); + }, + ), + ), + ); + }); + + testWidgets('height returns correct height', (tester) async { + const double testHeight = 768; + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(size: Size(1024, testHeight)), + child: Builder( + builder: (context) { + expect(context.height, testHeight); + return Container(); + }, + ), + ), + ); + }); + }); +} diff --git a/test/extensions/string_extensions_test.dart b/test/extensions/string_extensions_test.dart new file mode 100644 index 00000000..c0fcbd58 --- /dev/null +++ b/test/extensions/string_extensions_test.dart @@ -0,0 +1,62 @@ +import 'package:test/test.dart'; +import 'package:apidash/extensions/string_extensions.dart'; + +void main() { + group('Testing StringExtensions', () { + group('Testing capitalize', () { + test('should capitalize the first letter of a lowercase word', () { + expect('hello'.capitalize(), 'Hello'); + }); + + test( + 'should capitalize the first letter and lowercase the rest of an uppercase word', + () { + expect('HELLO'.capitalize(), 'Hello'); + }); + + test('should return the same string if it is already capitalized', () { + expect('Hello'.capitalize(), 'Hello'); + }); + + test('should return an empty string if the input is empty', () { + expect(''.capitalize(), ''); + }); + + test('should capitalize a single lowercase letter', () { + expect('h'.capitalize(), 'H'); + }); + + test('should return the same single uppercase letter', () { + expect('H'.capitalize(), 'H'); + }); + }); + + group('Testing clip', () { + test( + 'should return the same string if its length is less than or equal to the limit', + () { + expect('hello'.clip(5), 'hello'); + expect('hello'.clip(10), 'hello'); + }); + + test( + 'should clip the string and add ellipsis if its length is greater than the limit', + () { + expect('hello world'.clip(5), 'hello...'); + expect('hello world'.clip(8), 'hello wo...'); + }); + + test('should return an empty string if the input is empty', () { + expect(''.clip(5), ''); + }); + + test('should handle limit of 0 correctly', () { + expect('hello'.clip(0), '...'); + }); + + test('should handle negative limit correctly', () { + expect('hello'.clip(-1), '...'); + }); + }); + }); +} diff --git a/test/utils/envvar_utils_test.dart b/test/utils/envvar_utils_test.dart index 59bb4740..84b14652 100644 --- a/test/utils/envvar_utils_test.dart +++ b/test/utils/envvar_utils_test.dart @@ -299,7 +299,7 @@ void main() { }); group("Testing getVariableStatus function", () { - test("Testing getVariableStatus with available variable", () { + test("Testing getVariableStatus with variable available in global", () { const query = "num"; Map> envMap = { kGlobalEnvironmentId: globalVars, @@ -310,6 +310,19 @@ void main() { expect(getVariableStatus(query, envMap, null), expected); }); + test("Testing getVariableStatus with variable available in active", () { + const query = "num"; + Map> envMap = { + kGlobalEnvironmentId: globalVars, + "activeEnvId": activeEnvVars, + }; + const activeEnvironmentId = "activeEnvId"; + const expected = EnvironmentVariableSuggestion( + environmentId: activeEnvironmentId, + variable: EnvironmentVariableModel(key: "num", value: "8940000")); + expect(getVariableStatus(query, envMap, activeEnvironmentId), expected); + }); + test("Testing getVariableStatus with unavailable variable", () { const query = "path"; Map> envMap = { diff --git a/test/utils/ui_utils_test.dart b/test/utils/ui_utils_test.dart index 0a18431a..4d5a686b 100644 --- a/test/utils/ui_utils_test.dart +++ b/test/utils/ui_utils_test.dart @@ -141,4 +141,19 @@ void main() { colMethodDeleteDarkModeExpected); }); }); + + group('Testing getScaffoldKey function', () { + test('Returns kEnvScaffoldKey for railIdx 1', () { + expect(getScaffoldKey(1), kEnvScaffoldKey); + }); + + test('Returns kHisScaffoldKey for railIdx 2', () { + expect(getScaffoldKey(2), kHisScaffoldKey); + }); + + test('Returns kHomeScaffoldKey for railIdx other than 1 or 2', () { + expect(getScaffoldKey(0), kHomeScaffoldKey); + expect(getScaffoldKey(3), kHomeScaffoldKey); + }); + }); } diff --git a/test/widgets/button_clear_response_test.dart b/test/widgets/button_clear_response_test.dart new file mode 100644 index 00000000..e8dfb76c --- /dev/null +++ b/test/widgets/button_clear_response_test.dart @@ -0,0 +1,21 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/widgets/button_clear_response.dart'; + +import '../test_consts.dart'; + +void main() { + testWidgets('Testing for ClearResponseButton', (tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'ClearResponseButton', + theme: kThemeDataLight, + home: const Scaffold( + body: ClearResponseButton(), + ), + ), + ); + + expect(find.byIcon(Icons.delete), findsOneWidget); + }); +} diff --git a/test/widgets/button_copy_test.dart b/test/widgets/button_copy_test.dart new file mode 100644 index 00000000..d9397d93 --- /dev/null +++ b/test/widgets/button_copy_test.dart @@ -0,0 +1,53 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/widgets/button_copy.dart'; + +void main() { + String copyText = 'This is a sample response generated by '; + + testWidgets('Testing for copy button with label', (tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'Copy Button', + home: Scaffold( + body: CopyButton(toCopy: copyText, showLabel: true), + ), + ), + ); + + final icon = find.byIcon(Icons.content_copy); + expect(icon, findsOneWidget); + + final button = find.ancestor( + of: icon, + matching: find.byWidgetPredicate((widget) => widget is TextButton)); + expect(button, findsOneWidget); + + await tester.tap(button); + await tester.pumpAndSettle(); + + //TODO: The below test works for `flutter run` but not for `flutter test` + // var data = await Clipboard.getData('text/plain'); + // expect(data?.text, copyText); + }); + + testWidgets('Testing for copy button without label', (tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'Copy Button', + home: Scaffold( + body: CopyButton(toCopy: copyText, showLabel: false), + ), + ), + ); + + final icon = find.byIcon(Icons.content_copy); + expect(icon, findsOneWidget); + + final button = find.byType(IconButton); + expect(button, findsOneWidget); + + await tester.tap(button); + await tester.pump(); + }); +} diff --git a/test/widgets/button_discord_test.dart b/test/widgets/button_discord_test.dart new file mode 100644 index 00000000..63a146aa --- /dev/null +++ b/test/widgets/button_discord_test.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/widgets/button_discord.dart'; + +import '../test_consts.dart'; + +void main() { + testWidgets('Testing for Discord button', (tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'Discord button', + theme: kThemeDataLight, + home: const Scaffold( + body: DiscordButton(), + ), + ), + ); + + expect(find.byIcon(Icons.discord), findsOneWidget); + expect(find.text("Discord Server"), findsOneWidget); + }); +} diff --git a/test/widgets/button_repo_test.dart b/test/widgets/button_repo_test.dart new file mode 100644 index 00000000..b0023ef7 --- /dev/null +++ b/test/widgets/button_repo_test.dart @@ -0,0 +1,44 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/widgets/button_repo.dart'; + +import '../test_consts.dart'; + +void main() { + testWidgets('Testing for Repo button', (tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'Repo button', + theme: kThemeDataLight, + home: const Scaffold( + body: RepoButton( + icon: Icons.code, + ), + ), + ), + ); + + expect(find.byIcon(Icons.code), findsOneWidget); + expect(find.text("GitHub"), findsOneWidget); + }); + + testWidgets('Testing for Repo button icon = null', (tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'Repo button', + theme: kThemeDataLight, + home: const Scaffold( + body: RepoButton(), + ), + ), + ); + + expect(find.byIcon(Icons.code), findsNothing); + expect(find.text("GitHub"), findsOneWidget); + + final button1 = find.byType(FilledButton); + expect(button1, findsOneWidget); + + expect(tester.widget(button1).enabled, isTrue); + }); +} diff --git a/test/widgets/button_save_download_test.dart b/test/widgets/button_save_download_test.dart new file mode 100644 index 00000000..288849a8 --- /dev/null +++ b/test/widgets/button_save_download_test.dart @@ -0,0 +1,79 @@ +import 'dart:typed_data'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/consts.dart'; +import 'package:apidash/widgets/button_save_download.dart'; + +import '../test_consts.dart'; + +void main() { + testWidgets('Testing for Save in Downloads button', (tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'Save in Downloads button', + theme: kThemeDataLight, + home: const Scaffold( + body: SaveInDownloadsButton(), + ), + ), + ); + + final icon = find.byIcon(Icons.download); + expect(icon, findsOneWidget); + + Finder button; + if (tester.any(find.ancestor( + of: icon, + matching: find.byWidgetPredicate((widget) => widget is TextButton)))) { + expect(find.text(kLabelDownload), findsOneWidget); + button = find.ancestor( + of: icon, + matching: find.byWidgetPredicate((widget) => widget is TextButton)); + expect(button, findsOneWidget); + expect(tester.widget(button).enabled, isFalse); + } else if (tester + .any(find.ancestor(of: icon, matching: find.byType(IconButton)))) { + button = find.byType(IconButton); + expect(button, findsOneWidget); + expect(tester.widget(button).onPressed == null, isFalse); + } else { + fail('No TextButton or IconButton found'); + } + }); + + testWidgets('Testing for Save in Downloads button 2', (tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'Save in Downloads button', + theme: kThemeDataLight, + home: Scaffold( + body: SaveInDownloadsButton( + content: Uint8List.fromList([1]), + ), + ), + ), + ); + + final icon = find.byIcon(Icons.download); + expect(icon, findsOneWidget); + + Finder button; + if (tester.any(find.ancestor( + of: icon, + matching: find.byWidgetPredicate((widget) => widget is TextButton)))) { + expect(find.text(kLabelDownload), findsOneWidget); + button = find.ancestor( + of: icon, + matching: find.byWidgetPredicate((widget) => widget is TextButton)); + expect(button, findsOneWidget); + expect(tester.widget(button).enabled, isTrue); + } else if (tester + .any(find.ancestor(of: icon, matching: find.byType(IconButton)))) { + button = find.byType(IconButton); + expect(button, findsOneWidget); + expect(tester.widget(button).onPressed == null, isTrue); + } else { + fail('No TextButton or IconButton found'); + } + }); +} diff --git a/test/widgets/button_send_test.dart b/test/widgets/button_send_test.dart new file mode 100644 index 00000000..f02fddb9 --- /dev/null +++ b/test/widgets/button_send_test.dart @@ -0,0 +1,58 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/consts.dart'; +import 'package:apidash/widgets/button_send.dart'; + +import '../test_consts.dart'; + +void main() { + testWidgets('Testing for Send Request button', (tester) async { + dynamic changedValue; + await tester.pumpWidget( + MaterialApp( + title: 'Send Request button', + theme: kThemeDataLight, + home: Scaffold( + body: SendButton( + isWorking: false, + onTap: () { + changedValue = 'Send'; + }, + ), + ), + ), + ); + + expect(find.byIcon(Icons.send), findsOneWidget); + expect(find.text(kLabelSend), findsOneWidget); + final button1 = find.byType(FilledButton); + expect(button1, findsOneWidget); + + await tester.tap(button1); + expect(changedValue, 'Send'); + }); + + testWidgets( + 'Testing for Send Request button when RequestModel is viewed and is waiting for response', + (tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'Send Request button', + theme: kThemeDataLight, + home: Scaffold( + body: SendButton( + isWorking: true, + onTap: () {}, + ), + ), + ), + ); + + expect(find.byIcon(Icons.send), findsNothing); + expect(find.text(kLabelSending), findsOneWidget); + final button1 = find.byType(FilledButton); + expect(button1, findsOneWidget); + + expect(tester.widget(button1).enabled, isFalse); + }); +} diff --git a/test/widgets/buttons_test.dart b/test/widgets/buttons_test.dart deleted file mode 100644 index d611d4f0..00000000 --- a/test/widgets/buttons_test.dart +++ /dev/null @@ -1,250 +0,0 @@ -import 'dart:typed_data'; -import 'package:apidash/screens/common_widgets/sidebar_save_button.dart'; -import 'package:apidash/widgets/widgets.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:apidash/consts.dart'; -import '../test_consts.dart'; - -void main() { - String copyText = 'This is a sample response generated by '; - testWidgets('Testing for copy button', (tester) async { - await tester.pumpWidget( - MaterialApp( - title: 'Copy Button', - home: Scaffold( - body: CopyButton(toCopy: copyText), - ), - ), - ); - - final icon = find.byIcon(Icons.content_copy); - expect(icon, findsOneWidget); - - Finder button; - if (tester.any(find.ancestor( - of: icon, - matching: find.byWidgetPredicate((widget) => widget is TextButton)))) { - expect(find.text(kLabelCopy), findsOneWidget); - button = find.ancestor( - of: icon, - matching: find.byWidgetPredicate((widget) => widget is TextButton)); - } else if (tester - .any(find.ancestor(of: icon, matching: find.byType(IconButton)))) { - button = find.byType(IconButton); - } else { - fail('No TextButton or IconButton found'); - } - - expect(button, findsOneWidget); - await tester.tap(button); - - //TODO: The below test works for `flutter run` but not for `flutter test` - //var data = await Clipboard.getData('text/plain'); - //expect(data?.text, copyText); - }); - - testWidgets('Testing for Send Request button', (tester) async { - dynamic changedValue; - await tester.pumpWidget( - MaterialApp( - title: 'Send Request button', - theme: kThemeDataLight, - home: Scaffold( - body: SendButton( - isWorking: false, - onTap: () { - changedValue = 'Send'; - }, - ), - ), - ), - ); - - expect(find.byIcon(Icons.send), findsOneWidget); - expect(find.text(kLabelSend), findsOneWidget); - final button1 = find.byType(FilledButton); - expect(button1, findsOneWidget); - - await tester.tap(button1); - expect(changedValue, 'Send'); - }); - - testWidgets( - 'Testing for Send Request button when RequestModel is viewed and is waiting for response', - (tester) async { - await tester.pumpWidget( - MaterialApp( - title: 'Send Request button', - theme: kThemeDataLight, - home: Scaffold( - body: SendButton( - isWorking: true, - onTap: () {}, - ), - ), - ), - ); - - expect(find.byIcon(Icons.send), findsNothing); - expect(find.text(kLabelSending), findsOneWidget); - final button1 = find.byType(FilledButton); - expect(button1, findsOneWidget); - - expect(tester.widget(button1).enabled, isFalse); - }); - - testWidgets('Testing for Save in Downloads button', (tester) async { - await tester.pumpWidget( - MaterialApp( - title: 'Save in Downloads button', - theme: kThemeDataLight, - home: const Scaffold( - body: SaveInDownloadsButton(), - ), - ), - ); - - final icon = find.byIcon(Icons.download); - expect(icon, findsOneWidget); - - Finder button; - if (tester.any(find.ancestor( - of: icon, - matching: find.byWidgetPredicate((widget) => widget is TextButton)))) { - expect(find.text(kLabelDownload), findsOneWidget); - button = find.ancestor( - of: icon, - matching: find.byWidgetPredicate((widget) => widget is TextButton)); - expect(button, findsOneWidget); - expect(tester.widget(button).enabled, isFalse); - } else if (tester - .any(find.ancestor(of: icon, matching: find.byType(IconButton)))) { - button = find.byType(IconButton); - expect(button, findsOneWidget); - expect(tester.widget(button).onPressed == null, isFalse); - } else { - fail('No TextButton or IconButton found'); - } - }); - - testWidgets('Testing for Save in Downloads button 2', (tester) async { - await tester.pumpWidget( - MaterialApp( - title: 'Save in Downloads button', - theme: kThemeDataLight, - home: Scaffold( - body: SaveInDownloadsButton( - content: Uint8List.fromList([1]), - ), - ), - ), - ); - - final icon = find.byIcon(Icons.download); - expect(icon, findsOneWidget); - - Finder button; - if (tester.any(find.ancestor( - of: icon, - matching: find.byWidgetPredicate((widget) => widget is TextButton)))) { - expect(find.text(kLabelDownload), findsOneWidget); - button = find.ancestor( - of: icon, - matching: find.byWidgetPredicate((widget) => widget is TextButton)); - expect(button, findsOneWidget); - expect(tester.widget(button).enabled, isTrue); - } else if (tester - .any(find.ancestor(of: icon, matching: find.byType(IconButton)))) { - button = find.byType(IconButton); - expect(button, findsOneWidget); - expect(tester.widget(button).onPressed == null, isTrue); - } else { - fail('No TextButton or IconButton found'); - } - }); - - testWidgets('Testing for Repo button', (tester) async { - await tester.pumpWidget( - MaterialApp( - title: 'Repo button', - theme: kThemeDataLight, - home: const Scaffold( - body: RepoButton( - icon: Icons.code, - ), - ), - ), - ); - - expect(find.byIcon(Icons.code), findsOneWidget); - expect(find.text("GitHub"), findsOneWidget); - }); - - testWidgets('Testing for Repo button icon = null', (tester) async { - await tester.pumpWidget( - MaterialApp( - title: 'Repo button', - theme: kThemeDataLight, - home: const Scaffold( - body: RepoButton(), - ), - ), - ); - - expect(find.byIcon(Icons.code), findsNothing); - expect(find.text("GitHub"), findsOneWidget); - - final button1 = find.byType(FilledButton); - expect(button1, findsOneWidget); - - expect(tester.widget(button1).enabled, isTrue); - }); - - testWidgets('Testing for Discord button', (tester) async { - await tester.pumpWidget( - MaterialApp( - title: 'Discord button', - theme: kThemeDataLight, - home: const Scaffold( - body: DiscordButton(), - ), - ), - ); - - expect(find.byIcon(Icons.discord), findsOneWidget); - expect(find.text("Discord Server"), findsOneWidget); - }); - - testWidgets('Testing for Save button', (tester) async { - await tester.pumpWidget( - ProviderScope( - child: MaterialApp( - title: 'Save button', - theme: kThemeDataLight, - home: const Scaffold( - body: SaveButton(), - ), - ), - ), - ); - - expect(find.byIcon(Icons.save), findsOneWidget); - expect(find.text("Save"), findsOneWidget); - }); - - testWidgets('Testing for ClearResponseButton', (tester) async { - await tester.pumpWidget( - MaterialApp( - title: 'ClearResponseButton', - theme: kThemeDataLight, - home: const Scaffold( - body: ClearResponseButton(), - ), - ), - ); - - expect(find.byIcon(Icons.delete), findsOneWidget); - }); -} diff --git a/test/widgets/card_request_details.dart b/test/widgets/card_request_details.dart new file mode 100644 index 00000000..bc5df725 --- /dev/null +++ b/test/widgets/card_request_details.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/widgets/widgets.dart'; + +void main() { + testWidgets('Testing Request Details Card', (tester) async { + await tester.pumpWidget( + const MaterialApp( + title: 'Request Details Card', + home: Scaffold( + body: RequestDetailsCard(child: SizedBox(height: 10, width: 10))), + ), + ); + + expect(find.byType(Card), findsOneWidget); + expect(find.byType(SizedBox), findsOneWidget); + }); +} diff --git a/test/widgets/card_sidebar_environment_test.dart b/test/widgets/card_sidebar_environment_test.dart new file mode 100644 index 00000000..f053127a --- /dev/null +++ b/test/widgets/card_sidebar_environment_test.dart @@ -0,0 +1,206 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/widgets/widgets.dart' + show SidebarEnvironmentCard, ItemCardMenu; + +import '../test_consts.dart'; + +Future pumpSidebarEnvironmentCard( + WidgetTester tester, { + required ThemeData theme, + required String id, + required String selectedId, + String? editRequestId, + bool isGlobal = false, + required String name, + Function()? onTap, + Function()? onDoubleTap, + Function(String)? onChangedNameEditor, + Function()? onTapOutsideNameEditor, + Function(dynamic)? onMenuSelected, +}) async { + await tester.pumpWidget( + MaterialApp( + title: 'Sidebar Environment Card', + theme: theme, + home: Scaffold( + body: ListView( + children: [ + SidebarEnvironmentCard( + id: id, + selectedId: selectedId, + editRequestId: editRequestId, + isGlobal: isGlobal, + name: name, + onTap: onTap, + onDoubleTap: onDoubleTap, + onChangedNameEditor: onChangedNameEditor, + onTapOutsideNameEditor: onTapOutsideNameEditor, + onMenuSelected: onMenuSelected, + ), + ], + ), + ), + ), + ); +} + +void main() { + testWidgets('Testing Sidebar Environment Card', (tester) async { + dynamic changedValue; + + await pumpSidebarEnvironmentCard( + tester, + theme: kThemeDataLight, + id: '23', + selectedId: '2', + name: 'Production', + onTap: () { + changedValue = 'Single Tapped'; + }, + onDoubleTap: () { + changedValue = 'Double Tapped'; + }, + ); + + expect(find.byType(InkWell), findsOneWidget); + expect(find.text('Production'), findsOneWidget); + expect(find.widgetWithText(SizedBox, 'Production'), findsOneWidget); + expect(find.widgetWithText(Card, 'Production'), findsOneWidget); + + var tappable = find.widgetWithText(Card, 'Production'); + await tester.tap(tappable); + await tester.pumpAndSettle(const Duration(seconds: 2)); + expect(changedValue, 'Single Tapped'); + }); + + testWidgets('Testing Sidebar Environment Card dark mode', (tester) async { + dynamic changedValue; + + await pumpSidebarEnvironmentCard( + tester, + theme: kThemeDataDark, + id: '23', + selectedId: '2', + name: 'Production', + onTap: () { + changedValue = 'Single Tapped'; + }, + onDoubleTap: () { + changedValue = 'Double Tapped'; + }, + ); + + expect(find.byType(InkWell), findsOneWidget); + expect(find.text('Production'), findsOneWidget); + expect(find.widgetWithText(SizedBox, 'Production'), findsOneWidget); + expect(find.widgetWithText(Card, 'Production'), findsOneWidget); + + var tappable = find.widgetWithText(Card, 'Production'); + await tester.tap(tappable); + await tester.pumpAndSettle(const Duration(seconds: 2)); + expect(changedValue, 'Single Tapped'); + }); + + testWidgets('Testing Sidebar Environment Card inEditMode', (tester) async { + dynamic changedValue; + + await pumpSidebarEnvironmentCard( + tester, + theme: kThemeDataLight, + id: '23', + selectedId: '23', + editRequestId: '23', + name: 'Production', + onChangedNameEditor: (value) { + changedValue = value; + }, + onTapOutsideNameEditor: () { + changedValue = 'Tapped Outside'; + }, + ); + + expect(find.byType(InkWell), findsOneWidget); + + var tappable = find.byType(TextFormField); + await tester.enterText(tappable, 'entering 123 for testing'); + await tester.pumpAndSettle(); + expect(changedValue, 'entering 123 for testing'); + + await tester.tapAt(const Offset(100, 100)); + await tester.pumpAndSettle(); + expect(changedValue, 'Tapped Outside'); + + await tester.enterText(tappable, 'New Name'); + await tester.testTextInput.receiveAction(TextInputAction.done); + expect(changedValue, "Tapped Outside"); + }); + + group("Testing Sidebar Environment Card Item Card Menu visibility", () { + testWidgets( + 'Environment ItemCardMenu should be visible when not in edit mode', + (tester) async { + await pumpSidebarEnvironmentCard( + tester, + theme: kThemeDataLight, + id: '23', + selectedId: '23', + isGlobal: false, + name: 'Production', + onMenuSelected: (value) {}, + ); + + expect(find.byType(ItemCardMenu), findsOneWidget); + }); + + testWidgets( + 'Environment ItemCardMenu should not be visible when in edit mode', + (tester) async { + await pumpSidebarEnvironmentCard( + tester, + theme: kThemeDataLight, + id: '23', + selectedId: '23', + editRequestId: '23', + isGlobal: false, + name: 'Production', + onMenuSelected: (value) {}, + ); + + expect(find.byType(ItemCardMenu), findsNothing); + }); + + testWidgets( + 'Environment ItemCardMenu should not be visible when not selected', + (tester) async { + await pumpSidebarEnvironmentCard( + tester, + theme: kThemeDataLight, + id: '23', + selectedId: '24', + editRequestId: '24', + isGlobal: false, + name: 'Production', + onMenuSelected: (value) {}, + ); + + expect(find.byType(ItemCardMenu), findsNothing); + }); + + testWidgets('Environment ItemCardMenu should not be visible if isGlobal', + (tester) async { + await pumpSidebarEnvironmentCard( + tester, + theme: kThemeDataLight, + id: '23', + selectedId: '23', + editRequestId: '24', + isGlobal: true, + name: 'Production', + onMenuSelected: (value) {}, + ); + + expect(find.byType(ItemCardMenu), findsNothing); + }); + }); +} diff --git a/test/widgets/cards_test.dart b/test/widgets/card_sidebar_request_test.dart similarity index 88% rename from test/widgets/cards_test.dart rename to test/widgets/card_sidebar_request_test.dart index b66288eb..d3ba3155 100644 --- a/test/widgets/cards_test.dart +++ b/test/widgets/card_sidebar_request_test.dart @@ -90,17 +90,9 @@ void main() { await tester.tapAt(const Offset(100, 100)); await tester.pumpAndSettle(); expect(changedValue, 'Tapped Outside'); - }); - testWidgets('Testing Request Details Card', (tester) async { - await tester.pumpWidget( - const MaterialApp( - title: 'Request Details Card', - home: Scaffold( - body: RequestDetailsCard(child: SizedBox(height: 10, width: 10))), - ), - ); - expect(find.byType(Card), findsOneWidget); - expect(find.byType(SizedBox), findsOneWidget); + await tester.enterText(tappable, 'New Name'); + await tester.testTextInput.receiveAction(TextInputAction.done); + expect(changedValue, "Tapped Outside"); }); } diff --git a/test/widgets/envvar__indicator_test.dart b/test/widgets/envvar__indicator_test.dart new file mode 100644 index 00000000..9dc9bdc6 --- /dev/null +++ b/test/widgets/envvar__indicator_test.dart @@ -0,0 +1,94 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/consts.dart'; +import 'package:apidash/models/models.dart'; +import 'package:apidash/screens/common_widgets/envvar_indicator.dart'; + +void main() { + testWidgets( + 'EnvVarIndicator displays correct icon and color for unknown suggestion', + (WidgetTester tester) async { + const suggestion = EnvironmentVariableSuggestion( + isUnknown: true, + environmentId: 'someId', + variable: EnvironmentVariableModel(key: 'key', value: 'value')); + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: EnvVarIndicator(suggestion: suggestion), + ), + ), + ); + + final container = tester.widget(find.byType(Container)); + final icon = tester.widget(find.byType(Icon)); + + expect(container.decoration, isA()); + final decoration = container.decoration as BoxDecoration; + expect( + decoration.color, + Theme.of(tester.element(find.byType(Container))) + .colorScheme + .errorContainer); + expect(icon.icon, Icons.block); + }); + + testWidgets( + 'EnvVarIndicator displays correct icon and color for global suggestion', + (WidgetTester tester) async { + const suggestion = EnvironmentVariableSuggestion( + isUnknown: false, + environmentId: kGlobalEnvironmentId, + variable: EnvironmentVariableModel(key: 'key', value: 'value')); + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: EnvVarIndicator(suggestion: suggestion), + ), + ), + ); + + final container = tester.widget(find.byType(Container)); + final icon = tester.widget(find.byType(Icon)); + + expect(container.decoration, isA()); + final decoration = container.decoration as BoxDecoration; + expect( + decoration.color, + Theme.of(tester.element(find.byType(Container))) + .colorScheme + .secondaryContainer); + expect(icon.icon, Icons.public); + }); + + testWidgets( + 'EnvVarIndicator displays correct icon and color for non-global suggestion', + (WidgetTester tester) async { + const suggestion = EnvironmentVariableSuggestion( + isUnknown: false, + environmentId: 'someOtherId', + variable: EnvironmentVariableModel(key: 'key', value: 'value')); + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: EnvVarIndicator(suggestion: suggestion), + ), + ), + ); + + final container = tester.widget(find.byType(Container)); + final icon = tester.widget(find.byType(Icon)); + + expect(container.decoration, isA()); + final decoration = container.decoration as BoxDecoration; + expect( + decoration.color, + Theme.of(tester.element(find.byType(Container))) + .colorScheme + .primaryContainer); + expect(icon.icon, Icons.computer); + }); +} diff --git a/test/widgets/envvar_popover_test.dart b/test/widgets/envvar_popover_test.dart new file mode 100644 index 00000000..8621a68a --- /dev/null +++ b/test/widgets/envvar_popover_test.dart @@ -0,0 +1,36 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/consts.dart'; +import 'package:apidash/models/models.dart'; +import 'package:apidash/screens/common_widgets/envvar_indicator.dart'; +import 'package:apidash/screens/common_widgets/envvar_popover.dart'; + +void main() { + testWidgets('EnvVarPopover displays correct information', + (WidgetTester tester) async { + const suggestion = EnvironmentVariableSuggestion( + isUnknown: false, + environmentId: 'someId', + variable: EnvironmentVariableModel(key: 'API_KEY', value: '12345'), + ); + const scope = 'Global'; + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: EnvVarPopover(suggestion: suggestion, scope: scope), + ), + ), + ); + + expect(find.byType(EnvVarIndicator), findsOneWidget); + + expect(find.text('API_KEY'), findsOneWidget); + + expect(find.text('VALUE'), findsOneWidget); + expect(find.text('12345'), findsOneWidget); + + expect(find.text('SCOPE'), findsOneWidget); + expect(find.text('Global'), findsOneWidget); + }); +} diff --git a/test/widgets/popup_menu_codegen_test.dart b/test/widgets/popup_menu_codegen_test.dart new file mode 100644 index 00000000..b613c686 --- /dev/null +++ b/test/widgets/popup_menu_codegen_test.dart @@ -0,0 +1,76 @@ +import 'package:apidash/consts.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/widgets/popup_menu_codegen.dart'; + +void main() { + testWidgets('CodegenPopupMenu displays initial value', + (WidgetTester tester) async { + const codegenLanguage = CodegenLanguage.dartDio; + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: CodegenPopupMenu( + value: codegenLanguage, + items: [codegenLanguage], + ), + ), + ), + ); + + expect(find.text(codegenLanguage.label), findsOneWidget); + }); + + testWidgets('CodegenPopupMenu displays popup menu items', + (WidgetTester tester) async { + const codegenLanguage1 = CodegenLanguage.dartDio; + const codegenLanguage2 = CodegenLanguage.pythonRequests; + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: CodegenPopupMenu( + items: [codegenLanguage1, codegenLanguage2], + value: codegenLanguage1, + ), + ), + ), + ); + + await tester.tap(find.byIcon(Icons.unfold_more)); + await tester.pumpAndSettle(); + + expect(find.text(codegenLanguage1.label), findsExactly(2)); + expect(find.text(codegenLanguage2.label), findsOneWidget); + }); + + testWidgets('CodegenPopupMenu calls onChanged when an item is selected', + (WidgetTester tester) async { + const codegenLanguage1 = CodegenLanguage.dartDio; + const codegenLanguage2 = CodegenLanguage.pythonRequests; + CodegenLanguage? selectedLanguage; + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: CodegenPopupMenu( + value: codegenLanguage1, + items: const [codegenLanguage1, codegenLanguage2], + onChanged: (value) { + selectedLanguage = value; + }, + ), + ), + ), + ); + + await tester.tap(find.byIcon(Icons.unfold_more)); + await tester.pumpAndSettle(); + + await tester.tap(find.text(codegenLanguage2.label).last); + await tester.pumpAndSettle(); + + expect(selectedLanguage, codegenLanguage2); + }); +} diff --git a/test/widgets/popup_menu_env_test.dart b/test/widgets/popup_menu_env_test.dart new file mode 100644 index 00000000..cbb3b5f5 --- /dev/null +++ b/test/widgets/popup_menu_env_test.dart @@ -0,0 +1,118 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/models/models.dart'; +import 'package:apidash/widgets/popup_menu_env.dart'; + +void main() { + testWidgets('EnvironmentPopupMenu displays initial value', + (WidgetTester tester) async { + const environment = EnvironmentModel(name: 'Production', id: 'prod'); + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: EnvironmentPopupMenu( + value: environment, + items: [environment], + ), + ), + ), + ); + + expect(find.text('Production'), findsOneWidget); + }); + + testWidgets('EnvironmentPopupMenu displays "None" when no value is provided', + (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: EnvironmentPopupMenu( + items: [], + ), + ), + ), + ); + + expect(find.text('None'), findsOneWidget); + }); + + testWidgets('EnvironmentPopupMenu displays popup menu items', + (WidgetTester tester) async { + const environment1 = EnvironmentModel(name: 'Production', id: 'prod'); + const environment2 = EnvironmentModel(name: 'Development', id: 'dev'); + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: EnvironmentPopupMenu( + items: [environment1, environment2], + ), + ), + ), + ); + + await tester.tap(find.byIcon(Icons.unfold_more)); + await tester.pumpAndSettle(); + + expect(find.text('None'), findsExactly(2)); + expect(find.text('Production'), findsOneWidget); + expect(find.text('Development'), findsOneWidget); + }); + + testWidgets('EnvironmentPopupMenu calls onChanged when an item is selected', + (WidgetTester tester) async { + const environment1 = EnvironmentModel(name: 'Production', id: 'prod'); + const environment2 = EnvironmentModel(name: 'Development', id: 'dev'); + EnvironmentModel? selectedEnvironment; + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: EnvironmentPopupMenu( + items: const [environment1, environment2], + onChanged: (value) { + selectedEnvironment = value; + }, + ), + ), + ), + ); + + await tester.tap(find.byIcon(Icons.unfold_more)); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Development').last); + await tester.pumpAndSettle(); + + expect(selectedEnvironment, environment2); + }); + + testWidgets( + 'EnvironmentPopupMenu calls onChanged with null when "None" is selected', + (WidgetTester tester) async { + const environment = EnvironmentModel(name: 'Production', id: 'prod'); + EnvironmentModel? selectedEnvironment = environment; + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: EnvironmentPopupMenu( + items: const [environment], + onChanged: (value) { + selectedEnvironment = value; + }, + ), + ), + ), + ); + + await tester.tap(find.byIcon(Icons.unfold_more)); + await tester.pumpAndSettle(); + + await tester.tap(find.text('None').last); + await tester.pumpAndSettle(); + + expect(selectedEnvironment, isNull); + }); +} diff --git a/test/widgets/popup_menu_uri_test.dart b/test/widgets/popup_menu_uri_test.dart new file mode 100644 index 00000000..f27432ee --- /dev/null +++ b/test/widgets/popup_menu_uri_test.dart @@ -0,0 +1,75 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/widgets/popup_menu_uri.dart'; + +void main() { + testWidgets('URIPopupMenu displays initial value', + (WidgetTester tester) async { + const uriScheme = 'https'; + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: URIPopupMenu( + value: uriScheme, + items: [uriScheme], + ), + ), + ), + ); + + expect(find.text(uriScheme), findsOneWidget); + }); + + testWidgets('URIPopupMenu displays popup menu items', + (WidgetTester tester) async { + const uriScheme1 = 'https'; + const uriScheme2 = 'http'; + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: URIPopupMenu( + items: [uriScheme1, uriScheme2], + value: uriScheme1, + ), + ), + ), + ); + + await tester.tap(find.byIcon(Icons.unfold_more)); + await tester.pumpAndSettle(); + + expect(find.text(uriScheme1), findsExactly(2)); + expect(find.text(uriScheme2), findsOneWidget); + }); + + testWidgets('URIPopupMenu calls onChanged when an item is selected', + (WidgetTester tester) async { + const uriScheme1 = 'https'; + const uriScheme2 = 'http'; + String? selectedScheme; + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: URIPopupMenu( + value: uriScheme1, + items: const [uriScheme1, uriScheme2], + onChanged: (value) { + selectedScheme = value; + }, + ), + ), + ), + ); + + await tester.tap(find.byIcon(Icons.unfold_more)); + await tester.pumpAndSettle(); + + await tester.tap(find.text(uriScheme2).last); + await tester.pumpAndSettle(); + + expect(selectedScheme, uriScheme2); + }); +} diff --git a/test/widgets/sidebar_save_button_test.dart b/test/widgets/sidebar_save_button_test.dart new file mode 100644 index 00000000..2ecb0cec --- /dev/null +++ b/test/widgets/sidebar_save_button_test.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/screens/common_widgets/sidebar_save_button.dart'; +import '../test_consts.dart'; + +void main() { + testWidgets('Testing for Save button', (tester) async { + await tester.pumpWidget( + ProviderScope( + child: MaterialApp( + title: 'Save button', + theme: kThemeDataLight, + home: const Scaffold( + body: SaveButton(), + ), + ), + ), + ); + + expect(find.byIcon(Icons.save), findsOneWidget); + expect(find.text("Save"), findsOneWidget); + }); +} diff --git a/test/widgets/splitview_dashboard_test.dart b/test/widgets/splitview_dashboard_test.dart new file mode 100644 index 00000000..b0c3ab11 --- /dev/null +++ b/test/widgets/splitview_dashboard_test.dart @@ -0,0 +1,25 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:multi_split_view/multi_split_view.dart'; +import 'package:apidash/widgets/widgets.dart'; + +void main() { + testWidgets('Testing for Dashboard Splitview', (tester) async { + await tester.pumpWidget( + const MaterialApp( + title: 'Dashboard Splitview', + home: Scaffold( + body: DashboardSplitView( + sidebarWidget: Column(children: [Text("Hello")]), + mainWidget: Column(children: [Text("World")]), + ), + ), + ), + ); + + expect(find.text("World"), findsOneWidget); + expect(find.text("Hello"), findsOneWidget); + expect(find.byType(MultiSplitViewTheme), findsOneWidget); + }); + //TODO: Divider not visible on flutter run. Investigate. +} diff --git a/test/widgets/splitview_drawer_test.dart b/test/widgets/splitview_drawer_test.dart new file mode 100644 index 00000000..da244097 --- /dev/null +++ b/test/widgets/splitview_drawer_test.dart @@ -0,0 +1,97 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/widgets/splitview_drawer.dart'; + +void main() { + testWidgets('DrawerSplitView displays main components', (tester) async { + final scaffoldKey = GlobalKey(); + + await tester.pumpWidget( + MaterialApp( + home: DrawerSplitView( + scaffoldKey: scaffoldKey, + mainContent: const Text('Main Content'), + title: const Text('Title'), + leftDrawerContent: const Text('Left Drawer Content'), + rightDrawerContent: const Text('Right Drawer Content'), + ), + ), + ); + + // Verify the main content is displayed + expect(find.text('Main Content'), findsOneWidget); + + // Verify the title is displayed + expect(find.text('Title'), findsOneWidget); + + // Verify the left drawer content is not displayed initially + expect(find.text('Left Drawer Content'), findsNothing); + + // Verify the right drawer content is not displayed initially + expect(find.text('Right Drawer Content'), findsNothing); + }); + + testWidgets('DrawerSplitView opens left drawer', (tester) async { + final scaffoldKey = GlobalKey(); + + await tester.pumpWidget( + MaterialApp( + home: DrawerSplitView( + scaffoldKey: scaffoldKey, + mainContent: const Text('Main Content'), + title: const Text('Title'), + leftDrawerContent: const Text('Left Drawer Content'), + ), + ), + ); + + // Tap the leading icon to open the left drawer + await tester.tap(find.byIcon(Icons.format_list_bulleted_rounded)); + await tester.pumpAndSettle(); + + // Verify the left drawer content is displayed + expect(find.text('Left Drawer Content'), findsOneWidget); + }); + + testWidgets('DrawerSplitView opens right drawer', (tester) async { + final scaffoldKey = GlobalKey(); + + await tester.pumpWidget( + MaterialApp( + home: DrawerSplitView( + scaffoldKey: scaffoldKey, + mainContent: const Text('Main Content'), + title: const Text('Title'), + rightDrawerContent: const Text('Right Drawer Content'), + ), + ), + ); + + // Tap the right drawer icon to open the right drawer + await tester.tap(find.byIcon(Icons.arrow_forward)); + await tester.pumpAndSettle(); + + // Verify the right drawer content is displayed + expect(find.text('Right Drawer Content'), findsOneWidget); + }); + + testWidgets('DrawerSplitView displays actions', (tester) async { + final scaffoldKey = GlobalKey(); + + await tester.pumpWidget( + MaterialApp( + home: DrawerSplitView( + scaffoldKey: scaffoldKey, + mainContent: const Text('Main Content'), + title: const Text('Title'), + actions: [ + IconButton(icon: const Icon(Icons.search), onPressed: () {}) + ], + ), + ), + ); + + // Verify the action icon is displayed + expect(find.byIcon(Icons.search), findsOneWidget); + }); +} diff --git a/test/widgets/splitviews_test.dart b/test/widgets/splitview_equal_test.dart similarity index 60% rename from test/widgets/splitviews_test.dart rename to test/widgets/splitview_equal_test.dart index b8d074b1..c917a22b 100644 --- a/test/widgets/splitviews_test.dart +++ b/test/widgets/splitview_equal_test.dart @@ -4,23 +4,6 @@ import 'package:multi_split_view/multi_split_view.dart'; import 'package:apidash/widgets/widgets.dart'; void main() { - testWidgets('Testing for Dashboard Splitview', (tester) async { - await tester.pumpWidget( - const MaterialApp( - title: 'Dashboard Splitview', - home: Scaffold( - body: DashboardSplitView( - sidebarWidget: Column(children: [Text("Hello")]), - mainWidget: Column(children: [Text("World")]), - ), - ), - ), - ); - - expect(find.text("World"), findsOneWidget); - expect(find.text("Hello"), findsOneWidget); - expect(find.byType(MultiSplitViewTheme), findsOneWidget); - }); testWidgets('Testing for Equal SplitView', (tester) async { await tester.pumpWidget( const MaterialApp( diff --git a/test/widgets/tabs_test.dart b/test/widgets/tabs_test.dart new file mode 100644 index 00000000..7aaee00c --- /dev/null +++ b/test/widgets/tabs_test.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/widgets/tabs.dart'; + +void main() { + testWidgets('TabLabel shows indicator when showIndicator is true', + (tester) async { + const String labelText = 'URL Params'; + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: TabLabel( + text: labelText, + showIndicator: true, + ), + ), + ), + ); + + expect(find.text(labelText), findsOneWidget); + expect(find.byIcon(Icons.circle), findsOneWidget); + }); + + testWidgets('TabLabel does not show indicator when showIndicator is false', + (tester) async { + const String labelText = 'Request'; + + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: TabLabel( + text: labelText, + showIndicator: false, + ), + ), + ), + ); + + expect(find.text(labelText), findsOneWidget); + expect(find.byIcon(Icons.circle), findsNothing); + }); +}