mirror of
https://github.com/foss42/apidash.git
synced 2025-05-22 00:36:43 +08:00
Migrate to Dart 3
This commit is contained in:
@ -13,7 +13,7 @@ void main() async {
|
||||
await setupInitialWindow();
|
||||
} else {
|
||||
var win = getInitialSize();
|
||||
await setupWindow(sz: win.$0, off: win.$1);
|
||||
await setupWindow(sz: win.$1, off: win.$2);
|
||||
}
|
||||
runApp(
|
||||
ProviderScope(
|
||||
|
@ -132,17 +132,17 @@ class CollectionStateNotifier extends StateNotifier<List<RequestModel>?> {
|
||||
var responseRec =
|
||||
await request(requestModel, defaultUriScheme: defaultUriScheme);
|
||||
late final RequestModel newRequestModel;
|
||||
if (responseRec.$0 == null) {
|
||||
if (responseRec.$1 == null) {
|
||||
newRequestModel = requestModel.copyWith(
|
||||
responseStatus: -1,
|
||||
message: responseRec.$2,
|
||||
message: responseRec.$3,
|
||||
);
|
||||
} else {
|
||||
final responseModel = baseResponseModel.fromResponse(
|
||||
response: responseRec.$0!,
|
||||
time: responseRec.$1!,
|
||||
response: responseRec.$1!,
|
||||
time: responseRec.$2!,
|
||||
);
|
||||
int statusCode = responseRec.$0!.statusCode;
|
||||
int statusCode = responseRec.$1!.statusCode;
|
||||
newRequestModel = requestModel.copyWith(
|
||||
responseStatus: statusCode,
|
||||
message: kResponseCodeReasons[statusCode],
|
||||
|
@ -25,11 +25,11 @@ class _EditRequestBodyState extends ConsumerState<EditRequestBody> {
|
||||
margin: kPt5o10,
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
const SizedBox(
|
||||
height: kHeaderHeight,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
children: [
|
||||
Text(
|
||||
"Select Content Type:",
|
||||
),
|
||||
|
@ -28,8 +28,8 @@ class _RequestEditorPaneState extends ConsumerState<RequestEditorPane> {
|
||||
} else {
|
||||
return Padding(
|
||||
padding: kIsMacOS ? kPt24o8 : kP8,
|
||||
child: Column(
|
||||
children: const [
|
||||
child: const Column(
|
||||
children: [
|
||||
EditorPaneRequestURLCard(),
|
||||
kVSpacer10,
|
||||
Expanded(
|
||||
|
@ -28,13 +28,13 @@ class _EditorPaneRequestURLCardState extends State<EditorPaneRequestURLCard> {
|
||||
),
|
||||
borderRadius: kBorderRadius12,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 5,
|
||||
horizontal: 20,
|
||||
),
|
||||
child: Row(
|
||||
children: const [
|
||||
children: [
|
||||
DropdownButtonHTTPMethod(),
|
||||
kHSpacer20,
|
||||
Expanded(
|
||||
|
@ -13,8 +13,8 @@ class HomePage extends StatefulWidget {
|
||||
class HomePageState extends State<HomePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: const [
|
||||
return const Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: DashboardSplitView(
|
||||
sidebarWidget: CollectionPane(),
|
||||
|
@ -7,66 +7,59 @@ import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
|
||||
Future<(http.Response?, Duration?, String?)> request(
|
||||
RequestModel requestModel,
|
||||
{String defaultUriScheme = kDefaultUriScheme}
|
||||
) async {
|
||||
(Uri?, String?) uriRec = getValidRequestUri(requestModel.url,
|
||||
requestModel.requestParams,
|
||||
defaultUriScheme: defaultUriScheme);
|
||||
if(uriRec.$0 != null){
|
||||
Uri requestUrl = uriRec.$0!;
|
||||
RequestModel requestModel, {
|
||||
String defaultUriScheme = kDefaultUriScheme,
|
||||
}) async {
|
||||
(Uri?, String?) uriRec = getValidRequestUri(
|
||||
requestModel.url,
|
||||
requestModel.requestParams,
|
||||
defaultUriScheme: defaultUriScheme,
|
||||
);
|
||||
if (uriRec.$1 != null) {
|
||||
Uri requestUrl = uriRec.$1!;
|
||||
Map<String, String> headers = rowsToMap(requestModel.requestHeaders) ?? {};
|
||||
http.Response response;
|
||||
String? body;
|
||||
try {
|
||||
try {
|
||||
var requestBody = requestModel.requestBody;
|
||||
if(kMethodsWithBody.contains(requestModel.method) && requestBody != null){
|
||||
if (kMethodsWithBody.contains(requestModel.method) &&
|
||||
requestBody != null) {
|
||||
var contentLength = utf8.encode(requestBody).length;
|
||||
if (contentLength > 0){
|
||||
if (contentLength > 0) {
|
||||
body = requestBody;
|
||||
headers[HttpHeaders.contentLengthHeader] = contentLength.toString();
|
||||
headers[HttpHeaders.contentTypeHeader] = kContentTypeMap[requestModel.requestBodyContentType] ?? "";
|
||||
headers[HttpHeaders.contentTypeHeader] =
|
||||
kContentTypeMap[requestModel.requestBodyContentType] ?? "";
|
||||
}
|
||||
}
|
||||
Stopwatch stopwatch = Stopwatch()..start();
|
||||
switch(requestModel.method){
|
||||
switch (requestModel.method) {
|
||||
case HTTPVerb.get:
|
||||
response = await http.get(requestUrl,
|
||||
headers: headers);
|
||||
response = await http.get(requestUrl, headers: headers);
|
||||
break;
|
||||
case HTTPVerb.head:
|
||||
response = await http.head(requestUrl,
|
||||
headers: headers);
|
||||
response = await http.head(requestUrl, headers: headers);
|
||||
break;
|
||||
case HTTPVerb.post:
|
||||
response = await http.post(requestUrl,
|
||||
headers: headers,
|
||||
body: body);
|
||||
response = await http.post(requestUrl, headers: headers, body: body);
|
||||
break;
|
||||
case HTTPVerb.put:
|
||||
response = await http.put(requestUrl,
|
||||
headers: headers,
|
||||
body: body);
|
||||
response = await http.put(requestUrl, headers: headers, body: body);
|
||||
break;
|
||||
case HTTPVerb.patch:
|
||||
response = await http.patch(requestUrl,
|
||||
headers: headers,
|
||||
body: body);
|
||||
response = await http.patch(requestUrl, headers: headers, body: body);
|
||||
break;
|
||||
case HTTPVerb.delete:
|
||||
response = await http.delete(requestUrl,
|
||||
headers: headers,
|
||||
body: body);
|
||||
response =
|
||||
await http.delete(requestUrl, headers: headers, body: body);
|
||||
break;
|
||||
}
|
||||
stopwatch.stop();
|
||||
stopwatch.stop();
|
||||
return (response, stopwatch.elapsed, null);
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
return (null, null, e.toString());
|
||||
}
|
||||
}
|
||||
else {
|
||||
return (null, null, uriRec.$1);
|
||||
} else {
|
||||
return (null, null, uriRec.$2);
|
||||
}
|
||||
}
|
||||
|
@ -44,8 +44,8 @@ MediaType? getMediaTypeFromHeaders(Map? headers) {
|
||||
}
|
||||
|
||||
(String?, bool) getUriScheme(Uri uri) {
|
||||
if(uri.hasScheme){
|
||||
if(kSupportedUriSchemes.contains(uri.scheme)){
|
||||
if (uri.hasScheme) {
|
||||
if (kSupportedUriSchemes.contains(uri.scheme)) {
|
||||
return (uri.scheme, true);
|
||||
}
|
||||
return (uri.scheme, false);
|
||||
@ -53,38 +53,34 @@ MediaType? getMediaTypeFromHeaders(Map? headers) {
|
||||
return (null, false);
|
||||
}
|
||||
|
||||
(Uri?, String?) getValidRequestUri(
|
||||
String? url,
|
||||
List<KVRow>? requestParams,
|
||||
{String defaultUriScheme = kDefaultUriScheme}
|
||||
) {
|
||||
(Uri?, String?) getValidRequestUri(String? url, List<KVRow>? requestParams,
|
||||
{String defaultUriScheme = kDefaultUriScheme}) {
|
||||
url = url?.trim();
|
||||
if(url == null || url == ""){
|
||||
if (url == null || url == "") {
|
||||
return (null, "URL is missing!");
|
||||
}
|
||||
Uri? uri = Uri.tryParse(url);
|
||||
if(uri == null){
|
||||
Uri? uri = Uri.tryParse(url);
|
||||
if (uri == null) {
|
||||
return (null, "Check URL (malformed)");
|
||||
}
|
||||
(String?, bool) urlScheme = getUriScheme(uri);
|
||||
|
||||
if(urlScheme.$0 != null){
|
||||
if (!urlScheme.$1){
|
||||
return (null, "Unsupported URL Scheme (${urlScheme.$0})");
|
||||
if (urlScheme.$1 != null) {
|
||||
if (!urlScheme.$2) {
|
||||
return (null, "Unsupported URL Scheme (${urlScheme.$1})");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
url = "$defaultUriScheme://$url";
|
||||
}
|
||||
|
||||
uri = Uri.parse(url);
|
||||
if (uri.hasFragment){
|
||||
uri = Uri.parse(url);
|
||||
if (uri.hasFragment) {
|
||||
uri = uri.removeFragment();
|
||||
}
|
||||
|
||||
Map<String, String>? queryParams = rowsToMap(requestParams);
|
||||
if(queryParams != null){
|
||||
if(uri.hasQuery){
|
||||
if (queryParams != null) {
|
||||
if (uri.hasQuery) {
|
||||
Map<String, String> urlQueryParams = uri.queryParameters;
|
||||
queryParams = mergeMaps(urlQueryParams, queryParams);
|
||||
}
|
||||
@ -93,48 +89,58 @@ MediaType? getMediaTypeFromHeaders(Map? headers) {
|
||||
return (uri, null);
|
||||
}
|
||||
|
||||
(List<ResponseBodyView>, String?) getResponseBodyViewOptions(MediaType? mediaType){
|
||||
if(mediaType != null){
|
||||
(List<ResponseBodyView>, String?) getResponseBodyViewOptions(
|
||||
MediaType? mediaType) {
|
||||
if (mediaType != null) {
|
||||
var type = mediaType.type;
|
||||
var subtype = mediaType.subtype;
|
||||
if(kResponseBodyViewOptions.containsKey(type)){
|
||||
if (kResponseBodyViewOptions[type]!.containsKey(subtype)){
|
||||
return (kResponseBodyViewOptions[type]![subtype]!, kCodeHighlighterMap[subtype] ?? subtype);
|
||||
if (kResponseBodyViewOptions.containsKey(type)) {
|
||||
if (kResponseBodyViewOptions[type]!.containsKey(subtype)) {
|
||||
return (
|
||||
kResponseBodyViewOptions[type]![subtype]!,
|
||||
kCodeHighlighterMap[subtype] ?? subtype
|
||||
);
|
||||
}
|
||||
if(subtype.contains(kSubTypeJson)){
|
||||
if (subtype.contains(kSubTypeJson)) {
|
||||
subtype = kSubTypeJson;
|
||||
}
|
||||
if(subtype.contains(kSubTypeXml)){
|
||||
if (subtype.contains(kSubTypeXml)) {
|
||||
subtype = kSubTypeXml;
|
||||
}
|
||||
if (kResponseBodyViewOptions[type]!.containsKey(subtype)){
|
||||
return (kResponseBodyViewOptions[type]![subtype]!, kCodeHighlighterMap[subtype] ?? subtype);
|
||||
if (kResponseBodyViewOptions[type]!.containsKey(subtype)) {
|
||||
return (
|
||||
kResponseBodyViewOptions[type]![subtype]!,
|
||||
kCodeHighlighterMap[subtype] ?? subtype
|
||||
);
|
||||
}
|
||||
return (kResponseBodyViewOptions[type]![kSubTypeDefaultViewOptions]!, subtype);
|
||||
return (
|
||||
kResponseBodyViewOptions[type]![kSubTypeDefaultViewOptions]!,
|
||||
subtype
|
||||
);
|
||||
}
|
||||
}
|
||||
return (kNoBodyViewOptions, null);
|
||||
}
|
||||
|
||||
String? formatBody(String? body, MediaType? mediaType){
|
||||
if(mediaType != null && body != null){
|
||||
String? formatBody(String? body, MediaType? mediaType) {
|
||||
if (mediaType != null && body != null) {
|
||||
var subtype = mediaType.subtype;
|
||||
try {
|
||||
if(subtype.contains(kSubTypeJson)){
|
||||
if (subtype.contains(kSubTypeJson)) {
|
||||
final tmp = jsonDecode(body);
|
||||
String result = kEncoder.convert(tmp);
|
||||
return result;
|
||||
}
|
||||
if(subtype.contains(kSubTypeXml)){
|
||||
if (subtype.contains(kSubTypeXml)) {
|
||||
final document = XmlDocument.parse(body);
|
||||
String result = document.toXmlString(pretty: true, indent: ' ');
|
||||
return result;
|
||||
}
|
||||
if(subtype == kSubTypeHtml){
|
||||
if (subtype == kSubTypeHtml) {
|
||||
var len = body.length;
|
||||
var lines = kSplitter.convert(body);
|
||||
var numOfLines = lines.length;
|
||||
if(numOfLines !=0 && len/numOfLines <= kCodeCharsPerLineLimit){
|
||||
if (numOfLines != 0 && len / numOfLines <= kCodeCharsPerLineLimit) {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
@ -143,4 +149,4 @@ String? formatBody(String? body, MediaType? mediaType){
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import 'error_message.dart';
|
||||
(String, bool) sanitize(String input) {
|
||||
bool limitedLines = false;
|
||||
int tabSize = 4;
|
||||
var lines = kSplitter.convert(input);
|
||||
var lines = kSplitter.convert(input);
|
||||
if (lines.length > kCodePreviewLinesLimit) {
|
||||
lines = lines.sublist(0, kCodePreviewLinesLimit);
|
||||
limitedLines = true;
|
||||
@ -67,7 +67,12 @@ class _CodePreviewerState extends State<CodePreviewer> {
|
||||
textStyle = textStyle.merge(widget.textStyle);
|
||||
}
|
||||
processed = sanitize(widget.code);
|
||||
spans = asyncGenerateSpans(processed.$0, widget.language, widget.theme, processed.$1);
|
||||
spans = asyncGenerateSpans(
|
||||
processed.$1,
|
||||
widget.language,
|
||||
widget.theme,
|
||||
processed.$2,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -131,12 +136,14 @@ class _CodePreviewerState extends State<CodePreviewer> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<TextSpan>> asyncGenerateSpans(
|
||||
String code, String? language, Map<String, TextStyle> theme, bool limitedLines) async {
|
||||
Future<List<TextSpan>> asyncGenerateSpans(String code, String? language,
|
||||
Map<String, TextStyle> theme, bool limitedLines) async {
|
||||
var parsed = highlight.parse(code, language: language);
|
||||
var spans = convert(parsed.nodes!, theme);
|
||||
if(limitedLines) {
|
||||
spans.add(const TextSpan(text: "\n... more.\nPreview ends here ($kCodePreviewLinesLimit lines).\nYou can check Raw for full result."));
|
||||
if (limitedLines) {
|
||||
spans.add(const TextSpan(
|
||||
text:
|
||||
"\n... more.\nPreview ends here ($kCodePreviewLinesLimit lines).\nYou can check Raw for full result."));
|
||||
}
|
||||
return spans;
|
||||
}
|
||||
|
@ -339,8 +339,8 @@ class _ResponseBodyState extends State<ResponseBody> {
|
||||
}
|
||||
|
||||
var responseBodyView = getResponseBodyViewOptions(mediaType);
|
||||
var options = responseBodyView.$0;
|
||||
var highlightLanguage = responseBodyView.$1;
|
||||
var options = responseBodyView.$1;
|
||||
var highlightLanguage = responseBodyView.$2;
|
||||
|
||||
if (formattedBody == null) {
|
||||
options = [...options];
|
||||
|
@ -156,22 +156,20 @@ void main() {
|
||||
path: 'guides/libraries/library-tour',
|
||||
fragment: 'numbers');
|
||||
String uriScheme1Expected = 'https';
|
||||
expect(getUriScheme(uri1), (uriScheme1Expected,true));
|
||||
expect(getUriScheme(uri1), (uriScheme1Expected, true));
|
||||
});
|
||||
test('Testing getUriScheme for mailto scheme value', () {
|
||||
Uri uri2 = Uri(scheme: 'mailto');
|
||||
String uriScheme2Expected = 'mailto';
|
||||
expect(getUriScheme(uri2), (uriScheme2Expected,false));
|
||||
expect(getUriScheme(uri2), (uriScheme2Expected, false));
|
||||
});
|
||||
test('Testing getUriScheme for empty scheme value', () {
|
||||
Uri uri3 = Uri(
|
||||
scheme: '');
|
||||
expect(getUriScheme(uri3), (null,false));
|
||||
Uri uri3 = Uri(scheme: '');
|
||||
expect(getUriScheme(uri3), (null, false));
|
||||
});
|
||||
test('Testing getUriScheme for null scheme value', () {
|
||||
Uri uri4 = Uri(
|
||||
scheme: null);
|
||||
expect(getUriScheme(uri4), (null,false));
|
||||
Uri uri4 = Uri(scheme: null);
|
||||
expect(getUriScheme(uri4), (null, false));
|
||||
});
|
||||
});
|
||||
|
||||
@ -183,7 +181,7 @@ void main() {
|
||||
scheme: 'https',
|
||||
host: 'api.foss42.com',
|
||||
path: 'country/data',
|
||||
queryParameters: {'code':'US'});
|
||||
queryParameters: {'code': 'US'});
|
||||
expect(getValidRequestUri(url1, [kvRow1]), (uri1Expected, null));
|
||||
});
|
||||
test('Testing getValidRequestUri for null url value', () {
|
||||
@ -201,29 +199,31 @@ void main() {
|
||||
scheme: 'https',
|
||||
host: 'api.foss42.com',
|
||||
path: 'country/data',
|
||||
queryParameters: {'code':'US'});
|
||||
queryParameters: {'code': 'US'});
|
||||
expect(getValidRequestUri(url4, [kvRow4]), (uri4Expected, null));
|
||||
});
|
||||
test('Testing getValidRequestUri when url has fragment', () {
|
||||
String url5 = "https://dart.dev/guides/libraries/library-tour#numbers";
|
||||
Uri uri5Expected = Uri(
|
||||
scheme: 'https',
|
||||
host: 'dart.dev',
|
||||
path: '/guides/libraries/library-tour');
|
||||
scheme: 'https',
|
||||
host: 'dart.dev',
|
||||
path: '/guides/libraries/library-tour');
|
||||
expect(getValidRequestUri(url5, null), (uri5Expected, null));
|
||||
});
|
||||
test('Testing getValidRequestUri when uri scheme is not supported', () {
|
||||
String url5 = "mailto:someone@example.com";
|
||||
expect(getValidRequestUri(url5, null), (null, "Unsupported URL Scheme (mailto)"));
|
||||
expect(getValidRequestUri(url5, null),
|
||||
(null, "Unsupported URL Scheme (mailto)"));
|
||||
});
|
||||
test('Testing getValidRequestUri when query params in both url and kvrow', () {
|
||||
test('Testing getValidRequestUri when query params in both url and kvrow',
|
||||
() {
|
||||
String url6 = "api.foss42.com/country/data?code=IND";
|
||||
KVRow kvRow6 = const KVRow("code", "US");
|
||||
Uri uri6Expected = Uri(
|
||||
scheme: 'https',
|
||||
host: 'api.foss42.com',
|
||||
path: 'country/data',
|
||||
queryParameters: {'code':'US'});
|
||||
queryParameters: {'code': 'US'});
|
||||
expect(getValidRequestUri(url6, [kvRow6]), (uri6Expected, null));
|
||||
});
|
||||
test('Testing getValidRequestUri when kvrow is null', () {
|
||||
@ -232,7 +232,7 @@ void main() {
|
||||
scheme: 'https',
|
||||
host: 'api.foss42.com',
|
||||
path: 'country/data',
|
||||
queryParameters: {'code':'US'});
|
||||
queryParameters: {'code': 'US'});
|
||||
expect(getValidRequestUri(url7, null), (uri7Expected, null));
|
||||
});
|
||||
});
|
||||
@ -241,72 +241,78 @@ void main() {
|
||||
test('Testing getResponseBodyViewOptions for application/json', () {
|
||||
MediaType mediaType1 = MediaType("application", "json");
|
||||
var result1 = getResponseBodyViewOptions(mediaType1);
|
||||
expect(result1.$0,kCodeRawBodyViewOptions);
|
||||
expect(result1.$1, "json");
|
||||
expect(result1.$1, kCodeRawBodyViewOptions);
|
||||
expect(result1.$2, "json");
|
||||
});
|
||||
test('Testing getResponseBodyViewOptions for application/xml', () {
|
||||
MediaType mediaType2 = MediaType("application", "xml");
|
||||
var result2 = getResponseBodyViewOptions(mediaType2);
|
||||
expect(result2.$0, kCodeRawBodyViewOptions);
|
||||
expect(result2.$1,"xml");
|
||||
expect(result2.$1, kCodeRawBodyViewOptions);
|
||||
expect(result2.$2, "xml");
|
||||
});
|
||||
test('Testing getResponseBodyViewOptions for message/news a format currently not supported', () {
|
||||
test(
|
||||
'Testing getResponseBodyViewOptions for message/news a format currently not supported',
|
||||
() {
|
||||
MediaType mediaType3 = MediaType("message", "news");
|
||||
var result3 = getResponseBodyViewOptions(mediaType3);
|
||||
expect(result3.$0,kNoBodyViewOptions);
|
||||
expect(result3.$1,null);
|
||||
expect(result3.$1, kNoBodyViewOptions);
|
||||
expect(result3.$2, null);
|
||||
});
|
||||
test('Testing getResponseBodyViewOptions for application/calendar+json', () {
|
||||
test('Testing getResponseBodyViewOptions for application/calendar+json',
|
||||
() {
|
||||
MediaType mediaType4 = MediaType("application", "calendar+json");
|
||||
var result4 = getResponseBodyViewOptions(mediaType4);
|
||||
expect(result4.$0,kCodeRawBodyViewOptions);
|
||||
expect(result4.$1, "json");
|
||||
expect(result4.$1, kCodeRawBodyViewOptions);
|
||||
expect(result4.$2, "json");
|
||||
});
|
||||
test('Testing getResponseBodyViewOptions for image/svg+xml', () {
|
||||
MediaType mediaType5 = MediaType("image", "svg+xml");
|
||||
var result5 = getResponseBodyViewOptions(mediaType5);
|
||||
expect(result5.$0,kCodeRawBodyViewOptions);
|
||||
expect(result5.$1, "xml");
|
||||
expect(result5.$1, kCodeRawBodyViewOptions);
|
||||
expect(result5.$2, "xml");
|
||||
});
|
||||
test('Testing getResponseBodyViewOptions for application/xhtml+xml', () {
|
||||
MediaType mediaType6 = MediaType("application", "xhtml+xml");
|
||||
var result6 = getResponseBodyViewOptions(mediaType6);
|
||||
expect(result6.$0,kCodeRawBodyViewOptions);
|
||||
expect(result6.$1, "xml");
|
||||
expect(result6.$1, kCodeRawBodyViewOptions);
|
||||
expect(result6.$2, "xml");
|
||||
});
|
||||
test('Testing getResponseBodyViewOptions for application/xml-external-parsed-entity', () {
|
||||
MediaType mediaType7 = MediaType("application", "xml-external-parsed-entity");
|
||||
test(
|
||||
'Testing getResponseBodyViewOptions for application/xml-external-parsed-entity',
|
||||
() {
|
||||
MediaType mediaType7 =
|
||||
MediaType("application", "xml-external-parsed-entity");
|
||||
var result7 = getResponseBodyViewOptions(mediaType7);
|
||||
expect(result7.$0,kCodeRawBodyViewOptions);
|
||||
expect(result7.$1, "xml");
|
||||
expect(result7.$1, kCodeRawBodyViewOptions);
|
||||
expect(result7.$2, "xml");
|
||||
});
|
||||
test('Testing getResponseBodyViewOptions for text/html', () {
|
||||
MediaType mediaType8 = MediaType("text", "html");
|
||||
var result8 = getResponseBodyViewOptions(mediaType8);
|
||||
expect(result8.$0,kCodeRawBodyViewOptions);
|
||||
expect(result8.$1, "xml");
|
||||
expect(result8.$1, kCodeRawBodyViewOptions);
|
||||
expect(result8.$2, "xml");
|
||||
});
|
||||
test('Testing getResponseBodyViewOptions for application/pdf', () {
|
||||
MediaType mediaType9 = MediaType("application", "pdf");
|
||||
var result9 = getResponseBodyViewOptions(mediaType9);
|
||||
expect(result9.$0,kNoBodyViewOptions);
|
||||
expect(result9.$1, "pdf");
|
||||
expect(result9.$1, kNoBodyViewOptions);
|
||||
expect(result9.$2, "pdf");
|
||||
});
|
||||
test('Testing getResponseBodyViewOptions for text/calendar', () {
|
||||
test('Testing getResponseBodyViewOptions for text/calendar', () {
|
||||
MediaType mediaType10 = MediaType("text", "calendar");
|
||||
var result10 = getResponseBodyViewOptions(mediaType10);
|
||||
expect(result10.$0,kRawBodyViewOptions);
|
||||
expect(result10.$1, "calendar");
|
||||
expect(result10.$1, kRawBodyViewOptions);
|
||||
expect(result10.$2, "calendar");
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing formatBody", () {
|
||||
test('Testing formatBody for null values', () {
|
||||
expect(formatBody(null, null),null);
|
||||
expect(formatBody(null, null), null);
|
||||
});
|
||||
test('Testing formatBody for null body values', () {
|
||||
MediaType mediaType1 = MediaType("application", "xml");
|
||||
expect(formatBody(null, mediaType1),null);
|
||||
expect(formatBody(null, mediaType1), null);
|
||||
});
|
||||
test('Testing formatBody for null MediaType values', () {
|
||||
String body1 = '''
|
||||
@ -314,7 +320,7 @@ void main() {
|
||||
"text":"The Chosen One";
|
||||
}
|
||||
''';
|
||||
expect(formatBody(body1, null),null);
|
||||
expect(formatBody(body1, null), null);
|
||||
});
|
||||
test('Testing formatBody for json subtype values', () {
|
||||
String body2 = '''{"data":{"area":9831510.0,"population":331893745}}''';
|
||||
@ -325,7 +331,7 @@ void main() {
|
||||
"population": 331893745
|
||||
}
|
||||
}''';
|
||||
expect(formatBody(body2, mediaType2),result2Expected);
|
||||
expect(formatBody(body2, mediaType2), result2Expected);
|
||||
});
|
||||
test('Testing formatBody for xml subtype values', () {
|
||||
String body3 = '''
|
||||
@ -347,28 +353,30 @@ void main() {
|
||||
<calories>650</calories>
|
||||
</food>
|
||||
</breakfast_menu>''';
|
||||
expect(formatBody(body3, mediaType3),result3Expected);
|
||||
expect(formatBody(body3, mediaType3), result3Expected);
|
||||
});
|
||||
group("Testing formatBody for html", () {
|
||||
MediaType mediaTypeHtml = MediaType("text", "html");
|
||||
test('Testing formatBody for html subtype values', () {
|
||||
String body4 = '''<html>
|
||||
String body4 = '''<html>
|
||||
<body>
|
||||
<h1>My First Heading</h1>
|
||||
<p>My first paragraph.</p>
|
||||
</body>
|
||||
</html>''';
|
||||
expect(formatBody(body4, mediaTypeHtml),body4);
|
||||
</html>''';
|
||||
expect(formatBody(body4, mediaTypeHtml), body4);
|
||||
});
|
||||
|
||||
test('Testing formatBody for html subtype values with random values', () {
|
||||
String body5 = '''<html>${getRandomStringLines(100, 10000)}</html>''';
|
||||
expect(formatBody(body5, mediaTypeHtml), null);
|
||||
});
|
||||
test(
|
||||
'Testing formatBody for html subtype values with random values within limit',
|
||||
() {
|
||||
String body6 = '''<html>${getRandomStringLines(100, 190)}</html>''';
|
||||
expect(formatBody(body6, mediaTypeHtml), body6);
|
||||
});
|
||||
});
|
||||
|
||||
test('Testing formatBody for html subtype values with random values', () {
|
||||
String body5 = '''<html>${getRandomStringLines(100, 10000)}</html>''';
|
||||
expect(formatBody(body5, mediaTypeHtml),null);
|
||||
});
|
||||
test('Testing formatBody for html subtype values with random values within limit', () {
|
||||
String body6 = '''<html>${getRandomStringLines(100, 190)}</html>''';
|
||||
expect(formatBody(body6, mediaTypeHtml),body6);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ import 'package:multi_split_view/multi_split_view.dart';
|
||||
void main() {
|
||||
testWidgets('Testing for Dashboard Splitview', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
const MaterialApp(
|
||||
title: 'Dashboard Splitview',
|
||||
home: Scaffold(
|
||||
body: DashboardSplitView(
|
||||
sidebarWidget: Column(children: const [Text("Hello")]),
|
||||
mainWidget: Column(children: const [Text("World")]),
|
||||
sidebarWidget: Column(children: [Text("Hello")]),
|
||||
mainWidget: Column(children: [Text("World")]),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -23,12 +23,12 @@ void main() {
|
||||
});
|
||||
testWidgets('Testing for Equal SplitView', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
const MaterialApp(
|
||||
title: 'Equal SplitView',
|
||||
home: Scaffold(
|
||||
body: EqualSplitView(
|
||||
leftWidget: Column(children: const [Text("Hello equal")]),
|
||||
rightWidget: Column(children: const [Text("World equal")]),
|
||||
leftWidget: Column(children: [Text("Hello equal")]),
|
||||
rightWidget: Column(children: [Text("World equal")]),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -10,8 +10,8 @@ void main() {
|
||||
MaterialApp(
|
||||
title: 'URL Field',
|
||||
theme: kThemeDataDark,
|
||||
home: Scaffold(
|
||||
body: Column(children: const [URLField(activeId: '2')]),
|
||||
home: const Scaffold(
|
||||
body: Column(children: [URLField(activeId: '2')]),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -30,9 +30,9 @@ void main() {
|
||||
MaterialApp(
|
||||
title: 'CellField',
|
||||
theme: kThemeDataLight,
|
||||
home: Scaffold(
|
||||
home: const Scaffold(
|
||||
body: Column(
|
||||
children: const [
|
||||
children: [
|
||||
CellField(
|
||||
keyId: "4",
|
||||
hintText: "Passing some hint text",
|
||||
|
Reference in New Issue
Block a user