Files
apidash/test/widgets/button_copy_test.dart
2024-07-30 21:16:34 +05:30

54 lines
1.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:apidash/widgets/button_copy.dart';
void main() {
String copyText = 'This is a sample response generated by ';
testWidgets('Testing for copy button with label', (tester) async {
await tester.pumpWidget(
MaterialApp(
title: 'Copy Button',
home: Scaffold(
body: CopyButton(toCopy: copyText, showLabel: true),
),
),
);
final icon = find.byIcon(Icons.content_copy);
expect(icon, findsOneWidget);
final button = find.ancestor(
of: icon,
matching: find.byWidgetPredicate((widget) => widget is TextButton));
expect(button, findsOneWidget);
await tester.tap(button);
await tester.pumpAndSettle();
//TODO: The below test works for `flutter run` but not for `flutter test`
// var data = await Clipboard.getData('text/plain');
// expect(data?.text, copyText);
});
testWidgets('Testing for copy button without label', (tester) async {
await tester.pumpWidget(
MaterialApp(
title: 'Copy Button',
home: Scaffold(
body: CopyButton(toCopy: copyText, showLabel: false),
),
),
);
final icon = find.byIcon(Icons.content_copy);
expect(icon, findsOneWidget);
final button = find.byType(IconButton);
expect(button, findsOneWidget);
await tester.tap(button);
await tester.pump();
});
}