-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
226 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Flutter test | ||
|
||
on: | ||
pull_request: | ||
paths-ignore: | ||
- "**.md" | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
paths-ignore: | ||
- "**.md" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
concurrency: | ||
group: ${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: subosito/flutter-action@v2.18.0 | ||
with: | ||
channel: "stable" | ||
|
||
- name: Install dependencies | ||
run: flutter pub get | ||
|
||
- name: Test | ||
run: flutter test |
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.
Binary file not shown.
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,8 @@ | ||
import 'package:flutter/widgets.dart'; | ||
|
||
mixin DiagnosticableToStringMixin on Object { | ||
@override | ||
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { | ||
return super.toString(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,174 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:shadcn_ui/shadcn_ui.dart'; | ||
|
||
import '../../extra/diagnosticable_mixin.dart'; | ||
|
||
// Create a Mock class for SvgPicture using mocktail | ||
class MockSvgPicture extends Mock | ||
with DiagnosticableToStringMixin | ||
implements SvgPicture {} | ||
|
||
Future<void> main() async { | ||
setUpAll(() async {}); | ||
|
||
testWidgets('renders jpg image correctly', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: Scaffold( | ||
body: ShadImage('test/assets/image.jpg'), | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(Image), findsOneWidget); | ||
expect(find.byType(SvgPicture), findsNothing); | ||
}); | ||
|
||
testWidgets('renders svg image correctly', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: Scaffold( | ||
body: ShadImage('test/assets/image.svg'), | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(SvgPicture), findsOneWidget); | ||
expect(find.byType(Image), findsNothing); | ||
}); | ||
|
||
testWidgets('renders svg.vec image correctly', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: Scaffold( | ||
body: ShadImage('test/assets/image.svg.vec'), | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(SvgPicture), findsOneWidget); | ||
expect(find.byType(Image), findsNothing); | ||
}); | ||
|
||
testWidgets('renders icon correctly', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: Scaffold( | ||
body: ShadImage(Icons.star, width: 50, height: 50), | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(Icon), findsOneWidget); | ||
}); | ||
|
||
testWidgets('applies gradient correctly', (WidgetTester tester) async { | ||
const gradient = LinearGradient(colors: [Colors.red, Colors.blue]); | ||
|
||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: Scaffold( | ||
body: ShadImage(LucideIcons.mail, gradient: gradient), | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(ShaderMask), findsOneWidget); | ||
}); | ||
testWidgets('renders ShadImage with specified width and height', | ||
(WidgetTester tester) async { | ||
const testWidth = 150.0; | ||
const testHeight = 200.0; | ||
|
||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: Scaffold( | ||
body: ShadImage( | ||
'test/assets/image.jpg', | ||
width: testWidth, | ||
height: testHeight, | ||
), | ||
), | ||
), | ||
); | ||
|
||
// Verify that the rendered Image widget has the correct dimensions. | ||
final imageWidget = tester.widget<Image>(find.byType(Image)); | ||
expect(imageWidget.width, testWidth); | ||
expect(imageWidget.height, testHeight); | ||
}); | ||
|
||
testWidgets('renders ShadImage with specified color', | ||
(WidgetTester tester) async { | ||
const testColor = Colors.red; | ||
|
||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: Scaffold( | ||
body: ShadImage( | ||
'test/assets/image.jpg', | ||
color: testColor, | ||
), | ||
), | ||
), | ||
); | ||
|
||
final imageWidget = tester.widget<Image>(find.byType(Image)); | ||
final color = imageWidget.color; | ||
|
||
expect(color, equals(testColor)); | ||
}); | ||
|
||
testWidgets('renders ShadImage with inherited color', | ||
(WidgetTester tester) async { | ||
const testColor = Colors.red; | ||
|
||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: Scaffold( | ||
body: ShadProvider( | ||
data: ShadImageData(color: testColor), | ||
child: ShadImage( | ||
'test/assets/image.jpg', | ||
), | ||
), | ||
), | ||
), | ||
); | ||
|
||
final imageWidget = tester.widget<Image>(find.byType(Image)); | ||
final color = imageWidget.color; | ||
|
||
expect(color, equals(testColor)); | ||
}); | ||
|
||
testWidgets('renders ShadImage with correct colorFilter for SvgPicture', | ||
(WidgetTester tester) async { | ||
const testColor = Colors.green; | ||
|
||
await tester.pumpWidget( | ||
const MaterialApp( | ||
home: Scaffold( | ||
body: ShadImage( | ||
'test/assets/image.svg', | ||
color: testColor, | ||
), | ||
), | ||
), | ||
); | ||
|
||
// Verify that an SvgPicture widget is rendered. | ||
final svgPicture = tester.widget<SvgPicture>(find.byType(SvgPicture)); | ||
|
||
// Expect the SvgPicture to have a ColorFilter applied. | ||
expect(svgPicture.colorFilter, isA<ColorFilter>()); | ||
|
||
// Verify that the ColorFilter is correctly set up with the provided color. | ||
expect( | ||
svgPicture.colorFilter, | ||
equals(const ColorFilter.mode(testColor, BlendMode.srcIn)), | ||
); | ||
}); | ||
} |