cpd_2022_zi/test/widget_tests/widget_elevated_card_test.dart

72 lines
2.3 KiB
Dart
Raw Normal View History

2023-03-06 12:09:01 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:smoke_cess_app/widgets/elevated_card.dart';
void main() {
group('ElevatedCard', () {
testWidgets('Renders the title and child', (WidgetTester tester) async {
// Arrange
const title = 'My Card Title';
const childText = 'My Card Content';
2023-03-06 18:36:10 +01:00
const child = Text(childText);
const card = ElevatedCard(title: title, child: child);
2023-03-06 12:09:01 +01:00
// Act
2023-03-06 18:36:10 +01:00
await tester.pumpWidget(const MaterialApp(home: Scaffold(body: card)));
2023-03-06 12:09:01 +01:00
final titleFinder = find.text(title);
final childFinder = find.text(childText);
// Assert
expect(titleFinder, findsOneWidget);
expect(childFinder, findsOneWidget);
});
testWidgets('Uses default title style', (WidgetTester tester) async {
// Arrange
final card = ElevatedCard(title: 'My Title', child: Container());
// Act
await tester.pumpWidget(MaterialApp(home: Scaffold(body: card)));
final titleFinder = find.text('My Title');
final titleWidget = tester.widget<Text>(titleFinder);
// Assert
expect(titleWidget.style?.fontSize, equals(16.0));
expect(titleWidget.style?.fontWeight, equals(FontWeight.bold));
});
testWidgets('Uses custom title style', (WidgetTester tester) async {
// Arrange
final card = ElevatedCard(
title: 'My Title',
child: Container(),
);
// Act
await tester.pumpWidget(MaterialApp(home: Scaffold(body: card)));
final titleFinder = find.text('My Title');
final titleWidget = tester.widget<Text>(titleFinder);
// Assert
2023-03-06 19:12:31 +01:00
expect(titleWidget.style?.fontSize, equals(16.0));
2023-03-06 12:09:01 +01:00
expect(titleWidget.style?.fontWeight, equals(FontWeight.bold));
});
testWidgets('Has rounded corners', (WidgetTester tester) async {
// Arrange
final card = ElevatedCard(title: 'My Title', child: Container());
// Act
await tester.pumpWidget(MaterialApp(home: Scaffold(body: card)));
final cardFinder = find.byType(Card);
final cardWidget = tester.widget<Card>(cardFinder);
// Assert
2023-03-06 18:36:10 +01:00
expect(
cardWidget.shape,
const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(16.0))));
2023-03-06 12:09:01 +01:00
});
});
}