Skip to content

Commit

Permalink
fix: added goldens tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vanlooverenkoen committed Oct 4, 2024
1 parent a9572b6 commit 7d08c85
Show file tree
Hide file tree
Showing 41 changed files with 385 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"android":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"macos":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"linux":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"windows":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"web":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","dependencies":[]}]},"dependencyGraph":[{"name":"rive_common","dependencies":[]}],"date_created":"2024-10-03 14:43:31.190499","version":"3.24.1","swift_package_manager_enabled":false}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"android":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"macos":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"linux":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"windows":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","native_build":true,"dependencies":[]}],"web":[{"name":"rive_common","path":"/Users/vanlooverenkoen/.pub-cache/hosted/pub.dev/rive_common-0.4.11/","dependencies":[]}]},"dependencyGraph":[{"name":"rive_common","dependencies":[]}],"date_created":"2024-10-04 09:03:25.291994","version":"3.24.1","swift_package_manager_enabled":false}
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
test:
name: Runs all tests on main
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
Expand Down
Binary file added example/assets/font/geologica/geologica_bold.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added example/assets/font/ubuntu/ubuntu_bold.ttf
Binary file not shown.
Binary file added example/assets/font/ubuntu/ubuntu_light.ttf
Binary file not shown.
Binary file added example/assets/font/ubuntu/ubuntu_medium.ttf
Binary file not shown.
Binary file added example/assets/font/ubuntu/ubuntu_regular.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions example/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class MyAppState extends State<MyApp> {
return ImpaktfullUiApp(
title: 'impaktfull ui',
impaktfullUiTheme: ThemeButton.activeTheme,
flavorBannerText: 'Testing',
// const is disabled here because it would not rebuild when the theme is set again.
// ignore: prefer_const_constructors
home: HomeScreen(),
Expand Down
21 changes: 21 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ dev_dependencies:
flutter:
uses-material-design: true
assets:
- assets/font/ubuntu/
- assets/font/geologica/
- assets/image/
- assets/lottie/
- assets/rive/
fonts:
- family: Ubuntu
fonts:
- asset: assets/font/ubuntu/ubuntu_light.ttf
weight: 300
- asset: assets/font/ubuntu/ubuntu_regular.ttf
- asset: assets/font/ubuntu/ubuntu_medium.ttf
weight: 600
- asset: assets/font/ubuntu/ubuntu_bold.ttf
weight: 700
- family: Geologica
fonts:
- asset: assets/font/geologica/geologica-light.ttf
weight: 300
- asset: assets/font/geologica/geologica-regular.ttf
- asset: assets/font/geologica/geologica-medium.ttf
weight: 600
- asset: assets/font/geologica/geologica-bold.ttf
weight: 700
55 changes: 33 additions & 22 deletions lib/src/components/app/app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:impaktfull_ui_2/src/components/app/debug/app_debug_flag.dart';
import 'package:impaktfull_ui_2/src/components/snacky/snacky_configurator.dart';
import 'package:impaktfull_ui_2/src/theme/theme.dart';
import 'package:snacky/snacky.dart';
Expand All @@ -22,6 +23,8 @@ class ImpaktfullUiApp extends StatelessWidget {
final Widget Function(BuildContext context, Widget app)? builder;
final TargetPlatform? targetPlatform;
final bool showDebugFlag;
final String? flavorBannerText;
final Color? flavorBannerColor;

const ImpaktfullUiApp({
required this.title,
Expand All @@ -41,8 +44,13 @@ class ImpaktfullUiApp extends StatelessWidget {
this.builder,
this.targetPlatform,
this.showDebugFlag = kDebugMode,
this.flavorBannerText,
this.flavorBannerColor,
super.key,
});
}) : assert(
home != null || onGenerateRoute != null || builder != null,
'Either home or onGenerateRoute or builder must be provided',
);

@override
Widget build(BuildContext context) {
Expand All @@ -54,28 +62,31 @@ class ImpaktfullUiApp extends StatelessWidget {
snackyBuilder: snackyBuilder,
app: Builder(
builder: (context) {
final app = MaterialApp(
title: title,
home: home,
debugShowCheckedModeBanner: showDebugFlag,
locale: locale,
theme: (materialLightTheme ?? Theme.of(context))
.removeUnwantedBehavior(
targetPlatform: targetPlatform,
final app = AppDebugFlag(
showDebugFlag: showDebugFlag,
flavorBannerText: flavorBannerText,
flavorBannerColor: flavorBannerColor ?? theme.colors.accent,
child: MaterialApp(
title: title,
home: home,
debugShowCheckedModeBanner: showDebugFlag,
locale: locale,
theme: (materialLightTheme ?? Theme.of(context)).removeUnwantedBehavior(
targetPlatform: targetPlatform,
),
darkTheme: (materialLightTheme ?? Theme.of(context)).removeUnwantedBehavior(
targetPlatform: targetPlatform,
),
supportedLocales: supportedLocales,
localizationsDelegates: localizationsDelegates,
navigatorKey: navigatorKey,
initialRoute: initialRoute,
onGenerateRoute: onGenerateRoute,
navigatorObservers: [
SnackyNavigationObserver(),
...navigatorObservers,
],
),
darkTheme: (materialLightTheme ?? Theme.of(context))
.removeUnwantedBehavior(
targetPlatform: targetPlatform,
),
supportedLocales: supportedLocales,
localizationsDelegates: localizationsDelegates,
navigatorKey: navigatorKey,
initialRoute: initialRoute,
onGenerateRoute: onGenerateRoute,
navigatorObservers: [
SnackyNavigationObserver(),
...navigatorObservers,
],
);
return builder?.call(context, app) ?? app;
},
Expand Down
47 changes: 47 additions & 0 deletions lib/src/components/app/debug/app_debug_flag.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';

class AppDebugFlag extends StatelessWidget {
final bool showDebugFlag;
final String? flavorBannerText;
final Color flavorBannerColor;
final Widget child;

const AppDebugFlag({
required this.showDebugFlag,
required this.flavorBannerText,
required this.child,
required this.flavorBannerColor,
super.key,
});

@override
Widget build(BuildContext context) {
final showFlavorBannerFlag = flavorBannerText != null;
if (!showDebugFlag && !showFlavorBannerFlag) return child;
return Directionality(
textDirection: TextDirection.ltr,
child: Builder(
builder: (context) {
Widget child = this.child;
if (showDebugFlag) {
child = Banner(
message: 'Debug',
location: BannerLocation.topEnd,
child: child,
);
}
if (showFlavorBannerFlag) {
child = Banner(
message: flavorBannerText!,
location: BannerLocation.topStart,
color: flavorBannerColor,
child: child,
);
}

return child;
},
),
);
}
}
1 change: 1 addition & 0 deletions lib/src/components/bottom_sheet/bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class ImpaktfullUiBottomSheet extends StatelessWidget
}
},
asset: componentTheme.assets.close,
color: componentTheme.colors.icon,
),
),
),
Expand Down
5 changes: 3 additions & 2 deletions lib/src/components/bottom_sheet/bottom_sheet_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class ImpaktfullUiBottomSheetTheme extends ImpaktfullUiComponentTheme {
required this.textStyles,
});

static ImpaktfullUiBottomSheetTheme of(BuildContext context) =>
ImpaktfullUiTheme.of(context).components.bottomSheet;
static ImpaktfullUiBottomSheetTheme of(BuildContext context) => ImpaktfullUiTheme.of(context).components.bottomSheet;
}

class ImpaktfullUiBottomSheetAssetsTheme {
Expand All @@ -30,10 +29,12 @@ class ImpaktfullUiBottomSheetAssetsTheme {
class ImpaktfullUiBottomSheetColorTheme {
final Color background;
final Color handle;
final Color icon;

const ImpaktfullUiBottomSheetColorTheme({
required this.background,
required this.handle,
required this.icon,
});
}

Expand Down
24 changes: 18 additions & 6 deletions lib/src/theme/textstyle_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ class ImpaktfullUiTextStylesTheme {
required this.onDestructive,
});

List<ImpaktfullUiTextStyleTheme> get all => [
onCanvas,
onCanvasPrimary,
onCanvasSecondary,
onCanvasTertiary,
onCard,
onCardPrimary,
onCardSecondary,
onCardTertiary,
onCardDestructive,
onPrimary,
onSecondary,
onDestructive,
];

ImpaktfullUiTextStylesTheme copyWith({
ImpaktfullUiTextStyleTheme? onCanvas,
ImpaktfullUiTextStyleTheme? onCanvasPrimary,
Expand Down Expand Up @@ -133,8 +148,7 @@ class ImpaktfullUiTextStyleDisplayTheme {
String? fontFamily,
}) {
return ImpaktfullUiTextStyleDisplayTheme(
extraLarge2:
TextStyle(fontSize: 72, color: color, fontFamily: fontFamily),
extraLarge2: TextStyle(fontSize: 72, color: color, fontFamily: fontFamily),
extraLarge: TextStyle(fontSize: 60, color: color, fontFamily: fontFamily),
large: TextStyle(fontSize: 48, color: color, fontFamily: fontFamily),
medium: TextStyle(fontSize: 30, color: color, fontFamily: fontFamily),
Expand Down Expand Up @@ -179,13 +193,11 @@ class ImpaktfullUiTextStyleTextTheme {
String? fontFamily,
}) =>
ImpaktfullUiTextStyleTextTheme(
extraLarge:
TextStyle(fontSize: 20, color: color, fontFamily: fontFamily),
extraLarge: TextStyle(fontSize: 20, color: color, fontFamily: fontFamily),
large: TextStyle(fontSize: 18, color: color, fontFamily: fontFamily),
medium: TextStyle(fontSize: 16, color: color, fontFamily: fontFamily),
small: TextStyle(fontSize: 14, color: color, fontFamily: fontFamily),
extraSmall:
TextStyle(fontSize: 12, color: color, fontFamily: fontFamily),
extraSmall: TextStyle(fontSize: 12, color: color, fontFamily: fontFamily),
);
}

Expand Down
17 changes: 11 additions & 6 deletions lib/src/theme/theme_configurator.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import 'dart:ui';

import 'package:flutter/widgets.dart';
import 'package:impaktfull_ui_2/src/theme/theme.dart';

ImpaktfullUiTheme? _theme;
ImpaktfullUiTheme? _testTheme;
Locale? _locale;

ImpaktfullUiTheme get theme {
if (_testTheme != null) return _testTheme!;
if (_theme == null) {
throw Exception(
'Impaktfull theme is not set, make sure you call setImpaktfullTheme() before using theme.');
throw Exception('Impaktfull theme is not set, make sure you call setImpaktfullTheme() before using theme.');
}
return _theme!;
}

Locale get locale {
if (_locale == null) {
throw Exception(
'Impaktfull locale is not set, make sure you call setImpaktfullLocale() before using theme.');
throw Exception('Impaktfull locale is not set, make sure you call setImpaktfullLocale() before using theme.');
}
return _locale!;
}

void setImpaktfullUiTheme(ImpaktfullUiTheme? theme) {
if (_testTheme != null) return;
_theme = theme ?? ImpaktfullUiTheme.getDefault();
}

@visibleForTesting
void setImpaktfullUiTestTheme(ImpaktfullUiTheme? theme) {
_testTheme = theme;
}

void setImpaktfullUiLocale(Locale? locale) {
_locale = locale ?? const Locale('en');
}
3 changes: 2 additions & 1 deletion lib/src/theme/theme_default.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class DefaultTheme {
colors: ImpaktfullUiBottomSheetColorTheme(
background: colors.card,
handle: colors.text,
icon: colors.text,
),
dimens: ImpaktfullUiBottomSheetDimensTheme(
borderRadius: dimens.borderRadius.copyWith(
Expand Down Expand Up @@ -466,7 +467,7 @@ class DefaultTheme {
chevronUp: assets.icons.chevronUp,
),
colors: ImpaktfullUiSidebarNavigationItemColorTheme(
background: colors.primary,
background: colors.canvas,
icon: colors.text,
),
dimens: ImpaktfullUiSidebarNavigationItemDimensTheme(
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ dependencies:
snacky: ^0.5.3

dev_dependencies:
alchemist: ^0.10.0
flutter_lints: ^3.0.0
flutter_test:
sdk: flutter

flutter:
uses-material-design: true
assets:
- assets/lottie/
Binary file added test/assets/font/geologica/geologica_bold.ttf
Binary file not shown.
Binary file added test/assets/font/geologica/geologica_light.ttf
Binary file not shown.
Binary file added test/assets/font/geologica/geologica_medium.ttf
Binary file not shown.
Binary file added test/assets/font/geologica/geologica_regular.ttf
Binary file not shown.
Binary file not shown.
Binary file added test/assets/font/ubuntu/ubuntu_bold.ttf
Binary file not shown.
Binary file added test/assets/font/ubuntu/ubuntu_light.ttf
Binary file not shown.
Binary file added test/assets/font/ubuntu/ubuntu_medium.ttf
Binary file not shown.
Binary file added test/assets/font/ubuntu/ubuntu_regular.ttf
Binary file not shown.
Binary file added test/assets/font/ubuntu/ubuntu_semibold.ttf
Binary file not shown.
27 changes: 27 additions & 0 deletions test/src/components/app/app_golden_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:impaktfull_ui_2/impaktfull_ui.dart';

import '../../../util/golden_test_util.dart';
import '../../../util/golden_test_variant.dart';

void main() {
setUp(() => setupComponentTest());

runComponentTest(
fileName: 'impaktfull_app',
goldenTests: () => [
GoldenTest(
description: 'App',
child: ImpaktfullUiApp(
title: 'impaktfull app',
home: Container(
width: 400,
height: 400,
color: theme.colors.accent,
),
),
),
],
);
}
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.
27 changes: 27 additions & 0 deletions test/src/components/button/button_golden_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:impaktfull_ui_2/impaktfull_ui.dart';

import '../../../util/golden_test_util.dart';
import '../../../util/golden_test_variant.dart';

void main() {
setUp(() => setupComponentTest());

runComponentTest(
fileName: 'impaktfull_ui_button',
columns: 5,
goldenTests: () => [
for (final type in ImpaktfullUiButtonType.values) ...[
for (final size in ImpaktfullUiButtonSize.values) ...[
GoldenTest(
child: ImpaktfullUiButton(
type: type,
title: 'Button',
size: size,
),
),
],
],
],
);
}
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.
Loading

0 comments on commit 7d08c85

Please sign in to comment.