-
-
Notifications
You must be signed in to change notification settings - Fork 576
fix : Add tests for custom painters #3306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shoaib-inamdar
wants to merge
32
commits into
PalisadoesFoundation:develop
Choose a base branch
from
shoaib-inamdar:fix/3109-custom-painter-tests
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
c0a9348
Add tests for custom painters (fixes #3109)
shoaib-inamdar 9a215b5
Refactor painter tests: add helper function and paint() coverage
shoaib-inamdar 95b5010
Fix linter warnings: use Size.zero instead of Size(0, 0)
shoaib-inamdar 71ef8ab
Extracted buildPainterTestWidget into a shared test helper file.
shoaib-inamdar 0cbb227
Merge branch 'develop' into fix/3109-custom-painter-tests
shoaib-inamdar 66c3cc0
Refactor: Extract paint() smoke tests to runPaintSmokeTests helper
shoaib-inamdar d80832c
extracting the repeated paint()
shoaib-inamdar c1775aa
Fix: Use **params**: format for custom linter compliance
shoaib-inamdar 8f105b0
Fix: Use plain prose in doc comments (remove Markdown formatting)
shoaib-inamdar 932f9e2
Fix: Use @param tags in doc comments for linter compliance
shoaib-inamdar c59e385
Fix: Use @params block (plural) for linter compliance
shoaib-inamdar fe56b58
Fix: Use @param block
shoaib-inamdar d91487e
Fix: Use individual @param tags for each parameter
shoaib-inamdar f2c9fe4
Fix: Use **params**: format with asterisk bullets for linter compliance
shoaib-inamdar bc5ecf1
Fix: Add proper indentation (2 spaces) before asterisks in params block
shoaib-inamdar 292efc3
Add **returns**: sections to documentation for linter compliance
shoaib-inamdar 4cb01e5
Fix: Remove indentation before asterisks in **params**: section for l…
shoaib-inamdar edb0316
Optimize: Change shouldRepaint to return false for stateless painters
shoaib-inamdar de496a7
\Add: Golden files and tolerance comparator for painter tests
shoaib-inamdar af4c7f9
fix: coderabbit suggestions
shoaib-inamdar 7b76e00
\Add: Generate all missing golden files and tolerance comparator
shoaib-inamdar c29c133
\Refactor: Restrict tolerance comparator to painter tests only
shoaib-inamdar 3c109dc
fix: dart format
shoaib-inamdar 4e66e2d
\Remove: Delete out-of-scope golden files
shoaib-inamdar 18d79c0
fix : removed unecessary files
shoaib-inamdar 8d44035
Remove: Delete test artifact file
shoaib-inamdar 0df7e63
Revert: Remove out-of-scope formatting change
shoaib-inamdar 16f87b0
Fix: Move golden files to standard directory
shoaib-inamdar 9e21e03
Fix: Add path dependency and fix import order
shoaib-inamdar b245f99
Merge remote-tracking branch 'upstream/develop' into fix/3109-custom-…
shoaib-inamdar 2d2b9f5
fix: replaced path.jion usage with dart:io string interpolation
shoaib-inamdar 04d6f2d
fix: simplify golden test helper by removing custom comparator and us…
shoaib-inamdar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:talawa/custom_painters/language_icon.dart'; | ||
|
|
||
| import 'painter_test_helpers.dart'; | ||
|
|
||
| void main() { | ||
| group('LanguageIcon Painter Tests', () { | ||
| testWidgets('should render LanguageIcon correctly (golden test)', | ||
| (WidgetTester tester) async { | ||
| const key = ValueKey('language_icon_painter'); | ||
| await tester.pumpWidget( | ||
| buildPainterTestWidget( | ||
| painter: LanguageIcon(), | ||
| key: key, | ||
| ), | ||
| ); | ||
|
|
||
| await tester.pumpAndSettle(); | ||
|
|
||
| await expectLater( | ||
| find.byKey(key), | ||
| matchesGoldenFile('../../goldens/goldens/language_icon.png'), | ||
| ); | ||
| }); | ||
|
|
||
| test('LanguageIcon shouldRepaint returns false', () { | ||
| final painter1 = LanguageIcon(); | ||
| final painter2 = LanguageIcon(); | ||
|
|
||
| expect(painter1.shouldRepaint(painter2), isFalse); | ||
| }); | ||
|
|
||
| runPaintSmokeTests(() => LanguageIcon()); | ||
| }); | ||
| } | ||
This file contains hidden or 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,75 @@ | ||
| import 'dart:ui' as ui; | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| /// Helper function to build a test widget with a CustomPaint painter. | ||
| /// | ||
| /// Creates a standard MaterialApp scaffold with a CustomPaint widget for | ||
| /// testing custom painters in a consistent way across all tests. | ||
| /// | ||
| /// **params**: | ||
| /// * `painter`: The CustomPainter instance to test. | ||
| /// * `key`: A unique key to identify the CustomPaint widget in tests. | ||
| /// * `width`: The width of the canvas (default: 200). | ||
| /// * `height`: The height of the canvas (default: 200). | ||
| /// | ||
| /// **returns**: | ||
| /// * `Widget`: A MaterialApp containing the CustomPaint widget for testing. | ||
| Widget buildPainterTestWidget({ | ||
| required CustomPainter painter, | ||
| required Key key, | ||
| double width = 200, | ||
| double height = 200, | ||
| }) { | ||
| return MaterialApp( | ||
| home: Scaffold( | ||
| body: Center( | ||
| child: SizedBox( | ||
| width: width, | ||
| height: height, | ||
| child: CustomPaint( | ||
| key: key, | ||
| painter: painter, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| /// Runs smoke tests for the [paint] method of a [CustomPainter]. | ||
| /// | ||
| /// Verifies that the [paint] method completes without throwing exceptions | ||
| /// for various standard and edge-case canvas sizes. | ||
| /// | ||
| /// **params**: | ||
| /// * `createPainter`: A factory function that returns a new instance of the [CustomPainter] to test. | ||
| /// | ||
| /// **returns**: | ||
| /// None | ||
| void runPaintSmokeTests(CustomPainter Function() createPainter) { | ||
| group('paint() method smoke tests', () { | ||
| final sizes = [ | ||
| const MapEntry('normal size', Size(200, 200)), | ||
| const MapEntry('zero size', Size.zero), | ||
| const MapEntry('minimal size', Size(1, 1)), | ||
| const MapEntry('oversized', Size(1000, 1000)), | ||
| const MapEntry('non-square', Size(300, 150)), | ||
| ]; | ||
|
|
||
| for (final entry in sizes) { | ||
| test('paint() completes without throwing on ${entry.key} canvas', () { | ||
| final painter = createPainter(); | ||
| final recorder = ui.PictureRecorder(); | ||
| final canvas = Canvas(recorder); | ||
| final size = entry.value; | ||
|
|
||
| expect(() => painter.paint(canvas, size), returnsNormally); | ||
|
|
||
| // Cleanup to prevent memory leaks | ||
| recorder.endRecording().dispose(); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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,36 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:talawa/custom_painters/talawa_logo.dart'; | ||
|
|
||
| import 'painter_test_helpers.dart'; | ||
|
|
||
| void main() { | ||
| group('AppLogo Painter Tests', () { | ||
| testWidgets('should render AppLogo correctly (golden test)', | ||
| (WidgetTester tester) async { | ||
| const key = ValueKey('app_logo_painter'); | ||
| await tester.pumpWidget( | ||
| buildPainterTestWidget( | ||
| painter: AppLogo(), | ||
| key: key, | ||
| ), | ||
| ); | ||
|
|
||
| await tester.pumpAndSettle(); | ||
|
|
||
| await expectLater( | ||
| find.byKey(key), | ||
| matchesGoldenFile('../../goldens/goldens/talawa_logo.png'), | ||
| ); | ||
| }); | ||
|
|
||
| test('AppLogo shouldRepaint returns false', () { | ||
| final painter1 = AppLogo(); | ||
| final painter2 = AppLogo(); | ||
|
|
||
| expect(painter1.shouldRepaint(painter2), isFalse); | ||
| }); | ||
|
|
||
| runPaintSmokeTests(() => AppLogo()); | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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,36 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:talawa/custom_painters/telegram_logo.dart'; | ||
|
|
||
| import 'painter_test_helpers.dart'; | ||
|
|
||
| void main() { | ||
| group('TelegramLogo Painter Tests', () { | ||
| testWidgets('should render TelegramLogo correctly (golden test)', | ||
| (WidgetTester tester) async { | ||
| const key = ValueKey('telegram_logo_painter'); | ||
| await tester.pumpWidget( | ||
| buildPainterTestWidget( | ||
| painter: TelegramLogo(), | ||
| key: key, | ||
| ), | ||
| ); | ||
|
|
||
| await tester.pumpAndSettle(); | ||
|
|
||
| await expectLater( | ||
| find.byKey(key), | ||
| matchesGoldenFile('../../goldens/goldens/telegram_logo.png'), | ||
| ); | ||
| }); | ||
|
|
||
| test('TelegramLogo shouldRepaint returns false', () { | ||
| final painter1 = TelegramLogo(); | ||
| final painter2 = TelegramLogo(); | ||
|
|
||
| expect(painter1.shouldRepaint(painter2), isFalse); | ||
| }); | ||
|
|
||
| runPaintSmokeTests(() => TelegramLogo()); | ||
| }); | ||
| } |
This file contains hidden or 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,36 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:talawa/custom_painters/whatsapp_logo.dart'; | ||
|
|
||
| import 'painter_test_helpers.dart'; | ||
|
|
||
| void main() { | ||
| group('WhatsappLogo Painter Tests', () { | ||
| testWidgets('should render WhatsappLogo correctly (golden test)', | ||
| (WidgetTester tester) async { | ||
| const key = ValueKey('whatsapp_logo_painter'); | ||
| await tester.pumpWidget( | ||
| buildPainterTestWidget( | ||
| painter: WhatsappLogo(), | ||
| key: key, | ||
| ), | ||
| ); | ||
|
|
||
| await tester.pumpAndSettle(); | ||
|
|
||
| await expectLater( | ||
| find.byKey(key), | ||
| matchesGoldenFile('../../goldens/goldens/whatsapp_logo.png'), | ||
| ); | ||
| }); | ||
|
|
||
| test('WhatsappLogo shouldRepaint returns false', () { | ||
| final painter1 = WhatsappLogo(); | ||
| final painter2 = WhatsappLogo(); | ||
|
|
||
| expect(painter1.shouldRepaint(painter2), isFalse); | ||
| }); | ||
|
|
||
| runPaintSmokeTests(() => WhatsappLogo()); | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test file duplicates existing test coverage for LanguageIcon. A more comprehensive test file already exists at test/custom_painters/language_icon_test.dart which includes:
The new test file adds less value and creates duplicate coverage in a different directory. Consider either: