71 lines
2.3 KiB
Dart
71 lines
2.3 KiB
Dart
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';
|
|
final child = Text(childText);
|
|
final card = ElevatedCard (title: title, child: child);
|
|
|
|
// Act
|
|
await tester.pumpWidget(MaterialApp(home: Scaffold(body: card)));
|
|
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
|
|
expect(titleWidget.style?.fontSize, equals(20.0));
|
|
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
|
|
expect(cardWidget.shape,
|
|
const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0))));
|
|
});
|
|
});
|
|
}
|