From 2e5edd3b84207f6a00fb5bfc4a847e3dfedec0af Mon Sep 17 00:00:00 2001 From: Joshua Tang Date: Sat, 17 Dec 2022 12:51:24 +1100 Subject: [PATCH] refactor: update abstract text style cubit properties and constructor --- .../abstract_text_style.dart | 1 + lib/abstract_text_style/consts.dart | 57 +++++++++++ .../cubit/abstract_text_style_cubit.dart | 28 +++--- lib/app_bar_theme/app_bar_theme.dart | 1 - lib/app_bar_theme/constants.dart | 8 -- .../cubit/app_bar_theme_cubit.dart | 50 ++++++---- lib/text_theme/cubits/text_style_cubits.dart | 96 +++---------------- .../abstract_text_style_cubit_test.dart | 6 +- test/abstract_text_style/mocks.dart | 11 +-- .../app_bar_theme_cubit_test.dart | 65 +++++-------- .../app_bar_theme_editor_test.dart | 30 +++--- .../font_picker_test.dart | 0 test/pump_app.dart | 10 +- test/text_theme/text_style_cubit_test.dart | 21 ++++ 14 files changed, 189 insertions(+), 195 deletions(-) create mode 100644 lib/abstract_text_style/consts.dart delete mode 100644 lib/app_bar_theme/constants.dart rename test/{text_theme => font}/font_picker_test.dart (100%) create mode 100644 test/text_theme/text_style_cubit_test.dart diff --git a/lib/abstract_text_style/abstract_text_style.dart b/lib/abstract_text_style/abstract_text_style.dart index f64d6bdc..3eb9afca 100644 --- a/lib/abstract_text_style/abstract_text_style.dart +++ b/lib/abstract_text_style/abstract_text_style.dart @@ -1,2 +1,3 @@ +export 'consts.dart'; export 'cubit/abstract_text_style_cubit.dart'; export 'view/abstract_text_style_editor.dart'; diff --git a/lib/abstract_text_style/consts.dart b/lib/abstract_text_style/consts.dart new file mode 100644 index 00000000..a66d9de5 --- /dev/null +++ b/lib/abstract_text_style/consts.dart @@ -0,0 +1,57 @@ +import 'package:flutter/material.dart'; + +enum TypeScale { + headline1, + headline2, + headline3, + headline4, + headline5, + headline6, + subtitle1, + subtitle2, + bodyText1, + bodyText2, + button, + caption, + overline, +} + +const _englishTextTheme = Typography.englishLike2018; +final _blackTextTheme = _englishTextTheme.merge( + Typography.blackMountainView, +); +final _whiteTextTheme = _englishTextTheme.merge( + Typography.whiteMountainView, +); + +final kBlackTextStyles = { + TypeScale.headline1: _blackTextTheme.headline1, + TypeScale.headline2: _blackTextTheme.headline2, + TypeScale.headline3: _blackTextTheme.headline3, + TypeScale.headline4: _blackTextTheme.headline4, + TypeScale.headline5: _blackTextTheme.headline5, + TypeScale.headline6: _blackTextTheme.headline6, + TypeScale.subtitle1: _blackTextTheme.subtitle1, + TypeScale.subtitle2: _blackTextTheme.subtitle2, + TypeScale.bodyText1: _blackTextTheme.bodyText1, + TypeScale.bodyText2: _blackTextTheme.bodyText2, + TypeScale.button: _blackTextTheme.button, + TypeScale.caption: _blackTextTheme.caption, + TypeScale.overline: _blackTextTheme.overline, +}; + +final kWhiteTextStyles = { + TypeScale.headline1: _whiteTextTheme.headline1, + TypeScale.headline2: _whiteTextTheme.headline2, + TypeScale.headline3: _whiteTextTheme.headline3, + TypeScale.headline4: _whiteTextTheme.headline4, + TypeScale.headline5: _whiteTextTheme.headline5, + TypeScale.headline6: _whiteTextTheme.headline6, + TypeScale.subtitle1: _whiteTextTheme.subtitle1, + TypeScale.subtitle2: _whiteTextTheme.subtitle2, + TypeScale.bodyText1: _whiteTextTheme.bodyText1, + TypeScale.bodyText2: _whiteTextTheme.bodyText2, + TypeScale.button: _whiteTextTheme.button, + TypeScale.caption: _whiteTextTheme.caption, + TypeScale.overline: _whiteTextTheme.overline, +}; diff --git a/lib/abstract_text_style/cubit/abstract_text_style_cubit.dart b/lib/abstract_text_style/cubit/abstract_text_style_cubit.dart index 84163771..b66d39c9 100644 --- a/lib/abstract_text_style/cubit/abstract_text_style_cubit.dart +++ b/lib/abstract_text_style/cubit/abstract_text_style_cubit.dart @@ -1,3 +1,4 @@ +import 'package:appainter/abstract_text_style/abstract_text_style.dart'; import 'package:appainter/common/common.dart'; import 'package:appainter/models/models.dart'; import 'package:appainter/services/services.dart'; @@ -11,26 +12,21 @@ part 'abstract_text_style_cubit.g.dart'; part 'text_style_state.dart'; abstract class AbstractTextStyleCubit extends Cubit { - final TextStyle? baseStyle; - final TextStyle? blackStyle; - final TextStyle? whiteStyle; - final TextStyle? defaultStyle; - AbstractTextStyleCubit({ - this.baseStyle, - this.blackStyle, - this.whiteStyle, - this.defaultStyle, - }) : assert( - (baseStyle != null && blackStyle != null && whiteStyle != null) || - defaultStyle != null), - super( - TextStyleState(style: defaultStyle ?? baseStyle!.merge(blackStyle!)), - ); + required this.typeScale, + this.isBaseStyleBlack = true, + }) : super(TextStyleState( + style: isBaseStyleBlack + ? kBlackTextStyles[typeScale]! + : kWhiteTextStyles[typeScale]!, + )); + + final TypeScale typeScale; + final bool isBaseStyleBlack; void styleBrightnessChanged(bool isDark) { final style = - defaultStyle ?? baseStyle!.merge(isDark ? whiteStyle! : blackStyle!); + isDark ? kWhiteTextStyles[typeScale]! : kBlackTextStyles[typeScale]!; emit(state.copyWith(style: style)); } diff --git a/lib/app_bar_theme/app_bar_theme.dart b/lib/app_bar_theme/app_bar_theme.dart index 1b2e7fed..1ec24528 100644 --- a/lib/app_bar_theme/app_bar_theme.dart +++ b/lib/app_bar_theme/app_bar_theme.dart @@ -1,3 +1,2 @@ export 'cubit/app_bar_theme_cubit.dart'; export 'view/app_bar_theme_editor.dart'; -export 'constants.dart'; diff --git a/lib/app_bar_theme/constants.dart b/lib/app_bar_theme/constants.dart deleted file mode 100644 index 4472107c..00000000 --- a/lib/app_bar_theme/constants.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'package:appainter/common/common.dart'; -import 'package:flutter/material.dart'; - -const kAppBarIconTheme = IconThemeData(); -final kAppBarTitleTextStyle = - kEnglishTextTheme.merge(kWhiteTextTheme).headline6!; -final kAppBarToolbarTextStyle = - kEnglishTextTheme.merge(kWhiteTextTheme).bodyText2!; diff --git a/lib/app_bar_theme/cubit/app_bar_theme_cubit.dart b/lib/app_bar_theme/cubit/app_bar_theme_cubit.dart index 93b3a4ba..7deacafb 100644 --- a/lib/app_bar_theme/cubit/app_bar_theme_cubit.dart +++ b/lib/app_bar_theme/cubit/app_bar_theme_cubit.dart @@ -2,29 +2,21 @@ import 'dart:async'; import 'package:appainter/abstract_icon_theme/abstract_icon_theme.dart'; import 'package:appainter/abstract_text_style/abstract_text_style.dart'; -import 'package:appainter/app_bar_theme/app_bar_theme.dart'; +import 'package:appainter/models/models.dart'; import 'package:appainter_annotations/annotations.dart'; import 'package:bloc/bloc.dart'; import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; -import 'package:appainter/models/models.dart'; part 'app_bar_theme_cubit.g.dart'; part 'app_bar_theme_state.dart'; +const _titleTypeScale = TypeScale.headline6; +const _toolbarTypeScale = TypeScale.bodyText2; + @ThemeDocs(extraPropertyTypes: {'SystemUiOverlayStyle'}) class AppBarThemeCubit extends Cubit { - final AppBarActionsIconThemeCubit actionsIconThemeCubit; - final AppBarIconThemeCubit iconThemeCubit; - final AppBarTitleTextStyleCubit titleTextStyleCubit; - final AppBarToolbarTextStyleCubit toolbarTextStyleCubit; - - late final StreamSubscription actionsIconThemeCubitSubscription; - late final StreamSubscription iconThemeCubitSubscription; - late final StreamSubscription titleTextStyleCubitSubscription; - late final StreamSubscription toolbarTextStyleCubitSubscription; - AppBarThemeCubit({ required this.actionsIconThemeCubit, required this.iconThemeCubit, @@ -57,6 +49,20 @@ class AppBarThemeCubit extends Cubit { ); } + final AppBarActionsIconThemeCubit actionsIconThemeCubit; + final AppBarIconThemeCubit iconThemeCubit; + final AppBarTitleTextStyleCubit titleTextStyleCubit; + final AppBarToolbarTextStyleCubit toolbarTextStyleCubit; + + late final StreamSubscription actionsIconThemeCubitSubscription; + late final StreamSubscription iconThemeCubitSubscription; + late final StreamSubscription titleTextStyleCubitSubscription; + late final StreamSubscription toolbarTextStyleCubitSubscription; + + static const defaultIconTheme = IconThemeData(); + static final defaultTitleTextStyle = kWhiteTextStyles[_titleTypeScale]!; + static final defaultToolbarTextStyle = kWhiteTextStyles[_toolbarTypeScale]!; + @override Future close() { actionsIconThemeCubitSubscription.cancel(); @@ -68,16 +74,16 @@ class AppBarThemeCubit extends Cubit { void themeChanged(AppBarTheme theme) { actionsIconThemeCubit.themeChanged( - theme.actionsIconTheme ?? kAppBarIconTheme, + theme.actionsIconTheme ?? defaultIconTheme, ); iconThemeCubit.themeChanged( - theme.actionsIconTheme ?? kAppBarIconTheme, + theme.actionsIconTheme ?? defaultIconTheme, ); titleTextStyleCubit.styleChanged( - theme.titleTextStyle ?? kAppBarTitleTextStyle, + theme.titleTextStyle ?? defaultTitleTextStyle, ); toolbarTextStyleCubit.styleChanged( - theme.toolbarTextStyle ?? kAppBarToolbarTextStyle, + theme.toolbarTextStyle ?? defaultToolbarTextStyle, ); emit(state.copyWith(theme: theme)); } @@ -140,9 +146,17 @@ class AppBarActionsIconThemeCubit extends AbstractIconThemeCubit {} class AppBarIconThemeCubit extends AbstractIconThemeCubit {} class AppBarTitleTextStyleCubit extends AbstractTextStyleCubit { - AppBarTitleTextStyleCubit() : super(defaultStyle: kAppBarTitleTextStyle); + AppBarTitleTextStyleCubit() + : super( + typeScale: _titleTypeScale, + isBaseStyleBlack: false, + ); } class AppBarToolbarTextStyleCubit extends AbstractTextStyleCubit { - AppBarToolbarTextStyleCubit() : super(defaultStyle: kAppBarToolbarTextStyle); + AppBarToolbarTextStyleCubit() + : super( + typeScale: _toolbarTypeScale, + isBaseStyleBlack: false, + ); } diff --git a/lib/text_theme/cubits/text_style_cubits.dart b/lib/text_theme/cubits/text_style_cubits.dart index e63e2db7..72ddc602 100644 --- a/lib/text_theme/cubits/text_style_cubits.dart +++ b/lib/text_theme/cubits/text_style_cubits.dart @@ -1,123 +1,53 @@ import 'package:appainter/abstract_text_style/abstract_text_style.dart'; -import 'package:flutter/material.dart'; - -const _englishTextTheme = Typography.englishLike2018; -const _blackTextTheme = Typography.blackMountainView; -const _whiteTextTheme = Typography.whiteMountainView; class Headline1TextStyleCubit extends AbstractTextStyleCubit { - Headline1TextStyleCubit() - : super( - baseStyle: _englishTextTheme.headline1!, - blackStyle: _blackTextTheme.headline1!, - whiteStyle: _whiteTextTheme.headline1!, - ); + Headline1TextStyleCubit() : super(typeScale: TypeScale.headline1); } class Headline2TextStyleCubit extends AbstractTextStyleCubit { - Headline2TextStyleCubit() - : super( - baseStyle: _englishTextTheme.headline2!, - blackStyle: _blackTextTheme.headline2!, - whiteStyle: _whiteTextTheme.headline2!, - ); + Headline2TextStyleCubit() : super(typeScale: TypeScale.headline2); } class Headline3TextStyleCubit extends AbstractTextStyleCubit { - Headline3TextStyleCubit() - : super( - baseStyle: _englishTextTheme.headline3!, - blackStyle: _blackTextTheme.headline3!, - whiteStyle: _whiteTextTheme.headline3!, - ); + Headline3TextStyleCubit() : super(typeScale: TypeScale.headline3); } class Headline4TextStyleCubit extends AbstractTextStyleCubit { - Headline4TextStyleCubit() - : super( - baseStyle: _englishTextTheme.headline4!, - blackStyle: _blackTextTheme.headline4!, - whiteStyle: _whiteTextTheme.headline4!, - ); + Headline4TextStyleCubit() : super(typeScale: TypeScale.headline4); } class Headline5TextStyleCubit extends AbstractTextStyleCubit { - Headline5TextStyleCubit() - : super( - baseStyle: _englishTextTheme.headline5!, - blackStyle: _blackTextTheme.headline5!, - whiteStyle: _whiteTextTheme.headline5!, - ); + Headline5TextStyleCubit() : super(typeScale: TypeScale.headline5); } class Headline6TextStyleCubit extends AbstractTextStyleCubit { - Headline6TextStyleCubit() - : super( - baseStyle: _englishTextTheme.headline6!, - blackStyle: _blackTextTheme.headline6!, - whiteStyle: _whiteTextTheme.headline6!, - ); + Headline6TextStyleCubit() : super(typeScale: TypeScale.headline6); } class Subtitle1TextStyleCubit extends AbstractTextStyleCubit { - Subtitle1TextStyleCubit() - : super( - baseStyle: _englishTextTheme.subtitle1!, - blackStyle: _blackTextTheme.subtitle1!, - whiteStyle: _whiteTextTheme.subtitle1!, - ); + Subtitle1TextStyleCubit() : super(typeScale: TypeScale.subtitle1); } class Subtitle2TextStyleCubit extends AbstractTextStyleCubit { - Subtitle2TextStyleCubit() - : super( - baseStyle: _englishTextTheme.subtitle2!, - blackStyle: _blackTextTheme.subtitle2!, - whiteStyle: _whiteTextTheme.subtitle2!, - ); + Subtitle2TextStyleCubit() : super(typeScale: TypeScale.subtitle2); } class BodyText1TextStyleCubit extends AbstractTextStyleCubit { - BodyText1TextStyleCubit() - : super( - baseStyle: _englishTextTheme.bodyText1!, - blackStyle: _blackTextTheme.bodyText1!, - whiteStyle: _whiteTextTheme.bodyText1!, - ); + BodyText1TextStyleCubit() : super(typeScale: TypeScale.bodyText1); } class BodyText2TextStyleCubit extends AbstractTextStyleCubit { - BodyText2TextStyleCubit() - : super( - baseStyle: _englishTextTheme.bodyText2!, - blackStyle: _blackTextTheme.bodyText2!, - whiteStyle: _whiteTextTheme.bodyText2!, - ); + BodyText2TextStyleCubit() : super(typeScale: TypeScale.bodyText2); } class ButtonTextStyleCubit extends AbstractTextStyleCubit { - ButtonTextStyleCubit() - : super( - baseStyle: _englishTextTheme.button!, - blackStyle: _blackTextTheme.button!, - whiteStyle: _whiteTextTheme.button!, - ); + ButtonTextStyleCubit() : super(typeScale: TypeScale.button); } class CaptionTextStyleCubit extends AbstractTextStyleCubit { - CaptionTextStyleCubit() - : super( - baseStyle: _englishTextTheme.caption!, - blackStyle: _blackTextTheme.caption!, - whiteStyle: _whiteTextTheme.caption!, - ); + CaptionTextStyleCubit() : super(typeScale: TypeScale.caption); } class OverlineTextStyleCubit extends AbstractTextStyleCubit { - OverlineTextStyleCubit() - : super( - baseStyle: _englishTextTheme.overline!, - blackStyle: _blackTextTheme.overline!, - whiteStyle: _whiteTextTheme.overline!, - ); + OverlineTextStyleCubit() : super(typeScale: TypeScale.overline); } diff --git a/test/abstract_text_style/abstract_text_style_cubit_test.dart b/test/abstract_text_style/abstract_text_style_cubit_test.dart index 37340510..d5866dbe 100644 --- a/test/abstract_text_style/abstract_text_style_cubit_test.dart +++ b/test/abstract_text_style/abstract_text_style_cubit_test.dart @@ -25,7 +25,7 @@ void main() { setUp(() { cubit = TestTextStyleCubit(); - style = cubit.baseStyle!.merge(cubit.blackStyle); + style = cubit.blackTextStyle; color = getRandomColor(); doubleNum = Random().nextDouble(); @@ -40,9 +40,7 @@ void main() { act: (cubit) => cubit.styleBrightnessChanged(isDark), expect: () => [ TextStyleState( - style: isDark - ? style.merge(cubit.whiteStyle) - : style.merge(cubit.blackStyle), + style: isDark ? cubit.whiteTextStyle : cubit.blackTextStyle, ) ], ); diff --git a/test/abstract_text_style/mocks.dart b/test/abstract_text_style/mocks.dart index bff8093f..84559e39 100644 --- a/test/abstract_text_style/mocks.dart +++ b/test/abstract_text_style/mocks.dart @@ -3,12 +3,11 @@ import 'package:bloc_test/bloc_test.dart'; import 'package:flutter/material.dart'; class TestTextStyleCubit extends AbstractTextStyleCubit { - TestTextStyleCubit() - : super( - baseStyle: Typography.englishLike2018.bodyText1!, - blackStyle: Typography.blackMountainView.bodyText1!, - whiteStyle: Typography.whiteMountainView.bodyText1!, - ); + TestTextStyleCubit() : super(typeScale: TypeScale.headline1); + + TextStyle get blackTextStyle => kBlackTextStyles[typeScale]!; + + TextStyle get whiteTextStyle => kWhiteTextStyles[typeScale]!; } class MockTextStyleCubit extends MockCubit diff --git a/test/app_bar_theme/app_bar_theme_cubit_test.dart b/test/app_bar_theme/app_bar_theme_cubit_test.dart index 2fbda481..8382f7b3 100644 --- a/test/app_bar_theme/app_bar_theme_cubit_test.dart +++ b/test/app_bar_theme/app_bar_theme_cubit_test.dart @@ -1,12 +1,12 @@ import 'dart:math'; import 'package:appainter/abstract_icon_theme/abstract_icon_theme.dart'; -import 'package:appainter/abstract_text_style/cubit/abstract_text_style_cubit.dart'; +import 'package:appainter/abstract_text_style/abstract_text_style.dart'; +import 'package:appainter/app_bar_theme/app_bar_theme.dart'; +import 'package:appainter/models/models.dart'; import 'package:bloc_test/bloc_test.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:appainter/app_bar_theme/app_bar_theme.dart'; -import 'package:appainter/models/models.dart'; import 'package:random_color_scheme/random_color_scheme.dart'; import '../utils.dart'; @@ -20,7 +20,6 @@ void main() { late AppBarTheme theme; late IconThemeData iconTheme; - late TextStyle textStyle; late Color color; late double doubleNum; @@ -54,27 +53,29 @@ void main() { expect: () => [ AppBarThemeState(theme: theme), AppBarThemeState( - theme: theme.copyWith(actionsIconTheme: kAppBarIconTheme), + theme: theme.copyWith( + actionsIconTheme: AppBarThemeCubit.defaultIconTheme, + ), ), AppBarThemeState( theme: theme.copyWith( - actionsIconTheme: kAppBarIconTheme, - iconTheme: kAppBarIconTheme, + actionsIconTheme: AppBarThemeCubit.defaultIconTheme, + iconTheme: AppBarThemeCubit.defaultIconTheme, ), ), AppBarThemeState( theme: theme.copyWith( - actionsIconTheme: kAppBarIconTheme, - iconTheme: kAppBarIconTheme, - titleTextStyle: kAppBarTitleTextStyle, + actionsIconTheme: AppBarThemeCubit.defaultIconTheme, + iconTheme: AppBarThemeCubit.defaultIconTheme, + titleTextStyle: AppBarThemeCubit.defaultTitleTextStyle, ), ), AppBarThemeState( theme: theme.copyWith( - actionsIconTheme: kAppBarIconTheme, - iconTheme: kAppBarIconTheme, - titleTextStyle: kAppBarTitleTextStyle, - toolbarTextStyle: kAppBarToolbarTextStyle, + actionsIconTheme: AppBarThemeCubit.defaultIconTheme, + iconTheme: AppBarThemeCubit.defaultIconTheme, + titleTextStyle: AppBarThemeCubit.defaultTitleTextStyle, + toolbarTextStyle: AppBarThemeCubit.defaultToolbarTextStyle, ), ), ], @@ -188,31 +189,15 @@ void main() { ), ); - blocTest( - 'emits title text style color', - setUp: () => textStyle = kAppBarTitleTextStyle.copyWith(color: color), - build: () => titleTextStyleCubit, - act: (cubit) => cubit.colorChanged(color), - expect: () => [TextStyleState(style: textStyle)], - verify: (cubit) => expect( - themeCubit.state, - equals( - AppBarThemeState(theme: AppBarTheme(titleTextStyle: textStyle)), - ), - ), - ); + test('initialise title text style cubit', () { + final cubit = AppBarTitleTextStyleCubit(); + expect(cubit.typeScale, equals(TypeScale.headline6)); + expect(cubit.isBaseStyleBlack, equals(false)); + }); - blocTest( - 'emits toolbar text style color', - setUp: () => textStyle = kAppBarToolbarTextStyle.copyWith(color: color), - build: () => toolbarTextStyleCubit, - act: (cubit) => cubit.colorChanged(color), - expect: () => [TextStyleState(style: textStyle)], - verify: (cubit) => expect( - themeCubit.state, - equals( - AppBarThemeState(theme: AppBarTheme(toolbarTextStyle: textStyle)), - ), - ), - ); + test('initialise toolbar text style cubit', () { + final cubit = AppBarToolbarTextStyleCubit(); + expect(cubit.typeScale, equals(TypeScale.bodyText2)); + expect(cubit.isBaseStyleBlack, equals(false)); + }); } diff --git a/test/app_bar_theme/app_bar_theme_editor_test.dart b/test/app_bar_theme/app_bar_theme_editor_test.dart index cbea2fbb..6e700bb2 100644 --- a/test/app_bar_theme/app_bar_theme_editor_test.dart +++ b/test/app_bar_theme/app_bar_theme_editor_test.dart @@ -1,7 +1,7 @@ import 'dart:math'; import 'package:appainter/abstract_icon_theme/abstract_icon_theme.dart'; -import 'package:appainter/abstract_text_style/cubit/abstract_text_style_cubit.dart'; +import 'package:appainter/abstract_text_style/abstract_text_style.dart'; import 'package:appainter/app_bar_theme/app_bar_theme.dart'; import 'package:appainter/color_theme/color_theme.dart'; import 'package:appainter/models/models.dart'; @@ -18,9 +18,11 @@ import '../widget_testers.dart'; void main() { const defaultAppBarThemeState = AppBarThemeState(); const defaultIconThemeState = IconThemeState(); - final defaultTextStyleState = TextStyleState(style: kAppBarTitleTextStyle); + final defaultTextStyleState = TextStyleState( + style: AppBarThemeCubit.defaultTitleTextStyle, + ); final defaultToolbarStyleState = TextStyleState( - style: kAppBarToolbarTextStyle, + style: AppBarThemeCubit.defaultToolbarTextStyle, ); final widgetTesters = WidgetTesters(); @@ -109,7 +111,7 @@ void main() { ); } - testWidgets('displays nested editors', (tester) async { + testWidgets('display nested editors', (tester) async { await pumpApp(tester, defaultAppBarThemeState); expect(find.byType(ActionsIconThemeCard), findsOneWidget); expect(find.byType(IconThemeCard), findsOneWidget); @@ -117,7 +119,7 @@ void main() { expect(find.byType(ToolbarTextStyleCard), findsOneWidget); }); - testWidgets('updates background color', (tester) async { + testWidgets('update background color', (tester) async { final state = AppBarThemeState( theme: AppBarTheme(backgroundColor: color), ); @@ -132,7 +134,7 @@ void main() { verify(() => appBarThemeCubit.backgroundColorChanged(color)).called(1); }); - testWidgets('updates foreground color', (tester) async { + testWidgets('update foreground color', (tester) async { final state = AppBarThemeState( theme: AppBarTheme(foregroundColor: color), ); @@ -147,7 +149,7 @@ void main() { verify(() => appBarThemeCubit.foregroundColorChanged(color)).called(1); }); - testWidgets('updates elevation', (tester) async { + testWidgets('update elevation', (tester) async { final state = AppBarThemeState( theme: AppBarTheme(elevation: doubleNum), ); @@ -162,7 +164,7 @@ void main() { verify(() => appBarThemeCubit.elevationChanged(doubleStr)).called(1); }); - testWidgets('updates shadow color', (tester) async { + testWidgets('update shadow color', (tester) async { final state = AppBarThemeState(theme: AppBarTheme(shadowColor: color)); await pumpApp(tester, state); @@ -175,9 +177,9 @@ void main() { verify(() => appBarThemeCubit.shadowColorChanged(color)).called(1); }); - group('tests center title switch', () { + group('test center title switch', () { for (var isCenter in [true, false]) { - testWidgets('updates to $isCenter', (tester) async { + testWidgets('update to $isCenter', (tester) async { final state = AppBarThemeState( theme: AppBarTheme(centerTitle: isCenter), ); @@ -194,7 +196,7 @@ void main() { } }); - testWidgets('updates title spacing', (tester) async { + testWidgets('update title spacing', (tester) async { final state = AppBarThemeState( theme: AppBarTheme(titleSpacing: doubleNum), ); @@ -209,7 +211,7 @@ void main() { verify(() => appBarThemeCubit.titleSpacingChanged(doubleStr)).called(1); }); - testWidgets('updates tool bar height', (tester) async { + testWidgets('update tool bar height', (tester) async { final state = AppBarThemeState( theme: AppBarTheme(toolbarHeight: doubleNum), ); @@ -224,10 +226,10 @@ void main() { verify(() => appBarThemeCubit.toolBarHeightChanged(doubleStr)).called(1); }); - group('tests system UI overlay style dropdown', () { + group('test system UI overlay style dropdown', () { for (var style in MySystemUiOverlayStyle().values) { final styleStr = MySystemUiOverlayStyle().convertToString(style)!; - testWidgets('updates to ${style.statusBarBrightness}', (tester) async { + testWidgets('update to ${style.statusBarBrightness}', (tester) async { final state = AppBarThemeState( theme: AppBarTheme(systemOverlayStyle: style), ); diff --git a/test/text_theme/font_picker_test.dart b/test/font/font_picker_test.dart similarity index 100% rename from test/text_theme/font_picker_test.dart rename to test/font/font_picker_test.dart diff --git a/test/pump_app.dart b/test/pump_app.dart index c9e13e00..6ecfe60c 100644 --- a/test/pump_app.dart +++ b/test/pump_app.dart @@ -1,8 +1,5 @@ import 'package:appainter/abstract_icon_theme/abstract_icon_theme.dart'; import 'package:appainter/abstract_text_style/abstract_text_style.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_test/flutter_test.dart'; import 'package:appainter/advanced_theme/advanced_theme.dart'; import 'package:appainter/app_bar_theme/app_bar_theme.dart'; import 'package:appainter/basic_theme/basic_theme.dart'; @@ -21,6 +18,9 @@ import 'package:appainter/switch_theme/switch_theme.dart'; import 'package:appainter/tab_bar_theme/tab_bar_theme.dart'; import 'package:appainter/text_button_theme/text_button_theme.dart'; import 'package:appainter/text_theme/text_theme.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; import 'mocks.dart'; @@ -119,10 +119,10 @@ extension PumpApp on WidgetTester { when(() => appBarActionsIconThemeCubit.state).thenReturn(_iconThemeState); when(() => appBarIconThemeCubit.state).thenReturn(_iconThemeState); when(() => appBarTitleTextStyleCubit.state).thenReturn( - TextStyleState(style: kAppBarTitleTextStyle), + TextStyleState(style: AppBarThemeCubit.defaultTitleTextStyle), ); when(() => appBarToolbarTextStyleCubit.state).thenReturn( - TextStyleState(style: kAppBarToolbarTextStyle), + TextStyleState(style: AppBarThemeCubit.defaultToolbarTextStyle), ); when(() => tabBarThemeCubit.state).thenReturn(const TabBarThemeState()); diff --git a/test/text_theme/text_style_cubit_test.dart b/test/text_theme/text_style_cubit_test.dart new file mode 100644 index 00000000..1636ed66 --- /dev/null +++ b/test/text_theme/text_style_cubit_test.dart @@ -0,0 +1,21 @@ +import 'package:appainter/abstract_text_style/consts.dart'; +import 'package:appainter/text_theme/text_theme.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + test('initialise text style cubits', () { + expect(Headline1TextStyleCubit().typeScale, equals(TypeScale.headline1)); + expect(Headline2TextStyleCubit().typeScale, equals(TypeScale.headline2)); + expect(Headline3TextStyleCubit().typeScale, equals(TypeScale.headline3)); + expect(Headline4TextStyleCubit().typeScale, equals(TypeScale.headline4)); + expect(Headline5TextStyleCubit().typeScale, equals(TypeScale.headline5)); + expect(Headline6TextStyleCubit().typeScale, equals(TypeScale.headline6)); + expect(Subtitle1TextStyleCubit().typeScale, equals(TypeScale.subtitle1)); + expect(Subtitle2TextStyleCubit().typeScale, equals(TypeScale.subtitle2)); + expect(BodyText1TextStyleCubit().typeScale, equals(TypeScale.bodyText1)); + expect(BodyText2TextStyleCubit().typeScale, equals(TypeScale.bodyText2)); + expect(ButtonTextStyleCubit().typeScale, equals(TypeScale.button)); + expect(CaptionTextStyleCubit().typeScale, equals(TypeScale.caption)); + expect(OverlineTextStyleCubit().typeScale, equals(TypeScale.overline)); + }); +}