mirror of
https://github.com/foss42/apidash.git
synced 2025-08-06 13:51:20 +08:00
Update BodySuccess widget and tests
This commit is contained in:
@ -437,57 +437,48 @@ class _BodySuccessState extends State<BodySuccess> {
|
||||
],
|
||||
),
|
||||
kVSpacer10,
|
||||
Visibility(
|
||||
visible: currentSeg == ResponseBodyView.preview ||
|
||||
currentSeg == ResponseBodyView.none,
|
||||
child: Expanded(
|
||||
child: Container(
|
||||
width: double.maxFinite,
|
||||
padding: kP8,
|
||||
decoration: textContainerdecoration,
|
||||
child: Previewer(
|
||||
bytes: widget.bytes,
|
||||
body: widget.body,
|
||||
type: widget.mediaType.type,
|
||||
subtype: widget.mediaType.subtype,
|
||||
hasRaw: widget.options.contains(ResponseBodyView.raw),
|
||||
switch (currentSeg) {
|
||||
ResponseBodyView.preview || ResponseBodyView.none => Expanded(
|
||||
child: Container(
|
||||
width: double.maxFinite,
|
||||
padding: kP8,
|
||||
decoration: textContainerdecoration,
|
||||
child: Previewer(
|
||||
bytes: widget.bytes,
|
||||
body: widget.body,
|
||||
type: widget.mediaType.type,
|
||||
subtype: widget.mediaType.subtype,
|
||||
hasRaw: widget.options.contains(ResponseBodyView.raw),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (widget.formattedBody != null)
|
||||
Visibility(
|
||||
visible: currentSeg == ResponseBodyView.code,
|
||||
child: Expanded(
|
||||
ResponseBodyView.code => Expanded(
|
||||
child: Container(
|
||||
width: double.maxFinite,
|
||||
padding: kP8,
|
||||
decoration: textContainerdecoration,
|
||||
child: CodePreviewer(
|
||||
code: widget.formattedBody!,
|
||||
code: widget.formattedBody ?? widget.body,
|
||||
theme: codeTheme,
|
||||
language: widget.highlightLanguage,
|
||||
textStyle: kCodeStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: currentSeg == ResponseBodyView.raw,
|
||||
child: Expanded(
|
||||
child: Container(
|
||||
width: double.maxFinite,
|
||||
padding: kP8,
|
||||
decoration: textContainerdecoration,
|
||||
child: SingleChildScrollView(
|
||||
child: SelectableText(
|
||||
widget.formattedBody ?? widget.body,
|
||||
style: kCodeStyle,
|
||||
ResponseBodyView.raw => Expanded(
|
||||
child: Container(
|
||||
width: double.maxFinite,
|
||||
padding: kP8,
|
||||
decoration: textContainerdecoration,
|
||||
child: SingleChildScrollView(
|
||||
child: SelectableText(
|
||||
widget.formattedBody ?? widget.body,
|
||||
style: kCodeStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
}
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@ -431,7 +431,9 @@ void main() async {
|
||||
expect(find.byType(Image), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Testing Body Success tap segment', (tester) async {
|
||||
testWidgets(
|
||||
'Testing Body Success tap segment. formattedBody is always shown in Raw',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Body Success',
|
||||
@ -458,7 +460,37 @@ void main() async {
|
||||
|
||||
await tester.tap(find.text('Raw'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Formatted Hello from API Dash'), findsNothing);
|
||||
expect(find.text('Formatted Hello from API Dash'), findsOneWidget);
|
||||
expect(find.text('Raw Hello from API Dash'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Testing Body Success tap segment for formattedBody null',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Body Success',
|
||||
theme: kThemeDataLight,
|
||||
home: Scaffold(
|
||||
body: BodySuccess(
|
||||
body: 'Raw Hello from API Dash',
|
||||
formattedBody: null,
|
||||
mediaType: MediaType("text", "csv"),
|
||||
options: const [
|
||||
ResponseBodyView.code,
|
||||
ResponseBodyView.raw,
|
||||
],
|
||||
bytes: kBodyBytesJpeg,
|
||||
highlightLanguage: 'txt',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Raw Hello from API Dash'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Raw'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Raw Hello from API Dash'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user