Skip to content
Open
Show file tree
Hide file tree
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 Feb 11, 2026
9a215b5
Refactor painter tests: add helper function and paint() coverage
shoaib-inamdar Feb 11, 2026
95b5010
Fix linter warnings: use Size.zero instead of Size(0, 0)
shoaib-inamdar Feb 11, 2026
71ef8ab
Extracted buildPainterTestWidget into a shared test helper file.
shoaib-inamdar Feb 11, 2026
0cbb227
Merge branch 'develop' into fix/3109-custom-painter-tests
shoaib-inamdar Feb 11, 2026
66c3cc0
Refactor: Extract paint() smoke tests to runPaintSmokeTests helper
shoaib-inamdar Feb 12, 2026
d80832c
extracting the repeated paint()
shoaib-inamdar Feb 12, 2026
c1775aa
Fix: Use **params**: format for custom linter compliance
shoaib-inamdar Feb 12, 2026
8f105b0
Fix: Use plain prose in doc comments (remove Markdown formatting)
shoaib-inamdar Feb 12, 2026
932f9e2
Fix: Use @param tags in doc comments for linter compliance
shoaib-inamdar Feb 12, 2026
c59e385
Fix: Use @params block (plural) for linter compliance
shoaib-inamdar Feb 12, 2026
fe56b58
Fix: Use @param block
shoaib-inamdar Feb 12, 2026
d91487e
Fix: Use individual @param tags for each parameter
shoaib-inamdar Feb 12, 2026
f2c9fe4
Fix: Use **params**: format with asterisk bullets for linter compliance
shoaib-inamdar Feb 12, 2026
bc5ecf1
Fix: Add proper indentation (2 spaces) before asterisks in params block
shoaib-inamdar Feb 12, 2026
292efc3
Add **returns**: sections to documentation for linter compliance
shoaib-inamdar Feb 12, 2026
4cb01e5
Fix: Remove indentation before asterisks in **params**: section for l…
shoaib-inamdar Feb 12, 2026
edb0316
Optimize: Change shouldRepaint to return false for stateless painters
shoaib-inamdar Feb 12, 2026
de496a7
\Add: Golden files and tolerance comparator for painter tests
shoaib-inamdar Feb 12, 2026
af4c7f9
fix: coderabbit suggestions
shoaib-inamdar Feb 12, 2026
7b76e00
\Add: Generate all missing golden files and tolerance comparator
shoaib-inamdar Feb 12, 2026
c29c133
\Refactor: Restrict tolerance comparator to painter tests only
shoaib-inamdar Feb 12, 2026
3c109dc
fix: dart format
shoaib-inamdar Feb 12, 2026
4e66e2d
\Remove: Delete out-of-scope golden files
shoaib-inamdar Feb 13, 2026
18d79c0
fix : removed unecessary files
shoaib-inamdar Feb 13, 2026
8d44035
Remove: Delete test artifact file
shoaib-inamdar Feb 13, 2026
0df7e63
Revert: Remove out-of-scope formatting change
shoaib-inamdar Feb 13, 2026
16f87b0
Fix: Move golden files to standard directory
shoaib-inamdar Feb 14, 2026
9e21e03
Fix: Add path dependency and fix import order
shoaib-inamdar Feb 14, 2026
b245f99
Merge remote-tracking branch 'upstream/develop' into fix/3109-custom-…
shoaib-inamdar Feb 14, 2026
2d2b9f5
fix: replaced path.jion usage with dart:io string interpolation
shoaib-inamdar Feb 14, 2026
04d6f2d
fix: simplify golden test helper by removing custom comparator and us…
shoaib-inamdar Feb 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/custom_painters/talawa_logo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,6 @@ class AppLogo extends CustomPainter {

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
return false;
}
}
2 changes: 1 addition & 1 deletion lib/custom_painters/telegram_logo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ class TelegramLogo extends CustomPainter {

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
return false;
}
}
2 changes: 1 addition & 1 deletion lib/custom_painters/whatsapp_logo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,6 @@ class WhatsappLogo extends CustomPainter {

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
return false;
}
}
Binary file added test/goldens/goldens/language_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/goldens/goldens/talawa_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/goldens/goldens/telegram_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/goldens/goldens/whatsapp_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions test/widget_tests/painters/language_icon_test.dart
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());
});
}
Comment on lines 1 to 36
Copy link

Copilot AI Feb 11, 2026

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:

  • More thorough shouldRepaint tests with a fake CustomPainter
  • Tests that the paint method executes without throwing
  • Widget rendering tests with size verification

The new test file adds less value and creates duplicate coverage in a different directory. Consider either:

  1. Removing this file and using the existing test at test/custom_painters/language_icon_test.dart
  2. Moving all painter tests to a single consistent location (either test/custom_painters/ or test/widget_tests/painters/)
  3. Adding the missing tests (AppLogo, TelegramLogo, WhatsappLogo) to the test/custom_painters/ directory instead
Suggested change
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:talawa/custom_painters/language_icon.dart';
void main() {
group('LanguageIcon Painter Tests', () {
testWidgets('should render LanguageIcon correctly (golden test)',
(WidgetTester tester) async {
// Build a CustomPaint widget with LanguageIcon painter
const key = ValueKey('language_icon_painter');
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: SizedBox(
width: 200,
height: 200,
child: CustomPaint(
key: key,
painter: LanguageIcon(),
),
),
),
),
),
);
// Wait for the widget to settle
await tester.pumpAndSettle();
// Compare with golden file
await expectLater(
find.byKey(key),
matchesGoldenFile('goldens/language_icon.png'),
);
});
test('LanguageIcon shouldRepaint returns false', () {
// Create two instances of LanguageIcon
final painter1 = LanguageIcon();
final painter2 = LanguageIcon();
// LanguageIcon should return false (never repaints)
expect(painter1.shouldRepaint(painter2), isFalse);
});
test('LanguageIcon shouldRepaint with same instance returns false', () {
// Create one instance
final painter = LanguageIcon();
// Even with the same instance, should return false
expect(painter.shouldRepaint(painter), isFalse);
});
});
}
// This file previously contained duplicate tests for LanguageIcon.
// The comprehensive tests now reside in test/custom_painters/language_icon_test.dart.

Copilot uses AI. Check for mistakes.
75 changes: 75 additions & 0 deletions test/widget_tests/painters/painter_test_helpers.dart
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();
});
}
});
}
36 changes: 36 additions & 0 deletions test/widget_tests/painters/talawa_logo_test.dart
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());
});
}
36 changes: 36 additions & 0 deletions test/widget_tests/painters/telegram_logo_test.dart
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());
});
}
36 changes: 36 additions & 0 deletions test/widget_tests/painters/whatsapp_logo_test.dart
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());
});
}
Loading