Files
apidash/test/widgets/buttons_test.dart
2023-04-22 05:41:28 +05:30

103 lines
2.9 KiB
Dart

import 'package:apidash/consts.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:apidash/widgets/buttons.dart';
import '../test_consts.dart';
void main() {
String copyText = 'This is a sample response generated by ';
testWidgets('Testing for copy button', (tester) async {
await tester.pumpWidget(
MaterialApp(
title: 'Copy Button',
home: Scaffold(
body: CopyButton(toCopy: copyText),
),
),
);
expect(find.byIcon(Icons.content_copy), findsOneWidget);
expect(find.text(kLabelCopy), findsOneWidget);
final textButton1 = find.byType(TextButton);
expect(textButton1, findsOneWidget);
await tester.tap(textButton1);
//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 Send Request button', (tester) async {
dynamic changedValue;
await tester.pumpWidget(
MaterialApp(
title: 'Send Request button',
theme: kThemeDataLight,
home: Scaffold(
body: SendRequestButton(
activeId: '1',
sentRequestId: null,
onTap: () {
changedValue = 'Send';
},
),
),
),
);
expect(find.byIcon(Icons.send), findsOneWidget);
expect(find.text(kLabelSend), findsOneWidget);
final button1 = find.byType(FilledButton);
expect(button1, findsOneWidget);
await tester.tap(button1);
expect(changedValue, 'Send');
});
testWidgets('Testing for Send Request button when sentRequestId is not null',
(tester) async {
await tester.pumpWidget(
MaterialApp(
title: 'Send Request button',
theme: kThemeDataLight,
home: Scaffold(
body: SendRequestButton(
activeId: '1',
sentRequestId: '2',
onTap: () {},
),
),
),
);
expect(find.byIcon(Icons.send), findsNothing);
expect(find.text(kLabelBusy), findsOneWidget);
final button1 = find.byType(FilledButton);
expect(button1, findsOneWidget);
expect(tester.widget<FilledButton>(button1).enabled, isFalse);
});
testWidgets('Testing for Send Request button when sentRequestId = activeId',
(tester) async {
await tester.pumpWidget(
MaterialApp(
title: 'Send Request button',
theme: kThemeDataLight,
home: Scaffold(
body: SendRequestButton(
activeId: '1',
sentRequestId: '1',
onTap: () {},
),
),
),
);
expect(find.byIcon(Icons.send), findsNothing);
expect(find.text(kLabelSending), findsOneWidget);
final button1 = find.byType(FilledButton);
expect(button1, findsOneWidget);
expect(tester.widget<FilledButton>(button1).enabled, isFalse);
});
}