MotorSignal-App/test/club_monogram_test.dart

80 lines
3.0 KiB
Dart
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:motorcycle_dash/core/theme/theme_extensions.dart';
import 'package:motorcycle_dash/features/social/clubs/widgets/club_monogram.dart';
void main() {
group('ClubMonogram Algorithm Tests', () {
test('handles empty or whitespace strings', () {
expect(ClubMonogram.getMonogram(''), equals('C'));
expect(ClubMonogram.getMonogram(' '), equals('C'));
});
test('handles single word club names', () {
expect(ClubMonogram.getMonogram('Ducati'), equals('DU'));
expect(ClubMonogram.getMonogram('moto'), equals('MO'));
expect(ClubMonogram.getMonogram('X'), equals('X'));
expect(ClubMonogram.getMonogram('Yamaha'), equals('YA'));
});
test('handles multi-word club names', () {
expect(ClubMonogram.getMonogram('Blue Ridge'), equals('BR'));
expect(ClubMonogram.getMonogram('Bay Area Riders'), equals('BA'));
expect(ClubMonogram.getMonogram('norcal adventure group'), equals('NA'));
expect(ClubMonogram.getMonogram(' Pacific Coast '), equals('PC'));
});
test('handles numeric and special character names', () {
expect(ClubMonogram.getMonogram('99 Problems'), equals('9P'));
expect(ClubMonogram.getMonogram('1000cc Club'), equals('1C'));
});
test('handles emojis and pictographs safely without splitting grapheme clusters', () {
expect(ClubMonogram.getMonogram('🏍️'), equals('🏍️'));
expect(ClubMonogram.getMonogram('🏍️ NorCal Riders'), equals('🏍️N'));
expect(ClubMonogram.getMonogram('🔥 Motos'), equals('🔥M'));
});
test('handles non-Latin scripts and CJK characters', () {
expect(ClubMonogram.getMonogram('東京 Motos'), equals('東M'));
expect(ClubMonogram.getMonogram('東京'), equals('東京'));
expect(ClubMonogram.getMonogram('Москва Riders'), equals('МR'));
});
test('strips leading punctuation to find meaningful monogram letters', () {
expect(ClubMonogram.getMonogram('---NorCal---'), equals('NO'));
expect(ClubMonogram.getMonogram('---NorCal--- Riders'), equals('NR'));
expect(ClubMonogram.getMonogram('@NorCal #Riders'), equals('NR'));
expect(ClubMonogram.getMonogram('---'), equals('--'));
});
});
group('ClubMonogram Widget Tests', () {
testWidgets('renders monogram and semantics properly', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData.dark().copyWith(
extensions: [MotorSignalThemeColors.dark],
),
home: const Scaffold(
body: Center(
child: ClubMonogram(
name: 'Ridge Runners',
size: 50,
),
),
),
),
);
expect(find.text('RR'), findsOneWidget);
expect(
find.byWidgetPredicate(
(w) => w is Semantics && w.properties.label == 'Club monogram for Ridge Runners',
),
findsOneWidget,
);
});
});
}