-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #443 from JeetDalal/resolve-issue-#178
resolved issue #178(switch from GET->POST if payload exists)
- Loading branch information
Showing
12 changed files
with
209 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,6 @@ coverage/* | |
installers/* | ||
.metadata | ||
.fvm/ | ||
|
||
# Testing Files & Folders | ||
test-hive-storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:apidash/consts.dart'; | ||
import 'package:apidash/screens/home_page/editor_pane/details_card/request_pane/request_body.dart'; | ||
import 'package:apidash/widgets/editor.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:apidash/providers/providers.dart'; | ||
import 'helpers.dart'; | ||
|
||
void main() async { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
setUp(() async { | ||
await testSetUpTempDirForHive(); | ||
}); | ||
|
||
testWidgets( | ||
'Request method changes from GET to POST when body is added and Snackbar is shown', | ||
(WidgetTester tester) async { | ||
// Set up the test environment | ||
final container = createContainer(); | ||
final notifier = container.read(collectionStateNotifierProvider.notifier); | ||
|
||
// Ensure the initial request is a GET request with no body | ||
final id = notifier.state!.entries.first.key; | ||
expect( | ||
notifier.getRequestModel(id)!.httpRequestModel!.method, HTTPVerb.get); | ||
expect(notifier.getRequestModel(id)!.httpRequestModel!.body, isNull); | ||
|
||
// Build the EditRequestBody widget | ||
await tester.pumpWidget( | ||
ProviderScope( | ||
// ignore: deprecated_member_use | ||
parent: container, | ||
child: const MaterialApp( | ||
home: Scaffold( | ||
body: EditRequestBody(), | ||
), | ||
), | ||
), | ||
); | ||
|
||
// Add a body to the request, which should trigger the method change | ||
await tester.enterText(find.byType(TextFieldEditor), 'new body added'); | ||
await tester.pump(); // Process the state change | ||
|
||
// Verify that the request method changed to POST | ||
expect( | ||
notifier.getRequestModel(id)!.httpRequestModel!.method, HTTPVerb.post); | ||
|
||
// Verify that the Snackbar is shown | ||
expect(find.text('Switched to POST method'), findsOneWidget); | ||
}, skip: true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'dart:io'; | ||
import 'package:apidash/services/hive_services.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
/// A testing utility which creates a [ProviderContainer] and automatically | ||
/// disposes it at the end of the test. | ||
ProviderContainer createContainer({ | ||
ProviderContainer? parent, | ||
List<Override> overrides = const [], | ||
List<ProviderObserver>? observers, | ||
}) { | ||
// Create a ProviderContainer, and optionally allow specifying parameters. | ||
final container = ProviderContainer( | ||
parent: parent, | ||
overrides: overrides, | ||
observers: observers, | ||
); | ||
|
||
// When the test ends, dispose the container. | ||
addTearDown(container.dispose); | ||
|
||
return container; | ||
} | ||
|
||
Future<void> testSetUpForHive() async { | ||
// override path_provider methodCall to point | ||
// path to temporary location for all unit tests | ||
const MethodChannel channel = | ||
MethodChannel('plugins.flutter.io/path_provider'); | ||
|
||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger | ||
.setMockMethodCallHandler(channel, (MethodCall methodCall) async { | ||
return './test-hive-storage/'; | ||
}); | ||
|
||
await initHiveBoxes(false, null); | ||
// await deleteHiveBoxes(); | ||
// await openHiveBoxes(); | ||
} | ||
|
||
Future<void> testSetUpTempDirForHive() async { | ||
const MethodChannel channel = | ||
MethodChannel('plugins.flutter.io/path_provider'); | ||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger | ||
.setMockMethodCallHandler(channel, (MethodCall methodCall) async { | ||
if (methodCall.method == 'getApplicationDocumentsDirectory') { | ||
// Create a mock app doc directory for testing | ||
Directory tempDir = | ||
await Directory.systemTemp.createTemp('mock_app_doc_dir'); | ||
return tempDir.path; // Return the path to the mock directory | ||
} | ||
return null; | ||
}); | ||
await initHiveBoxes(false, null); | ||
} |
Oops, something went wrong.