-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added testing guide on golden and unit tests
- Loading branch information
Showing
7 changed files
with
330 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:zeta_flutter/zeta_flutter.dart'; | ||
|
||
import '../../../test_utils/test_app.dart'; | ||
|
||
void main() { | ||
group('ZetaTooltip Widget Tests', () { | ||
testWidgets('renders with default properties', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const TestApp( | ||
home: Scaffold( | ||
body: ZetaTooltip( | ||
child: Text('Tooltip text'), | ||
), | ||
), | ||
), | ||
); | ||
|
||
expect(find.text('Tooltip text'), findsOneWidget); | ||
expect(find.byType(ZetaTooltip), findsOneWidget); | ||
}); | ||
|
||
testWidgets('renders with custom color and padding', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const TestApp( | ||
home: Scaffold( | ||
body: ZetaTooltip( | ||
color: Colors.red, | ||
padding: EdgeInsets.all(20), | ||
child: Text('Tooltip text'), | ||
), | ||
), | ||
), | ||
); | ||
|
||
final tooltipBox = tester.widget<DecoratedBox>( | ||
find.descendant( | ||
of: find.byType(ZetaTooltip), | ||
matching: find.byType(DecoratedBox), | ||
), | ||
); | ||
|
||
expect((tooltipBox.decoration as BoxDecoration).color, Colors.red); | ||
|
||
final padding = tester.widget<Padding>( | ||
find.descendant( | ||
of: find.byType(ZetaTooltip), | ||
matching: find.byType(Padding), | ||
), | ||
); | ||
|
||
expect(padding.padding, const EdgeInsets.all(20)); | ||
}); | ||
|
||
testWidgets('renders with custom text style', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const TestApp( | ||
home: Scaffold( | ||
body: ZetaTooltip( | ||
textStyle: TextStyle(fontSize: 24, color: Colors.blue), | ||
child: Text('Tooltip text'), | ||
), | ||
), | ||
), | ||
); | ||
|
||
// Find the RichText widget, which is a descendant of the Text widget | ||
final richTextFinder = find.descendant( | ||
of: find.text('Tooltip text'), | ||
matching: find.byType(RichText), | ||
); | ||
|
||
expect(richTextFinder, findsOneWidget); | ||
|
||
// Verify the styles | ||
final RichText richTextWidget = tester.widget(richTextFinder); | ||
final TextSpan textSpan = richTextWidget.text as TextSpan; | ||
|
||
expect(textSpan.style?.fontSize, 24); | ||
expect(textSpan.style?.color, Colors.blue); | ||
}); | ||
|
||
testWidgets('renders with arrow correctly in up direction', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const TestApp( | ||
home: Scaffold( | ||
body: ZetaTooltip( | ||
arrowDirection: ZetaTooltipArrowDirection.up, | ||
child: Text('Tooltip up'), | ||
), | ||
), | ||
), | ||
); | ||
|
||
expect(find.text('Tooltip up'), findsOneWidget); | ||
|
||
// Verifying the CustomPaint with different arrow directions. | ||
await expectLater( | ||
find.byType(ZetaTooltip), | ||
matchesGoldenFile(p.join('golden', 'arrow_up.png')), | ||
); | ||
}); | ||
|
||
testWidgets('renders with arrow correctly in down direction', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const TestApp( | ||
home: Scaffold( | ||
body: ZetaTooltip( | ||
child: Text('Tooltip down'), | ||
), | ||
), | ||
), | ||
); | ||
|
||
expect(find.text('Tooltip down'), findsOneWidget); | ||
|
||
// Verifying the CustomPaint with different arrow directions. | ||
await expectLater( | ||
find.byType(ZetaTooltip), | ||
matchesGoldenFile(p.join('golden', 'arrow_down.png')), | ||
); | ||
}); | ||
|
||
testWidgets('renders with arrow correctly in left direction', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const TestApp( | ||
home: Scaffold( | ||
body: ZetaTooltip( | ||
arrowDirection: ZetaTooltipArrowDirection.left, | ||
child: Text('Tooltip left'), | ||
), | ||
), | ||
), | ||
); | ||
|
||
expect(find.text('Tooltip left'), findsOneWidget); | ||
|
||
// Verifying the CustomPaint with different arrow directions. | ||
await expectLater( | ||
find.byType(ZetaTooltip), | ||
matchesGoldenFile(p.join('golden', 'arrow_left.png')), | ||
); | ||
}); | ||
|
||
testWidgets('renders with arrow correctly in right direction', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const TestApp( | ||
home: Scaffold( | ||
body: ZetaTooltip( | ||
arrowDirection: ZetaTooltipArrowDirection.right, | ||
child: Text('Tooltip right'), | ||
), | ||
), | ||
), | ||
); | ||
|
||
expect(find.text('Tooltip right'), findsOneWidget); | ||
|
||
// Verifying the CustomPaint with different arrow directions. | ||
await expectLater( | ||
find.byType(ZetaTooltip), | ||
matchesGoldenFile(p.join('golden', 'arrow_right.png')), | ||
); | ||
}); | ||
|
||
testWidgets('renders with rounded and sharp corners', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const TestApp( | ||
home: Scaffold( | ||
body: Column( | ||
children: [ | ||
ZetaTooltip( | ||
child: Text('Rounded tooltip'), | ||
), | ||
ZetaTooltip( | ||
rounded: false, | ||
child: Text('Sharp tooltip'), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
|
||
expect(find.text('Rounded tooltip'), findsOneWidget); | ||
expect(find.text('Sharp tooltip'), findsOneWidget); | ||
|
||
final roundedTooltipBox = tester.widget<DecoratedBox>( | ||
find.descendant( | ||
of: find.widgetWithText(ZetaTooltip, 'Rounded tooltip'), | ||
matching: find.byType(DecoratedBox), | ||
), | ||
); | ||
|
||
final sharpTooltipBox = tester.widget<DecoratedBox>( | ||
find.descendant( | ||
of: find.widgetWithText(ZetaTooltip, 'Sharp tooltip'), | ||
matching: find.byType(DecoratedBox), | ||
), | ||
); | ||
|
||
expect((roundedTooltipBox.decoration as BoxDecoration).borderRadius, ZetaRadius.minimal); | ||
expect((sharpTooltipBox.decoration as BoxDecoration).borderRadius, null); | ||
}); | ||
}); | ||
} |