mirror of
https://github.com/foss42/apidash.git
synced 2025-05-30 13:27:09 +08:00
test: history widgets
This commit is contained in:
71
test/widgets/button_form_data_file_test.dart
Normal file
71
test/widgets/button_form_data_file_test.dart
Normal file
@ -0,0 +1,71 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/widgets/button_form_data_file.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing FormDataFileButton for default label',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: FormDataFileButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final icon = find.byIcon(Icons.snippet_folder_rounded);
|
||||
Finder button = find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is ElevatedButton));
|
||||
|
||||
expect(button, findsOneWidget);
|
||||
expect(find.text(kLabelSelectFile), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Testing FormDataFileButton with provided label',
|
||||
(WidgetTester tester) async {
|
||||
const testValue = 'test_file.txt';
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: FormDataFileButton(initialValue: testValue),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final icon = find.byIcon(Icons.snippet_folder_rounded);
|
||||
Finder button = find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is ElevatedButton));
|
||||
|
||||
expect(button, findsOneWidget);
|
||||
expect(find.text(testValue), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Testing FormDataFileButton triggers onPressed callback',
|
||||
(WidgetTester tester) async {
|
||||
bool pressed = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: FormDataFileButton(
|
||||
onPressed: () {
|
||||
pressed = true;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final icon = find.byIcon(Icons.snippet_folder_rounded);
|
||||
Finder button = find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is ElevatedButton));
|
||||
|
||||
await tester.tap(button);
|
||||
await tester.pump();
|
||||
|
||||
expect(pressed, isTrue);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user