feat: Added tests and minor fixes
This commit is contained in:
@@ -47,7 +47,7 @@ class _GradientAvatarState extends State<GradientAvatar> {
|
||||
var result = '';
|
||||
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
result = result + parts[i][0];
|
||||
result = result + parts[i][0].toUpperCase();
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -112,8 +112,8 @@ class DemoPainter extends CustomPainter {
|
||||
|
||||
final textSize = smallerSide / 3;
|
||||
|
||||
final dxShift = (username.length == 2 ? 1.45 : 0.75) * textSize / 2;
|
||||
final dyShift = (username.length == 2 ? 1.0 : 1.8) * textSize / 2;
|
||||
final dxShift = (username.length == 2 ? 1.45 : 0.9) * textSize / 2;
|
||||
final dyShift = (username.length == 2 ? 1.0 : 1.65) * textSize / 2;
|
||||
|
||||
final fontSize = username.length == 2 ? textSize : textSize * 1.5;
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:golden_toolkit/golden_toolkit.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:stream_chat_flutter/src/gradient_avatar.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
import 'mocks.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'control test',
|
||||
(WidgetTester tester) async {
|
||||
final client = MockClient();
|
||||
final clientState = MockClientState();
|
||||
|
||||
when(() => client.state).thenReturn(clientState);
|
||||
when(() => clientState.user).thenReturn(OwnUser(id: 'user-id'));
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StreamChat(
|
||||
client: client,
|
||||
child: const Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: GradientAvatar(name: 'demo user', userId: 'demo123'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(GradientAvatar), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testGoldens(
|
||||
'golden test for the name "demo user"',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: GradientAvatar(name: 'demo user', userId: 'demo123'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await screenMatchesGolden(tester, 'gradient_avatar_0');
|
||||
},
|
||||
);
|
||||
|
||||
testGoldens(
|
||||
'golden test for the name "demo"',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: GradientAvatar(name: 'demo', userId: 'demo1'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await screenMatchesGolden(tester, 'gradient_avatar_1');
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user