Skip to content
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

fix: loading fonts from other packages #111

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion lib/src/golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Future<void> loadFonts() async {
.map((dynamic x) => x as Map<String, dynamic>);

for (final entry in fontManifest) {
final family = (entry['family'] as String).stripFontFamilyPackageName();
final family =
(entry['family'] as String).stripFontFamilyAlchemistPackageName();

final fontAssets = [
for (final fontAssetEntry in entry['fonts'] as List<dynamic>)
Expand Down
44 changes: 22 additions & 22 deletions lib/src/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,34 @@
static const obscuredTextFontFamily = 'Ahem';

/// Strips all text packages from this theme's [ThemeData.textTheme] for use
/// in golden tests using [GoldenTestTextStyleExtensions.stripPackage].
/// in golden tests using [GoldenTestTextStyleExtensions.stripAlchemistPackage].

Check notice on line 83 in lib/src/utilities.dart

View workflow job for this annotation

GitHub Actions / build

The line length exceeds the 80-character limit.

Try breaking the line across multiple lines. See https://dart.dev/lints/lines_longer_than_80_chars to learn more about this problem.
///
/// Only used internally and should not be used by consumers.
@protected
ThemeData stripTextPackages() {
return copyWith(
textTheme: textTheme.copyWith(
displayLarge: textTheme.displayLarge?.stripPackage(),
displayMedium: textTheme.displayMedium?.stripPackage(),
displaySmall: textTheme.displaySmall?.stripPackage(),
headlineMedium: textTheme.headlineMedium?.stripPackage(),
headlineSmall: textTheme.headlineSmall?.stripPackage(),
titleLarge: textTheme.titleLarge?.stripPackage(),
titleMedium: textTheme.titleMedium?.stripPackage(),
titleSmall: textTheme.titleSmall?.stripPackage(),
bodyLarge: textTheme.bodyLarge?.stripPackage(),
bodyMedium: textTheme.bodyMedium?.stripPackage(),
bodySmall: textTheme.bodySmall?.stripPackage(),
labelLarge: textTheme.labelLarge?.stripPackage(),
labelSmall: textTheme.labelSmall?.stripPackage(),
displayLarge: textTheme.displayLarge?.stripAlchemistPackage(),
displayMedium: textTheme.displayMedium?.stripAlchemistPackage(),
displaySmall: textTheme.displaySmall?.stripAlchemistPackage(),
headlineMedium: textTheme.headlineMedium?.stripAlchemistPackage(),
headlineSmall: textTheme.headlineSmall?.stripAlchemistPackage(),
titleLarge: textTheme.titleLarge?.stripAlchemistPackage(),
titleMedium: textTheme.titleMedium?.stripAlchemistPackage(),
titleSmall: textTheme.titleSmall?.stripAlchemistPackage(),
bodyLarge: textTheme.bodyLarge?.stripAlchemistPackage(),
bodyMedium: textTheme.bodyMedium?.stripAlchemistPackage(),
bodySmall: textTheme.bodySmall?.stripAlchemistPackage(),
labelLarge: textTheme.labelLarge?.stripAlchemistPackage(),
labelSmall: textTheme.labelSmall?.stripAlchemistPackage(),
),
floatingActionButtonTheme: floatingActionButtonTheme.copyWith(
extendedTextStyle:
floatingActionButtonTheme.extendedTextStyle?.stripPackage(),
extendedTextStyle: floatingActionButtonTheme.extendedTextStyle
?.stripAlchemistPackage(),
),
dialogTheme: dialogTheme.copyWith(
titleTextStyle: dialogTheme.titleTextStyle?.stripPackage(),
contentTextStyle: dialogTheme.contentTextStyle?.stripPackage(),
titleTextStyle: dialogTheme.titleTextStyle?.stripAlchemistPackage(),
contentTextStyle: dialogTheme.contentTextStyle?.stripAlchemistPackage(),
),
);
}
Expand Down Expand Up @@ -135,7 +135,7 @@
/// Strips the package name from this text style's [TextStyle.fontFamily] for
/// use in golden tests.
@protected
TextStyle stripPackage() {
TextStyle stripAlchemistPackage() {
return TextStyle(
inherit: inherit,
color: color,
Expand All @@ -158,7 +158,7 @@
decorationStyle: decorationStyle,
decorationThickness: decorationThickness,
debugLabel: debugLabel,
fontFamily: fontFamily?.stripFontFamilyPackageName(),
fontFamily: fontFamily?.stripFontFamilyAlchemistPackageName(),
fontFamilyFallback: fontFamilyFallback,
overflow: overflow,
);
Expand All @@ -168,8 +168,8 @@
/// Strips the package name from the given font family for use in golden tests.
extension FontFamilyStringExtensions on String {
/// Strips the package name from this font family for use in golden tests.
String stripFontFamilyPackageName() {
return replaceAll(RegExp(r'packages\/[^\/]*\/'), '');
String stripFontFamilyAlchemistPackageName() {
return replaceAll(RegExp(r'packages\/alchemist\/'), '');
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/src/golden_test_adapter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,10 @@ void main() {
);

testWidgets(
'has its text packages stripped',
'has alchemist text packages stripped',
(tester) async {
const fontFamilyName = 'fontFamilyName';
const providedFontFamily = 'packages/test_package/$fontFamilyName';
const providedFontFamily = 'packages/alchemist/$fontFamilyName';

await tester.pumpWidget(
Theme(
Expand Down
8 changes: 4 additions & 4 deletions test/src/utilities_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ to avoid unnecessary overhead.''',
group('GoldenTestThemeDataExtensions', () {
test('stripTextPackages remove package prefix from all textTheme styles',
() {
const fontFamilyBefore = 'packages/package_name/dir1/dir2';
const fontFamilyBefore = 'packages/alchemist/dir1/dir2';
const fontFamilyAfter = 'dir1/dir2';

final base = ThemeData();
Expand Down Expand Up @@ -142,12 +142,12 @@ to avoid unnecessary overhead.''',
});

group('GoldenTestTextStyleExtensions', () {
test('stripPackage removes package prefix from style', () {
const fontFamilyBefore = 'packages/package_name/dir1/dir2';
test('stripAlchemistPackage removes package prefix from style', () {
const fontFamilyBefore = 'packages/alchemist/dir1/dir2';
const fontFamilyAfter = 'dir1/dir2';

const styleBefore = TextStyle(fontFamily: fontFamilyBefore);
final styleAfter = styleBefore.stripPackage();
final styleAfter = styleBefore.stripAlchemistPackage();

expect(
styleAfter,
Expand Down
Loading