Update BodySuccess widget and tests

This commit is contained in:
Ashita Prasad
2024-01-27 00:38:05 +05:30
parent d8736f1070
commit 7116183a9b
2 changed files with 60 additions and 37 deletions

View File

@ -437,57 +437,48 @@ class _BodySuccessState extends State<BodySuccess> {
], ],
), ),
kVSpacer10, kVSpacer10,
Visibility( switch (currentSeg) {
visible: currentSeg == ResponseBodyView.preview || ResponseBodyView.preview || ResponseBodyView.none => Expanded(
currentSeg == ResponseBodyView.none, child: Container(
child: Expanded( width: double.maxFinite,
child: Container( padding: kP8,
width: double.maxFinite, decoration: textContainerdecoration,
padding: kP8, child: Previewer(
decoration: textContainerdecoration, bytes: widget.bytes,
child: Previewer( body: widget.body,
bytes: widget.bytes, type: widget.mediaType.type,
body: widget.body, subtype: widget.mediaType.subtype,
type: widget.mediaType.type, hasRaw: widget.options.contains(ResponseBodyView.raw),
subtype: widget.mediaType.subtype, ),
hasRaw: widget.options.contains(ResponseBodyView.raw),
), ),
), ),
), ResponseBodyView.code => Expanded(
),
if (widget.formattedBody != null)
Visibility(
visible: currentSeg == ResponseBodyView.code,
child: Expanded(
child: Container( child: Container(
width: double.maxFinite, width: double.maxFinite,
padding: kP8, padding: kP8,
decoration: textContainerdecoration, decoration: textContainerdecoration,
child: CodePreviewer( child: CodePreviewer(
code: widget.formattedBody!, code: widget.formattedBody ?? widget.body,
theme: codeTheme, theme: codeTheme,
language: widget.highlightLanguage, language: widget.highlightLanguage,
textStyle: kCodeStyle, textStyle: kCodeStyle,
), ),
), ),
), ),
), ResponseBodyView.raw => Expanded(
Visibility( child: Container(
visible: currentSeg == ResponseBodyView.raw, width: double.maxFinite,
child: Expanded( padding: kP8,
child: Container( decoration: textContainerdecoration,
width: double.maxFinite, child: SingleChildScrollView(
padding: kP8, child: SelectableText(
decoration: textContainerdecoration, widget.formattedBody ?? widget.body,
child: SingleChildScrollView( style: kCodeStyle,
child: SelectableText( ),
widget.formattedBody ?? widget.body,
style: kCodeStyle,
), ),
), ),
), ),
), }
),
], ],
), ),
); );

View File

@ -431,7 +431,9 @@ void main() async {
expect(find.byType(Image), findsOneWidget); 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( await tester.pumpWidget(
MaterialApp( MaterialApp(
title: 'Body Success', title: 'Body Success',
@ -458,7 +460,37 @@ void main() async {
await tester.tap(find.text('Raw')); await tester.tap(find.text('Raw'));
await tester.pumpAndSettle(); 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); expect(find.text('Raw Hello from API Dash'), findsOneWidget);
}); });
} }