diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0cac28b67..622e6919c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,40 +7,48 @@ on: branches: [main] jobs: - test_mix_repo: + test: runs-on: ubuntu-latest - name: Test Mix Repo + name: Test steps: - name: Checkout mix repo uses: actions/checkout@v2 - with: - path: main - - - name: Checkout remix_ui repo - uses: actions/checkout@v2 - with: - repository: conceptadev/remix_ui - path: remix - name: Setup Flutter uses: subosito/flutter-action@v2 with: channel: "stable" - - run: cd main && flutter pub get + - run: flutter pub get - - uses: axel-op/dart-package-analyzer@v3 + - uses: invertase/github-action-dart-analyzer@v1 with: - githubToken: ${{ secrets.GITHUB_TOKEN }} - relativePath: main + fatal-infos: false + + - name: Install DCM + uses: CQLabs/setup-dcm@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + + - name: Run DCM + run: dcm analyze lib --fatal-style --fatal-performance --fatal-warnings + + # - name: Run DCM + # uses: CQLabs/dcm-action@v1 + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # folders: lib + # pull_request_comment_on_fail: true + + + - run: flutter test - - run: cd main && flutter test analyze_breaking_changes: runs-on: ubuntu-latest name: Analyze Breaking Changes - needs: test_mix_repo + needs: test steps: - name: Checkout mix repo uses: actions/checkout@v2 diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 30cab1c57..8383adb42 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -3,6 +3,8 @@ "andreasblech.better-tests", "dart-code.dart-code", "dcmdev.dcm-vscode-extension", - "flutterando.flutter-coverage" + "flutterando.flutter-coverage", + "dart-code.flutter", + "circlecodesolution.ccs-flutter-color" ] } \ No newline at end of file diff --git a/analysis_options.yaml b/analysis_options.yaml index e4c7dc218..09b9a2326 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,53 +1,44 @@ include: package:flutter_lints/flutter.yaml +analyzer: + exclude: + - "**/*.g.dart" + - "**/*.freezed.dart" + - "tool/**" # For lint rules and documentation, see http://dart-lang.github.io/linter/lints. # Uncomment to specify additional rules. linter: rules: + # TODO: Turn this to true when all public apis are documented public_member_api_docs: false prefer_relative_imports: true -analyzer: - exclude: - - "**/*.g.dart" - - "**/*.freezed.dart" - dart_code_metrics: extends: - package:dart_code_metrics_presets/recommended.yaml - metrics-exclude: + - package:dart_code_metrics_presets/metrics_recommended.yaml + metrics-excludes: - test/** - rules-exclude: - - "test/**" rules: + # avoid-collection-mutating-methods: true + newline-before-return: true + avoid-importing-entrypoint-exports: + only-in-src: true prefer-match-file-name: false - no-object-declaration: false + prefer-correct-callback-field-name: false + # Remove later when cleaning up prefer-single-widget-per-file: false - parameters-ordering: false + # End of remove later match-getter-setter-field-names: false prefer-dedicated-media-query-methods: false - arguments-ordering: - child-last: true - avoid-dynamic: false avoid-shadowing: false - prefer-getter-over-method: false enum-constants-ordering: false - prefer-widget-private-members: false - prefer-static-class: false - avoid-late-keyword: false - avoid-declaring-call-method: false - avoid-long-parameter-list: false - avoid-recursive-calls: false - no-magic-number: false - avoid-ignoring-return-values: false - prefer-commenting-analyzer-ignores: false - prefer-correct-identifier-length: false avoid-unsafe-collection-methods: false - avoid-similar-names: false - no-equal-arguments: false prefer-prefixed-global-constants: false avoid-returning-widgets: false + arguments-ordering: + child-last: true avoid-nested-conditional-expressions: acceptable-level: 3 member-ordering: @@ -66,7 +57,4 @@ dart_code_metrics: - overridden-public-getters - build-method prefer-named-boolean-parameters: - ignore-single: true - - - \ No newline at end of file + ignore-single: true \ No newline at end of file diff --git a/lib/mix.dart b/lib/mix.dart index fe133a4ba..ff7d6de7a 100644 --- a/lib/mix.dart +++ b/lib/mix.dart @@ -1,15 +1,27 @@ library mix; +// This file is generated by the update_exports.dart script. +// DO NOT MODIFY MANUALLY + +// Some default exports +export 'src/deprecations.dart'; + +// Automated file exports export 'src/attributes/border/border_dto.dart'; export 'src/attributes/border/border_radius_dto.dart'; export 'src/attributes/border/border_radius_util.dart'; export 'src/attributes/border/border_util.dart'; +export 'src/attributes/border/shape_border_dto.dart'; +export 'src/attributes/border/shape_border_util.dart'; +export 'src/attributes/color/color_directives.dart'; export 'src/attributes/color/color_dto.dart'; export 'src/attributes/color/color_util.dart'; export 'src/attributes/constraints/constraints_dto.dart'; export 'src/attributes/constraints/constraints_util.dart'; export 'src/attributes/decoration/decoration_dto.dart'; export 'src/attributes/decoration/decoration_util.dart'; +export 'src/attributes/decoration/image/decoration_image_dto.dart'; +export 'src/attributes/decoration/image/decoration_image_util.dart'; export 'src/attributes/gradient/gradient_dto.dart'; export 'src/attributes/gradient/gradient_util.dart'; export 'src/attributes/nested_style/nested_style_attribute.dart'; @@ -31,13 +43,13 @@ export 'src/core/attribute.dart'; export 'src/core/attributes_map.dart'; export 'src/core/decorator.dart'; export 'src/core/directive.dart'; +export 'src/core/extensions/color_ext.dart'; export 'src/core/extensions/iterable_ext.dart'; export 'src/core/extensions/values_ext.dart'; export 'src/core/styled_widget.dart'; export 'src/decorators/widget_decorator_widget.dart'; export 'src/decorators/widget_decorators.dart'; export 'src/decorators/widget_decorators_util.dart'; -export 'src/deprecations.dart'; export 'src/factory/mix_provider.dart'; export 'src/factory/mix_provider_data.dart'; export 'src/factory/style_mix.dart'; diff --git a/lib/src/attributes/border/border_dto.dart b/lib/src/attributes/border/border_dto.dart index eae4b470a..2744e37e0 100644 --- a/lib/src/attributes/border/border_dto.dart +++ b/lib/src/attributes/border/border_dto.dart @@ -1,5 +1,3 @@ -// ignore_for_file: prefer-returning-conditional-expressions - import 'package:flutter/material.dart'; import '../../core/attribute.dart'; diff --git a/lib/src/attributes/border/border_radius_util.dart b/lib/src/attributes/border/border_radius_util.dart index c0e5b1921..baf1b5d30 100644 --- a/lib/src/attributes/border/border_radius_util.dart +++ b/lib/src/attributes/border/border_radius_util.dart @@ -1,5 +1,3 @@ -// ignore_for_file: avoid-non-null-assertion - import 'package:flutter/material.dart'; import '../../core/attribute.dart'; diff --git a/lib/src/attributes/border/shape_border_dto.dart b/lib/src/attributes/border/shape_border_dto.dart index ab5f3bede..258376b77 100644 --- a/lib/src/attributes/border/shape_border_dto.dart +++ b/lib/src/attributes/border/shape_border_dto.dart @@ -1,6 +1,9 @@ import 'package:flutter/material.dart'; -import '../../../mix.dart'; +import '../../core/attribute.dart'; +import '../../factory/mix_provider_data.dart'; +import 'border_dto.dart'; +import 'border_radius_dto.dart'; @immutable abstract class ShapeBorderDto extends Dto diff --git a/lib/src/attributes/border/shape_border_util.dart b/lib/src/attributes/border/shape_border_util.dart index 90acada43..d8c93f6d9 100644 --- a/lib/src/attributes/border/shape_border_util.dart +++ b/lib/src/attributes/border/shape_border_util.dart @@ -1,6 +1,11 @@ import 'package:flutter/material.dart'; -import '../../../mix.dart'; +import '../../core/attribute.dart'; +import '../scalars/scalar_util.dart'; +import 'border_dto.dart'; +import 'border_radius_dto.dart'; +import 'border_radius_util.dart'; +import 'border_util.dart'; import 'shape_border_dto.dart'; /// Utility for setting `ShapeBorder` values. diff --git a/lib/src/attributes/color/color_util.dart b/lib/src/attributes/color/color_util.dart index a42f79ad6..881422634 100644 --- a/lib/src/attributes/color/color_util.dart +++ b/lib/src/attributes/color/color_util.dart @@ -1,5 +1,3 @@ -// ignore_for_file: avoid-non-null-assertion - import 'package:flutter/material.dart'; import '../../core/attribute.dart'; diff --git a/lib/src/attributes/decoration/decoration_dto.dart b/lib/src/attributes/decoration/decoration_dto.dart index 4a513a3bc..06de01106 100644 --- a/lib/src/attributes/decoration/decoration_dto.dart +++ b/lib/src/attributes/decoration/decoration_dto.dart @@ -122,8 +122,8 @@ class BoxDecorationDto extends DecorationDto { gradient: GradientDto.maybeFrom(decoration.gradient), boxShadow: decoration.boxShadow?.map(BoxShadowDto.from).toList(), shape: decoration.shape, - image: DecorationImageDto.maybeFrom(decoration.image), backgroundBlendMode: decoration.backgroundBlendMode, + image: DecorationImageDto.maybeFrom(decoration.image), ); } @@ -166,13 +166,13 @@ class BoxDecorationDto extends DecorationDto { BoxDecoration resolve(MixData mix) { return BoxDecoration( color: color?.resolve(mix), + image: image?.resolve(mix), border: border?.resolve(mix), borderRadius: borderRadius?.resolve(mix), boxShadow: boxShadow?.map((e) => e.resolve(mix)).toList(), gradient: gradient?.resolve(mix), backgroundBlendMode: backgroundBlendMode, shape: shape ?? BoxShape.rectangle, - image: image?.resolve(mix), ); } diff --git a/lib/src/attributes/spacing/spacing_dto.dart b/lib/src/attributes/spacing/spacing_dto.dart index 9ab7e9233..48cd5ec59 100644 --- a/lib/src/attributes/spacing/spacing_dto.dart +++ b/lib/src/attributes/spacing/spacing_dto.dart @@ -1,5 +1,3 @@ -// ignore_for_file: prefer-moving-to-variable - import 'package:flutter/material.dart'; import '../../factory/mix_provider_data.dart'; diff --git a/lib/src/attributes/text_style/text_style_dto.dart b/lib/src/attributes/text_style/text_style_dto.dart index cb156565e..61d2b8fe5 100644 --- a/lib/src/attributes/text_style/text_style_dto.dart +++ b/lib/src/attributes/text_style/text_style_dto.dart @@ -1,5 +1,3 @@ -// ignore_for_file: avoid-non-null-assertion - import 'dart:ui'; import 'package:flutter/material.dart'; diff --git a/lib/src/core/extensions/color_ext.dart b/lib/src/core/extensions/color_ext.dart index cada9c47e..1dce9e94e 100644 --- a/lib/src/core/extensions/color_ext.dart +++ b/lib/src/core/extensions/color_ext.dart @@ -7,6 +7,7 @@ import '../../attributes/color/color_dto.dart'; extension ColorExt on Color { Color mix(Color toColor, [int amount = 50]) { final p = RangeError.checkValueInInterval(amount, 0, 100, 'amount') / 100; + return Color.fromARGB( ((toColor.alpha - alpha) * p + alpha).round(), ((toColor.red - red) * p + red).round(), @@ -19,11 +20,13 @@ extension ColorExt on Color { final p = RangeError.checkValueInInterval(amount, 0, 100, 'amount') / 100; final hsl = HSLColor.fromColor(this); final lightness = _clamp(hsl.lightness + p); + return hsl.withLightness(lightness).toColor(); } Color brighten([int amount = 10]) { final p = RangeError.checkValueInInterval(amount, 0, 100, 'amount') / 100; + return Color.fromARGB( alpha, math.max(0, math.min(255, red - (255 * -p).round())), @@ -44,6 +47,7 @@ extension ColorExt on Color { final p = RangeError.checkValueInInterval(amount, 0, 100, 'amount') / 100; final hsl = HSLColor.fromColor(this); final lightness = _clamp(hsl.lightness - p); + return hsl.withLightness(lightness).toColor(); } @@ -61,6 +65,7 @@ extension ColorExt on Color { final p = RangeError.checkValueInInterval(amount, 0, 100, 'amount') / 100; final hsl = HSLColor.fromColor(this); final saturation = _clamp(hsl.saturation - p); + return hsl.withSaturation(saturation).toColor(); } @@ -68,6 +73,7 @@ extension ColorExt on Color { final p = RangeError.checkValueInInterval(amount, 0, 100, 'amount') / 100; final hsl = HSLColor.fromColor(this); final saturation = _clamp(hsl.saturation + p); + return hsl.withSaturation(saturation).toColor(); } @@ -76,6 +82,7 @@ extension ColorExt on Color { Color complement() { final hsl = HSLColor.fromColor(this); final hue = (hsl.hue + 180) % 360; + return hsl.withHue(hue).toColor(); } diff --git a/lib/src/decorators/widget_decorators.dart b/lib/src/decorators/widget_decorators.dart index b8a1dba18..2288f009e 100644 --- a/lib/src/decorators/widget_decorators.dart +++ b/lib/src/decorators/widget_decorators.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; import '../attributes/scalars/scalar_util.dart'; import '../core/attribute.dart'; import '../core/decorator.dart'; +import '../factory/mix_provider_data.dart'; import '../helpers/lerp_helpers.dart'; class AspectRatioDecorator extends WidgetDecorator { @@ -24,7 +25,7 @@ class AspectRatioDecorator extends WidgetDecorator { get props => [aspectRatio]; @override - Widget build(mix, child) => + Widget build(MixData mix, Widget child) => AspectRatio(key: key, aspectRatio: aspectRatio, child: child); } @@ -41,7 +42,7 @@ class VisibilityDecorator extends WidgetDecorator { get props => [visible]; @override - Widget build(mix, child) => + Widget build(MixData mix, Widget child) => Visibility(key: key, visible: visible, child: child); } @@ -71,7 +72,7 @@ class FlexibleDecorator extends WidgetDecorator get props => [flex, fit]; @override - Widget build(mix, Widget child) { + Widget build(MixData mix, Widget child) { return Flexible( key: key, flex: flex ?? 1, @@ -97,7 +98,8 @@ class OpacityDecorator extends WidgetDecorator { get props => [opacity]; @override - Widget build(mix, child) => Opacity(key: key, opacity: opacity, child: child); + Widget build(MixData mix, Widget child) => + Opacity(key: key, opacity: opacity, child: child); } class RotateDecorator extends WidgetDecorator { @@ -113,7 +115,7 @@ class RotateDecorator extends WidgetDecorator { get props => [quarterTurns]; @override - Widget build(mix, child) { + Widget build(MixData mix, Widget child) { return RotatedBox(key: key, quarterTurns: quarterTurns, child: child); } } @@ -131,7 +133,7 @@ class ScaleDecorator extends WidgetDecorator { get props => [scale]; @override - Widget build(mix, child) { + Widget build(MixData mix, Widget child) { return Transform.scale(key: key, scale: scale, child: child); } } @@ -185,7 +187,7 @@ class ClipDecorator extends WidgetDecorator get props => [clipType, clipBehavior, clipper, borderRadius]; @override - Widget build(mix, child) { + Widget build(MixData mix, Widget child) { switch (clipType) { case ClipType.path: return ClipPath( diff --git a/lib/src/deprecations.dart b/lib/src/deprecations.dart index caa9e5c5e..73dfac07f 100644 --- a/lib/src/deprecations.dart +++ b/lib/src/deprecations.dart @@ -1,4 +1,23 @@ -import '../mix.dart'; +// ignore_for_file: avoid-dynamic + +import '../src/attributes/spacing/spacing_util.dart'; +import '../src/factory/mix_provider_data.dart'; +import '../src/specs/container/box_util.dart'; +import '../src/specs/flex/flex_util.dart'; +import '../src/specs/icon/icon_util.dart'; +import '../src/specs/icon/icon_widget.dart'; +import '../src/specs/stack/stack_util.dart'; +import '../src/specs/text/text_util.dart'; +import '../src/specs/text/text_widget.dart'; +import '../src/utils/context_variant_util/on_breakpoint_util.dart'; +import '../src/utils/context_variant_util/on_brightness_util.dart'; +import '../src/utils/context_variant_util/on_helper_util.dart'; +import '../src/utils/context_variant_util/on_orientation_util.dart'; +import '../src/utils/helper_util.dart'; +import '../src/variants/variant.dart'; +import '../src/widgets/pressable/widget_state_util.dart'; +import 'core/attribute.dart'; +import 'factory/style_mix.dart'; const kShortAliasDeprecation = 'Short aliases will be deprecated, you can create your own. Example: final p = padding;'; diff --git a/lib/src/factory/style_mix.dart b/lib/src/factory/style_mix.dart index 308519616..b45d02c55 100644 --- a/lib/src/factory/style_mix.dart +++ b/lib/src/factory/style_mix.dart @@ -396,8 +396,7 @@ class SwitchCondition { const SwitchCondition(this.condition, this.value); } -Style Function(Iterable attributes) - _styleType>() { +Style Function(Iterable attributes) _styleType() { return (Iterable attributes) { final merged = attributes.reduce((value, element) => value.merge(element)); diff --git a/lib/src/helpers/compare_mixin.dart b/lib/src/helpers/compare_mixin.dart index 46d1f6e7e..ed80384a7 100644 --- a/lib/src/helpers/compare_mixin.dart +++ b/lib/src/helpers/compare_mixin.dart @@ -1,3 +1,5 @@ +// ignore_for_file: avoid-dynamic + import 'package:flutter/material.dart'; import '../core/extensions/iterable_ext.dart'; diff --git a/lib/src/specs/container/box_spec.dart b/lib/src/specs/container/box_spec.dart index 00c9c7047..9141d17d5 100644 --- a/lib/src/specs/container/box_spec.dart +++ b/lib/src/specs/container/box_spec.dart @@ -120,7 +120,6 @@ class BoxSpecTween extends Tween { if (begin == null) return end; if (end == null) return begin; - // ignore: avoid-non-null-assertion return begin!.lerp(end!, t); } } diff --git a/lib/src/specs/container/box_widget.dart b/lib/src/specs/container/box_widget.dart index 75ea6d2b4..731f767e8 100644 --- a/lib/src/specs/container/box_widget.dart +++ b/lib/src/specs/container/box_widget.dart @@ -223,10 +223,10 @@ class AnimatedMixedBox extends StatelessWidget { alignment: spec.alignment, padding: spec.padding, decoration: spec.decoration, + foregroundDecoration: spec.foregroundDecoration, width: spec.width, height: spec.height, constraints: spec.constraints, - foregroundDecoration: spec.foregroundDecoration, margin: spec.margin, transform: spec.transform, clipBehavior: spec.clipBehavior ?? Clip.none, diff --git a/lib/src/specs/image/image_spec.dart b/lib/src/specs/image/image_spec.dart index eddadf80a..4a3663d3a 100644 --- a/lib/src/specs/image/image_spec.dart +++ b/lib/src/specs/image/image_spec.dart @@ -53,12 +53,12 @@ class ImageSpec extends Spec { width: lerpDouble(width, other?.width, t), height: lerpDouble(height, other?.height, t), color: Color.lerp(color, other?.color, t), - centerSlice: lerpSnap(centerSlice, other?.centerSlice, t), repeat: lerpSnap(repeat, other?.repeat, t), fit: lerpSnap(fit, other?.fit, t), + alignment: AlignmentGeometry.lerp(alignment, other?.alignment, t), + centerSlice: lerpSnap(centerSlice, other?.centerSlice, t), filterQuality: lerpSnap(filterQuality, other?.filterQuality, t), colorBlendMode: lerpSnap(colorBlendMode, other?.colorBlendMode, t), - alignment: AlignmentGeometry.lerp(alignment, other?.alignment, t), ); } @@ -81,8 +81,8 @@ class ImageSpec extends Spec { color: color ?? this.color, repeat: repeat ?? this.repeat, fit: fit ?? this.fit, - centerSlice: centerSlice ?? this.centerSlice, alignment: alignment ?? this.alignment, + centerSlice: centerSlice ?? this.centerSlice, filterQuality: filterQuality ?? this.filterQuality, colorBlendMode: colorBlendMode ?? this.colorBlendMode, ); diff --git a/lib/src/specs/image/image_util.dart b/lib/src/specs/image/image_util.dart index 739c02f82..dd7815f41 100644 --- a/lib/src/specs/image/image_util.dart +++ b/lib/src/specs/image/image_util.dart @@ -22,13 +22,13 @@ class ImageUtility extends SpecUtility { FilterQuality? filterQuality, }) { return ImageSpecAttribute( + centerSlice: centerSlice, width: width, height: height, color: color, repeat: repeat, fit: fit, alignment: alignment, - centerSlice: centerSlice, colorBlendMode: blendMode, filterQuality: filterQuality, ); @@ -64,7 +64,8 @@ class ImageUtility extends SpecUtility { FilterQualityUtility get filterQuality { return FilterQualityUtility( - (filterQuality) => _only(filterQuality: filterQuality)); + (filterQuality) => _only(filterQuality: filterQuality), + ); } BlendModeUtility get blendMode { diff --git a/lib/src/specs/image/image_widget.dart b/lib/src/specs/image/image_widget.dart index 49bbcd96c..08d21e910 100644 --- a/lib/src/specs/image/image_widget.dart +++ b/lib/src/specs/image/image_widget.dart @@ -7,13 +7,6 @@ import '../../utils/helper_util.dart'; import 'image_spec.dart'; class StyledImage extends StyledWidget { - final ImageProvider image; - final ImageFrameBuilder? frameBuilder; - final ImageLoadingBuilder? loadingBuilder; - final ImageErrorWidgetBuilder? errorBuilder; - final String? semanticLabel; - final bool excludeFromSemantics; - const StyledImage({ super.key, super.style, @@ -26,16 +19,23 @@ class StyledImage extends StyledWidget { required this.image, }); + final ImageProvider image; + final ImageFrameBuilder? frameBuilder; + final ImageLoadingBuilder? loadingBuilder; + final ImageErrorWidgetBuilder? errorBuilder; + final String? semanticLabel; + final bool excludeFromSemantics; + @override Widget build(BuildContext context) { return withMix(context, (mix) { return MixedImage( image: image, - errorBuilder: errorBuilder, - excludeFromSemantics: excludeFromSemantics, frameBuilder: frameBuilder, loadingBuilder: loadingBuilder, + errorBuilder: errorBuilder, semanticLabel: semanticLabel, + excludeFromSemantics: excludeFromSemantics, ); }); } @@ -78,12 +78,12 @@ class MixedImage extends StatelessWidget { width: spec.width, height: spec.height, color: spec.color, - repeat: spec.repeat ?? ImageRepeat.noRepeat, + colorBlendMode: spec.colorBlendMode ?? BlendMode.clear, fit: spec.fit, alignment: spec.alignment ?? Alignment.center, + repeat: spec.repeat ?? ImageRepeat.noRepeat, centerSlice: spec.centerSlice, filterQuality: spec.filterQuality ?? FilterQuality.none, - colorBlendMode: spec.colorBlendMode ?? BlendMode.clear, ); return shouldApplyDecorators( diff --git a/lib/src/specs/stack/stack_widget.dart b/lib/src/specs/stack/stack_widget.dart index 805fa0fbd..698d6dc2b 100644 --- a/lib/src/specs/stack/stack_widget.dart +++ b/lib/src/specs/stack/stack_widget.dart @@ -104,4 +104,6 @@ class ZBox extends StyledWidget { // Default Stack used as a fallback // for styling properties in MixedStack. -final _defaultStack = Stack(); +// ignore: prefer_const_constructors +// TODO: Need to turn this into const for Flutter SDK support later +const _defaultStack = Stack(); diff --git a/lib/src/theme/mix_theme.dart b/lib/src/theme/mix_theme.dart index 54173d070..ab652c544 100644 --- a/lib/src/theme/mix_theme.dart +++ b/lib/src/theme/mix_theme.dart @@ -1,5 +1,3 @@ -// ignore_for_file: avoid-non-null-assertion - import 'package:flutter/material.dart'; import '../helpers/compare_mixin.dart'; diff --git a/lib/src/theme/tokens/space_token.dart b/lib/src/theme/tokens/space_token.dart index e790ad8be..c27f42350 100644 --- a/lib/src/theme/tokens/space_token.dart +++ b/lib/src/theme/tokens/space_token.dart @@ -1,5 +1,3 @@ -// ignore_for_file: avoid-non-null-assertion - import 'package:flutter/material.dart'; import '../mix_theme.dart'; diff --git a/lib/src/utils/context_variant_util/on_breakpoint_util.dart b/lib/src/utils/context_variant_util/on_breakpoint_util.dart index 1ac735bc9..9bd31e584 100644 --- a/lib/src/utils/context_variant_util/on_breakpoint_util.dart +++ b/lib/src/utils/context_variant_util/on_breakpoint_util.dart @@ -24,7 +24,10 @@ final onLarge = onBreakpointToken(BreakpointToken.large); /// [minWidth] and [maxWidth] define the width constraints, while [orientation] specifies /// the orientation constraint. This function returns a [ContextVariant] which will apply /// when the screen size matches these constraints. -ContextVariant onBreakpoint({minWidth = 0, maxWidth = double.infinity}) { +ContextVariant onBreakpoint({ + double minWidth = 0, + double maxWidth = double.infinity, +}) { final constraints = Breakpoint(minWidth: minWidth, maxWidth: maxWidth); final constraintName = 'minWidth-${constraints.minWidth}-maxWidth-${constraints.maxWidth}'; diff --git a/lib/src/widgets/pressable/pressable_widget.dart b/lib/src/widgets/pressable/pressable_widget.dart index 46b85c288..c54859aef 100644 --- a/lib/src/widgets/pressable/pressable_widget.dart +++ b/lib/src/widgets/pressable/pressable_widget.dart @@ -179,9 +179,7 @@ class PressableWidgetState extends State { focusable: onEnabled && _node.canRequestFocus, focused: _node.hasFocus, child: widget.disabled - ? GestureDetector( - child: focusableDetector, - ) + ? GestureDetector(child: focusableDetector) : GestureDetector( onTapDown: (_) => updateState(() => _pressed = true), onTapUp: (_) => handleUnpress(), diff --git a/pubspec.yaml b/pubspec.yaml index 52926c050..ec4128365 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ dev_dependencies: flutter_lints: ^2.0.3 flutter_test: sdk: flutter - dart_code_metrics_presets: ^2.4.0 + dart_code_metrics_presets: ^2.8.0 path: ^1.8.3 mockito: ^5.4.2 meta: ^1.9.1 diff --git a/test/bechmarks/widget_build_test.dart b/test/bechmarks/widget_build_test.dart index 1f0b9d834..803230216 100644 --- a/test/bechmarks/widget_build_test.dart +++ b/test/bechmarks/widget_build_test.dart @@ -1,5 +1,7 @@ // ignore_for_file: prefer_const_constructors +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mix/mix.dart'; @@ -18,8 +20,8 @@ class StyledContainerExample extends StatelessWidget { final borderAttribute = box.border.all( color: Colors.red, - width: 1, style: BorderStyle.solid, + width: 1, ); final radiusAttribute = box.borderRadius(10); @@ -36,10 +38,7 @@ class StyledContainerExample extends StatelessWidget { radiusAttribute, colorAttribute, ), - child: const SizedBox( - width: 100, - height: 100, - ), + child: const SizedBox(width: 100, height: 100), ); } } @@ -50,23 +49,20 @@ class ContainerExample extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - padding: const EdgeInsets.all(10), - margin: const EdgeInsets.all(15), alignment: Alignment.center, - clipBehavior: Clip.hardEdge, + padding: const EdgeInsets.all(10), decoration: BoxDecoration( + color: Colors.red, border: Border.all( color: Colors.red, width: 1, style: BorderStyle.solid, ), borderRadius: BorderRadius.circular(10), - color: Colors.red, - ), - child: const SizedBox( - width: 100, - height: 100, ), + margin: const EdgeInsets.all(15), + clipBehavior: Clip.hardEdge, + child: const SizedBox(width: 100, height: 100), ); } } @@ -82,6 +78,7 @@ void main() { await tester.pumpWidget(widget); } stopwatch.stop(); + return stopwatch.elapsedMilliseconds; }) ?? 0; @@ -101,24 +98,28 @@ void main() { // print('StyledContainer: $elapsedStyledContainerTime ms'); // print('Container: $elapsedContainerTime ms'); // StyledContainer shoudl not b slower than 0.01 ms - expect(elapsedStyledContainerTime, lessThan(elapsedContainerTime + 0.02), - reason: 'StyledContainer is too slow'); + expect( + elapsedStyledContainerTime, + lessThan(elapsedContainerTime + 0.02), + reason: 'StyledContainer is too slow', + ); }); // test perfromance for Style.create test('Style.create', () { const iterations = 10000; final stopwatch = Stopwatch()..start(); + Style style = Style(); for (int i = 0; i < iterations; i++) { - Style.create([ + style = Style.create([ box.padding(10), box.margin(15), box.alignment.center(), box.clipBehavior.hardEdge(), box.border.all( color: Colors.red, - width: 1, style: BorderStyle.solid, + width: 1, ), box.borderRadius(10), box.color(Colors.red), @@ -127,15 +128,17 @@ void main() { stopwatch.stop(); final elapsedTime = stopwatch.elapsedMilliseconds / iterations; - print('Style.create: $elapsedTime ms'); + log('Style.create: $elapsedTime ms'); + expect(style.isNotEmpty, true); }); // test performance for MixData.create test('MixData.create', () { const iterations = 10000; final stopwatch = Stopwatch()..start(); + MixData mixData = EmptyMixData; for (int i = 0; i < iterations; i++) { - MixData.create( + mixData = MixData.create( MockBuildContext(), Style( box.padding(10), @@ -144,8 +147,8 @@ void main() { box.clipBehavior.hardEdge(), box.border.all( color: Colors.red, - width: 1, style: BorderStyle.solid, + width: 1, ), box.borderRadius(10), box.color(Colors.red), @@ -156,7 +159,8 @@ void main() { stopwatch.stop(); final timeElapsed = stopwatch.elapsedMilliseconds / iterations; - print('MixData.create: $timeElapsed ms'); + log('MixData.create: $timeElapsed ms'); + expect(mixData.attributes.isNotEmpty, true); }); } @@ -201,10 +205,7 @@ class StyleWidgetExpensiveAttributge extends StatelessWidget { return Box( style: mergedStyle, - child: const SizedBox( - width: 100, - height: 100, - ), + child: const SizedBox(width: 100, height: 100), ); } } diff --git a/test/helpers/attribute_generator.dart b/test/helpers/attribute_generator.dart index 648ebfe3d..169c26914 100644 --- a/test/helpers/attribute_generator.dart +++ b/test/helpers/attribute_generator.dart @@ -1,5 +1,7 @@ // Used mostly for testing +// ignore_for_file: unused-code + import 'dart:math'; import 'package:flutter/material.dart'; @@ -15,11 +17,11 @@ class RandomGenerator { }) { final random = Random(); - minWidth ??= random.nextDouble() * 200; - minHeight ??= random.nextDouble() * 200; + minWidth ??= (random.nextDouble() * 200); + minHeight ??= (random.nextDouble() * 200); - maxHeight ??= minWidth + random.nextDouble() * 200; - maxWidth ??= minHeight + random.nextDouble() * 200; + maxHeight ??= minWidth + (random.nextDouble() * 200); + maxWidth ??= minHeight + (random.nextDouble() * 200); return BoxConstraints( minWidth: minWidth, @@ -44,11 +46,11 @@ class RandomGenerator { return StrutStyle( fontFamily: fontFamily ?? 'Roboto', fontFamilyFallback: fontFamilyFallback ?? ['Roboto'], - fontSize: fontSize ?? random.nextDouble() * 20, + fontSize: fontSize ?? (random.nextDouble() * 20), + height: height ?? (random.nextDouble() * 20), + leading: leading ?? (random.nextDouble() * 20), fontWeight: fontWeight ?? FontWeight.values.random(), fontStyle: fontStyle ?? FontStyle.values.random(), - height: height ?? random.nextDouble() * 20, - leading: leading ?? random.nextDouble() * 20, forceStrutHeight: forceStrutHeight ?? random.nextBool(), ); } @@ -62,10 +64,10 @@ class RandomGenerator { final random = Random(); return EdgeInsets.only( - top: top ?? random.nextDouble() * 20, - bottom: bottom ?? random.nextDouble() * 20, - left: left ?? random.nextDouble() * 20, - right: right ?? random.nextDouble() * 20, + left: left ?? (random.nextDouble() * 20), + top: top ?? (random.nextDouble() * 20), + right: right ?? (random.nextDouble() * 20), + bottom: bottom ?? (random.nextDouble() * 20), ); } @@ -78,55 +80,23 @@ class RandomGenerator { final random = Random(); return EdgeInsetsDirectional.only( - top: top ?? random.nextDouble() * 20, - bottom: bottom ?? random.nextDouble() * 20, - start: start ?? random.nextDouble() * 20, - end: end ?? random.nextDouble() * 20, + start: start ?? (random.nextDouble() * 20), + top: top ?? (random.nextDouble() * 20), + end: end ?? (random.nextDouble() * 20), + bottom: bottom ?? (random.nextDouble() * 20), ); } - static Matrix4 matrix4({ - double? x, - double? y, - double? z, - }) { + static Matrix4 matrix4({double? x, double? y, double? z}) { final random = Random(); return Matrix4.translationValues( - x ?? random.nextDouble() * 20, - y ?? random.nextDouble() * 20, - z ?? random.nextDouble() * 20, + x ?? (random.nextDouble() * 20), + y ?? (random.nextDouble() * 20), + z ?? (random.nextDouble() * 20), ); } - TextOverflow textOverflow([TextOverflow? overflow]) { - return overflow ?? TextOverflow.values.random(); - } - - Axis axis([Axis? axis]) { - return axis ?? Random().randomElement(Axis.values); - } - - MainAxisAlignment mainAxisAlignment([MainAxisAlignment? alignment]) { - return alignment ?? MainAxisAlignment.values.random(); - } - - MainAxisSize mainAxisSize([MainAxisSize? size]) { - return size ?? MainAxisSize.values.random(); - } - - CrossAxisAlignment crossAxisAlignment([CrossAxisAlignment? alignment]) { - return alignment ?? CrossAxisAlignment.values.random(); - } - - TextBaseline textBaseline([TextBaseline? baseline]) { - return baseline ?? TextBaseline.values.random(); - } - - VerticalDirection verticalDirection([VerticalDirection? direction]) { - return direction ?? VerticalDirection.values.random(); - } - static BorderRadius borderRadius({ double? topLeft, double? topRight, @@ -156,7 +126,7 @@ class RandomGenerator { } static Radius radius([double? radius]) { - return Radius.circular(radius ?? Random().nextDouble() * 20); + return Radius.circular(radius ?? (Random().nextDouble() * 20)); } static Border border({ @@ -166,10 +136,10 @@ class RandomGenerator { BorderSide? bottom, }) { return Border( - left: left ?? RandomGenerator.borderSide(), - right: right ?? RandomGenerator.borderSide(), top: top ?? RandomGenerator.borderSide(), + right: right ?? RandomGenerator.borderSide(), bottom: bottom ?? RandomGenerator.borderSide(), + left: left ?? RandomGenerator.borderSide(), ); } @@ -180,7 +150,7 @@ class RandomGenerator { }) { return BorderSide( color: color ?? RandomGenerator.color(), - width: width ?? Random().nextDouble() * 4, + width: width ?? (Random().nextDouble() * 4), style: style ?? BorderStyle.values.random(), ); } @@ -193,9 +163,9 @@ class RandomGenerator { }) { return BorderDirectional( top: top ?? RandomGenerator.borderSide(), - bottom: bottom ?? RandomGenerator.borderSide(), start: start ?? RandomGenerator.borderSide(), end: end ?? RandomGenerator.borderSide(), + bottom: bottom ?? RandomGenerator.borderSide(), ); } @@ -209,15 +179,11 @@ class RandomGenerator { ); } - static Shadow shadow({ - Color? color, - Offset? offset, - double? blurRadius, - }) { + static Shadow shadow({Color? color, Offset? offset, double? blurRadius}) { return Shadow( color: color ?? RandomGenerator.color(), offset: offset ?? const Offset(0, 0), - blurRadius: blurRadius ?? Random().nextDouble() * 4, + blurRadius: blurRadius ?? (Random().nextDouble() * 4), ); } @@ -236,8 +202,9 @@ class RandomGenerator { ]); } - static AlignmentDirectional alignmentDirectional( - [AlignmentDirectional? alignment]) { + static AlignmentDirectional alignmentDirectional([ + AlignmentDirectional? alignment, + ]) { return alignment ?? Random().randomElement([ AlignmentDirectional.center, @@ -261,23 +228,21 @@ class RandomGenerator { Gradient? gradient, }) { final boxShadowList = boxShadow ?? [RandomGenerator.boxShadow()]; + return BoxDecoration( color: color ?? RandomGenerator.color(), border: border ?? RandomGenerator.border(), borderRadius: borderRadius ?? RandomGenerator.borderRadius(), boxShadow: boxShadowList, - shape: shape ?? BoxShape.values.random(), gradient: gradient ?? RandomGenerator.linearGradient(), + shape: shape ?? BoxShape.values.random(), ); } - static Offset offset({ - double? dx, - double? dy, - }) { + static Offset offset({double? dx, double? dy}) { return Offset( - dx ?? Random().nextDouble() * 20, - dy ?? Random().nextDouble() * 20, + dx ?? (Random().nextDouble() * 20), + dy ?? (Random().nextDouble() * 20), ); } @@ -311,21 +276,47 @@ class RandomGenerator { ); } + TextOverflow textOverflow([TextOverflow? overflow]) { + return overflow ?? TextOverflow.values.random(); + } + + Axis axis([Axis? axis]) { + return axis ?? Random().randomElement(Axis.values); + } + + MainAxisAlignment mainAxisAlignment([MainAxisAlignment? alignment]) { + return alignment ?? MainAxisAlignment.values.random(); + } + + MainAxisSize mainAxisSize([MainAxisSize? size]) { + return size ?? MainAxisSize.values.random(); + } + + CrossAxisAlignment crossAxisAlignment([CrossAxisAlignment? alignment]) { + return alignment ?? CrossAxisAlignment.values.random(); + } + + TextBaseline textBaseline([TextBaseline? baseline]) { + return baseline ?? TextBaseline.values.random(); + } + + VerticalDirection verticalDirection([VerticalDirection? direction]) { + return direction ?? VerticalDirection.values.random(); + } + TextStyle textStyle() { final shadows = [ RandomGenerator.shadow(), RandomGenerator.shadow(), RandomGenerator.shadow(), ]; + return TextStyle( color: RandomGenerator.color(), backgroundColor: RandomGenerator.color(), - decorationColor: RandomGenerator.color(), - decorationStyle: TextDecorationStyle.values.random(), - fontFamily: 'Roboto', fontSize: Random().nextDoubleInRange(12, 32), - fontStyle: FontStyle.values.random(), fontWeight: FontWeight.values.random(), + fontStyle: FontStyle.values.random(), letterSpacing: Random().nextDoubleInRange(0, 2), wordSpacing: Random().nextDoubleInRange(0, 2), height: Random().nextDoubleInRange(0, 2), @@ -337,6 +328,9 @@ class RandomGenerator { TextDecoration.lineThrough, TextDecoration.overline, ].random(), + decorationColor: RandomGenerator.color(), + decorationStyle: TextDecorationStyle.values.random(), + fontFamily: 'Roboto', ); } } diff --git a/test/helpers/equatable_mixin_test.dart b/test/helpers/equatable_mixin_test.dart index 7f64de5ee..6c055c034 100644 --- a/test/helpers/equatable_mixin_test.dart +++ b/test/helpers/equatable_mixin_test.dart @@ -27,30 +27,21 @@ void main() { expect(instance.toString(), 'TestClass(1, A)'); }); - test('Should have correct equality', () { + test('Deep nested class Should have correct equality', () { final instance1 = DeepNestedClass(deepNestedMap, deepNestedList); final instance2 = DeepNestedClass(deepNestedMap, deepNestedList); final instance3 = DeepNestedClass( { - 'key1': { - 'innerKey1': 1, - 'innerKey2': 999, - }, + 'key1': {'innerKey1': 1, 'innerKey2': 999}, }, [ [ ['value1', 'value2'], - [ - 'value3', - 'value4', - ], + ['value3', 'value4'], ], [ ['value5', 'value6'], - [ - 'value7', - 'value8', - ], + ['value7', 'value8'], ], ], ); @@ -60,30 +51,21 @@ void main() { expect(instance2, isNot(instance3)); }); - test('Should have correct hashCode', () { + test('Deep nested class Should have correct hashCode', () { final instance1 = DeepNestedClass(deepNestedMap, deepNestedList); final instance2 = DeepNestedClass(deepNestedMap, deepNestedList); final instance3 = DeepNestedClass( { - 'key1': { - 'innerKey1': 1, - 'innerKey2': 999, - }, + 'key1': {'innerKey1': 1, 'innerKey2': 999}, }, [ [ ['value1', 'value2'], - [ - 'value3', - 'value4', - ], + ['value3', 'value4'], ], [ ['value5', 'value6'], - [ - 'value7', - 'value8', - ], + ['value7', 'value8'], ], ], ); @@ -92,7 +74,7 @@ void main() { expect(instance1.hashCode, isNot(instance3.hashCode)); }); - test('Should have correct toString', () { + test('Deep nested class Should have correct toString', () { final instance = DeepNestedClass(deepNestedMap, deepNestedList); expect( instance.toString(), @@ -126,14 +108,8 @@ class DeepNestedClass with Comparable { } Map> deepNestedMap = { - 'key1': { - 'innerKey1': 1, - 'innerKey2': 2, - }, - 'key2': { - 'innerKey3': 3, - 'innerKey4': 4, - }, + 'key1': {'innerKey1': 1, 'innerKey2': 2}, + 'key2': {'innerKey3': 3, 'innerKey4': 4}, }; List>> deepNestedList = [ diff --git a/test/helpers/string_ext_test.dart b/test/helpers/string_ext_test.dart index 825e491a9..e990b4644 100644 --- a/test/helpers/string_ext_test.dart +++ b/test/helpers/string_ext_test.dart @@ -23,7 +23,8 @@ void main() { '!@#\$%^&*()': ['!@#\$%^&*()'], // Special characters only 'Hello!World': [ 'Hello!', - 'World' + // ignore: unnecessary-trailing-comma + 'World', ], // Words separated by a non-standard separator }; diff --git a/test/helpers/testing_utils.dart b/test/helpers/testing_utils.dart index a9917dcac..643ce7238 100644 --- a/test/helpers/testing_utils.dart +++ b/test/helpers/testing_utils.dart @@ -11,19 +11,11 @@ export 'package:mix/src/core/extensions/values_ext.dart'; class MockBuildContext extends Mock implements BuildContext {} -MixData MockMixData( - Style style, -) { - return MixData.create( - MockBuildContext(), - style, - ); +MixData MockMixData(Style style) { + return MixData.create(MockBuildContext(), style); } -final EmptyMixData = MixData.create( - MockBuildContext(), - const Style.empty(), -); +final EmptyMixData = MixData.create(MockBuildContext(), const Style.empty()); MediaQuery createMediaQuery(Size size) { return MediaQuery( @@ -47,7 +39,6 @@ Widget createBrightnessTheme(Brightness brightness) { return MixTheme( data: MixThemeData(), child: MaterialApp( - theme: ThemeData(brightness: brightness), home: Scaffold( body: Builder( builder: (BuildContext context) { @@ -55,6 +46,7 @@ Widget createBrightnessTheme(Brightness brightness) { }, ), ), + theme: ThemeData(brightness: brightness), ), ); } @@ -77,9 +69,7 @@ Widget createDirectionality(TextDirection direction) { ); } -Widget createWithMixTheme( - MixThemeData theme, -) { +Widget createWithMixTheme(MixThemeData theme) { return MixTheme( data: theme, child: MaterialApp( @@ -98,7 +88,6 @@ extension WidgetTesterExt on WidgetTester { Future pumpWithMix( Widget widget, { Style style = const Style.empty(), - MixThemeData theme = const MixThemeData.empty(), }) async { await pumpWithMixTheme( Builder( @@ -119,12 +108,7 @@ extension WidgetTesterExt on WidgetTester { MixThemeData theme = const MixThemeData.empty(), }) async { await pumpWidget( - MaterialApp( - home: MixTheme( - data: theme, - child: widget, - ), - ), + MaterialApp(home: MixTheme(data: theme, child: widget)), ); } @@ -140,10 +124,10 @@ extension WidgetTesterExt on WidgetTester { MaterialApp( home: WidgetStateNotifier( data: data.copyWith( - state: state, - status: status, - hover: hover, focus: focus, + hover: hover, + status: status, + state: state, ), child: widget, ), @@ -152,11 +136,7 @@ extension WidgetTesterExt on WidgetTester { } Future pumpMaterialApp(Widget widget) async { - await pumpWidget( - MaterialApp( - home: widget, - ), - ); + await pumpWidget(MaterialApp(home: widget)); } Future pumpStyledWidget( @@ -164,28 +144,17 @@ extension WidgetTesterExt on WidgetTester { MixThemeData theme = const MixThemeData.empty(), }) async { await pumpWidget( - MaterialApp( - home: MixTheme( - data: theme, - child: widget, - ), - ), + MaterialApp(home: MixTheme(data: theme, child: widget)), ); } } // ignore: constant_identifier_names -const FillWidget = SizedBox( - height: 25, - width: 25, -); +const FillWidget = SizedBox(width: 25, height: 25); class WrapMixThemeWidget extends StatelessWidget { - const WrapMixThemeWidget({ - required this.child, - this.theme, - Key? key, - }) : super(key: key); + const WrapMixThemeWidget({required this.child, this.theme, Key? key}) + : super(key: key); final Widget child; final MixThemeData? theme; @@ -194,10 +163,7 @@ class WrapMixThemeWidget extends StatelessWidget { Widget build(BuildContext context) { return MixTheme( data: theme ?? MixThemeData(), - child: Directionality( - textDirection: TextDirection.ltr, - child: child, - ), + child: Directionality(textDirection: TextDirection.ltr, child: child), ); } } @@ -281,14 +247,6 @@ class UtilityTestDtoAttribute, V> class CustomWidgetDecorator extends WidgetDecorator { const CustomWidgetDecorator({super.key}); - @override - Widget build(mix, child) { - return Padding( - padding: const EdgeInsets.all(8.0), - child: child, - ); - } - @override CustomWidgetDecorator lerp(CustomWidgetDecorator? other, double t) { if (other == null) return this; @@ -298,6 +256,10 @@ class CustomWidgetDecorator extends WidgetDecorator { @override get props => []; + @override + Widget build(MixData mix, Widget child) { + return Padding(padding: const EdgeInsets.all(8.0), child: child); + } } class WidgetWithTestableBuild extends StyledWidget { @@ -309,6 +271,7 @@ class WidgetWithTestableBuild extends StyledWidget { Widget build(BuildContext context) { return withMix(context, (_) { onBuild(context); + return const SizedBox(); }); } diff --git a/test/src/attributes/border/border_dto_test.dart b/test/src/attributes/border/border_dto_test.dart index 81bed49ec..ddefed9eb 100644 --- a/test/src/attributes/border/border_dto_test.dart +++ b/test/src/attributes/border/border_dto_test.dart @@ -86,10 +86,10 @@ void main() { // merge test('merge() Border', () { const borderDto1 = BoxBorderDto( - top: BorderSideDto(width: 1.0, color: ColorDto(Colors.red)), - bottom: BorderSideDto(width: 1.0, color: ColorDto(Colors.red)), - left: BorderSideDto(width: 1.0, color: ColorDto(Colors.red)), - right: BorderSideDto(width: 1.0, color: ColorDto(Colors.red)), + top: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), + bottom: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), + left: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), + right: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), ); const borderDto2 = BoxBorderDto( @@ -119,15 +119,15 @@ void main() { group('BorderSideDto', () { test('should correctly merge with another BorderSideDto', () { const borderSideDto1 = BorderSideDto( - width: 1.0, color: ColorDto(Colors.red), style: BorderStyle.solid, + width: 1.0, ); const borderSideDto2 = BorderSideDto( - width: 2.0, color: ColorDto(Colors.blue), style: BorderStyle.solid, + width: 2.0, ); final merged = borderSideDto1.merge(borderSideDto2); @@ -140,14 +140,14 @@ void main() { // copywith test('copyWith should correctly copy the BorderSideDto', () { const borderSideDto = BorderSideDto( - width: 1.0, color: ColorDto(Colors.red), style: BorderStyle.solid, + width: 1.0, ); final copied = borderSideDto.copyWith( - width: 2.0, color: const ColorDto(Colors.blue), + width: 2.0, ); expect(copied.width, 2.0); @@ -158,8 +158,8 @@ void main() { // from test('from should correctly create a BorderSideDto from a BorderSide', () { const borderSide = BorderSide( - width: 1.0, color: Colors.red, + width: 1.0, style: BorderStyle.solid, ); @@ -171,19 +171,21 @@ void main() { }); // resolve - test('resolve should correctly create a BorderSide from a BorderSideDto', - () { - const borderSideDto = BorderSideDto( - width: 1.0, - color: ColorDto(Colors.red), - style: BorderStyle.solid, - ); - - final resolved = borderSideDto.resolve(EmptyMixData); - - expect(resolved.width, borderSideDto.width); - expect(resolved.color, borderSideDto.color?.resolve(EmptyMixData)); - expect(resolved.style, borderSideDto.style); - }); + test( + 'resolve should correctly create a BorderSide from a BorderSideDto', + () { + const borderSideDto = BorderSideDto( + color: ColorDto(Colors.red), + style: BorderStyle.solid, + width: 1.0, + ); + + final resolved = borderSideDto.resolve(EmptyMixData); + + expect(resolved.width, borderSideDto.width); + expect(resolved.color, borderSideDto.color?.resolve(EmptyMixData)); + expect(resolved.style, borderSideDto.style); + }, + ); }); } diff --git a/test/src/attributes/border/border_radius_dto_test.dart b/test/src/attributes/border/border_radius_dto_test.dart index ca01dc389..15f5b7a92 100644 --- a/test/src/attributes/border/border_radius_dto_test.dart +++ b/test/src/attributes/border/border_radius_dto_test.dart @@ -32,10 +32,10 @@ void main() { test('merge should combine two BorderRadiusGeometryDtos correctly', () { const borderRadius1 = BorderRadiusGeometryDto( - bottomLeft: Radius.circular(10), - bottomRight: Radius.circular(20), topLeft: Radius.circular(30), topRight: Radius.circular(40), + bottomLeft: Radius.circular(10), + bottomRight: Radius.circular(20), ); const borderRadius2 = BorderRadiusGeometryDto( topLeft: Radius.circular(20), @@ -126,10 +126,10 @@ void main() { test('merge should combine two BorderRadiusGeometryDtos correctly', () { const borderRadius1 = BorderRadiusGeometryDto( - bottomEnd: Radius.circular(10), - topEnd: Radius.circular(10), topStart: Radius.circular(10), + topEnd: Radius.circular(10), bottomStart: Radius.circular(10), + bottomEnd: Radius.circular(10), ); const borderRadius2 = BorderRadiusGeometryDto( topStart: Radius.circular(20), @@ -197,14 +197,20 @@ void main() { group('BorderSideDto', () { test('from constructor sets all values correctly', () { final attr = BorderSideDto( - color: Colors.red.toDto(), width: 1.0, style: BorderStyle.solid); + color: Colors.red.toDto(), + style: BorderStyle.solid, + width: 1.0, + ); expect(attr.color?.value, Colors.red); expect(attr.width, 1.0); expect(attr.style, BorderStyle.solid); }); test('resolve returns correct BorderSide', () { final attr = BorderSideDto( - color: Colors.red.toDto(), width: 1.0, style: BorderStyle.solid); + color: Colors.red.toDto(), + style: BorderStyle.solid, + width: 1.0, + ); final borderSide = attr.resolve(EmptyMixData); expect(borderSide.color, Colors.red); expect(borderSide.width, 1.0); @@ -212,16 +218,28 @@ void main() { }); test('Equality holds when all attributes are the same', () { final attr1 = BorderSideDto( - color: Colors.red.toDto(), width: 1.0, style: BorderStyle.solid); + color: Colors.red.toDto(), + style: BorderStyle.solid, + width: 1.0, + ); final attr2 = BorderSideDto( - color: Colors.red.toDto(), width: 1.0, style: BorderStyle.solid); + color: Colors.red.toDto(), + style: BorderStyle.solid, + width: 1.0, + ); expect(attr1, attr2); }); test('Equality fails when attributes are different', () { final attr1 = BorderSideDto( - color: Colors.red.toDto(), width: 1.0, style: BorderStyle.solid); + color: Colors.red.toDto(), + style: BorderStyle.solid, + width: 1.0, + ); final attr2 = BorderSideDto( - color: Colors.blue.toDto(), width: 1.0, style: BorderStyle.solid); + color: Colors.blue.toDto(), + style: BorderStyle.solid, + width: 1.0, + ); expect(attr1, isNot(attr2)); }); }); diff --git a/test/src/attributes/border/border_radius_util_test.dart b/test/src/attributes/border/border_radius_util_test.dart index 36f7834a5..8dc04016e 100644 --- a/test/src/attributes/border/border_radius_util_test.dart +++ b/test/src/attributes/border/border_radius_util_test.dart @@ -39,174 +39,185 @@ void main() { }); test( - 'vertical should return BorderRadiusAttribute with specified top and bottom radius', - () { - final resultTop = borderRadius.top.circular(10); - final resultBottom = borderRadius.bottom.circular(20); - expect(resultTop.value.topLeft, const Radius.circular(10)); - expect(resultTop.value.topRight, const Radius.circular(10)); - expect(resultBottom.value.bottomLeft, const Radius.circular(20)); - expect(resultBottom.value.bottomRight, const Radius.circular(20)); - }); + 'vertical should return BorderRadiusAttribute with specified top and bottom radius', + () { + final resultTop = borderRadius.top.circular(10); + final resultBottom = borderRadius.bottom.circular(20); + expect(resultTop.value.topLeft, const Radius.circular(10)); + expect(resultTop.value.topRight, const Radius.circular(10)); + expect(resultBottom.value.bottomLeft, const Radius.circular(20)); + expect(resultBottom.value.bottomRight, const Radius.circular(20)); + }, + ); test( - 'horizontal should return BorderRadiusAttribute with specified left and right radius', - () { - final resultLeft = borderRadius.left.circular(10); - final resultRight = borderRadius.right.circular(20); - expect(resultLeft.value.topLeft, const Radius.circular(10)); - expect(resultLeft.value.bottomLeft, const Radius.circular(10)); - expect(resultRight.value.topRight, const Radius.circular(20)); - expect(resultRight.value.bottomRight, const Radius.circular(20)); - }); + 'horizontal should return BorderRadiusAttribute with specified left and right radius', + () { + final resultLeft = borderRadius.left.circular(10); + final resultRight = borderRadius.right.circular(20); + expect(resultLeft.value.topLeft, const Radius.circular(10)); + expect(resultLeft.value.bottomLeft, const Radius.circular(10)); + expect(resultRight.value.topRight, const Radius.circular(20)); + expect(resultRight.value.bottomRight, const Radius.circular(20)); + }, + ); test( - 'positional should return BorderRadiusAttribute with specified positional radius', - () { - final result = borderRadius(10, 20, 30, 40); - expect(result.value.topLeft, const Radius.circular(10)); - expect(result.value.topRight, const Radius.circular(20)); - expect(result.value.bottomLeft, const Radius.circular(30)); - expect(result.value.bottomRight, const Radius.circular(40)); - }); + 'positional should return BorderRadiusAttribute with specified positional radius', + () { + final result = borderRadius(10, 20, 30, 40); + expect(result.value.topLeft, const Radius.circular(10)); + expect(result.value.topRight, const Radius.circular(20)); + expect(result.value.bottomLeft, const Radius.circular(30)); + expect(result.value.bottomRight, const Radius.circular(40)); + }, + ); - test('circular should return BorderRadiusAttribute with specified radius', - () { - final result = borderRadius(10); - expect(result.value.topLeft, const Radius.circular(10)); - expect(result.value.topRight, const Radius.circular(10)); - expect(result.value.bottomLeft, const Radius.circular(10)); - expect(result.value.bottomRight, const Radius.circular(10)); - }); + test( + 'circular should return BorderRadiusAttribute with specified radius', + () { + final result = borderRadius(10); + expect(result.value.topLeft, const Radius.circular(10)); + expect(result.value.topRight, const Radius.circular(10)); + expect(result.value.bottomLeft, const Radius.circular(10)); + expect(result.value.bottomRight, const Radius.circular(10)); + }, + ); // topLeft - test('topLeft should return BorderRadiusAttribute with specified radius', - () { - final result = borderRadius.topLeft.circular(10); - expect(result.value.topLeft, const Radius.circular(10)); - expect(result.value.topRight, isNull); - expect(result.value.bottomLeft, isNull); - expect(result.value.bottomRight, isNull); - }); + test( + 'topLeft should return BorderRadiusAttribute with specified radius', + () { + final result = borderRadius.topLeft.circular(10); + expect(result.value.topLeft, const Radius.circular(10)); + expect(result.value.topRight, isNull); + expect(result.value.bottomLeft, isNull); + expect(result.value.bottomRight, isNull); + }, + ); // topRight - test('topRight should return BorderRadiusAttribute with specified radius', - () { - final result = borderRadius.topRight.circular(10); - expect(result.value.topLeft, isNull); - expect(result.value.topRight, const Radius.circular(10)); - expect(result.value.bottomLeft, isNull); - expect(result.value.bottomRight, isNull); - }); + test( + 'topRight should return BorderRadiusAttribute with specified radius', + () { + final result = borderRadius.topRight.circular(10); + expect(result.value.topLeft, isNull); + expect(result.value.topRight, const Radius.circular(10)); + expect(result.value.bottomLeft, isNull); + expect(result.value.bottomRight, isNull); + }, + ); // bottomLeft - test('bottomLeft should return BorderRadiusAttribute with specified radius', - () { - final result = borderRadius.bottomLeft.circular(10); - expect(result.value.topLeft, isNull); - expect(result.value.topRight, isNull); - expect(result.value.bottomLeft, const Radius.circular(10)); - expect(result.value.bottomRight, isNull); - }); + test( + 'bottomLeft should return BorderRadiusAttribute with specified radius', + () { + final result = borderRadius.bottomLeft.circular(10); + expect(result.value.topLeft, isNull); + expect(result.value.topRight, isNull); + expect(result.value.bottomLeft, const Radius.circular(10)); + expect(result.value.bottomRight, isNull); + }, + ); // bottomRight test( - 'bottomRight should return BorderRadiusAttribute with specified radius', - () { - final result = borderRadius.bottomRight.circular(10); - expect(result.value.topLeft, isNull); - expect(result.value.topRight, isNull); - expect(result.value.bottomLeft, isNull); - expect(result.value.bottomRight, const Radius.circular(10)); - }); + 'bottomRight should return BorderRadiusAttribute with specified radius', + () { + final result = borderRadius.bottomRight.circular(10); + expect(result.value.topLeft, isNull); + expect(result.value.topRight, isNull); + expect(result.value.bottomLeft, isNull); + expect(result.value.bottomRight, const Radius.circular(10)); + }, + ); }); group('BorderRadiusDirectionalUtility', () { - test('zero should return BorderRadiusDirectionalAttribute with zero radius', - () { - final result = borderRadiusDirectional.zero(); - expect(result.value.topStart, Radius.zero); - expect(result.value.topEnd, Radius.zero); - expect(result.value.bottomStart, Radius.zero); - expect(result.value.bottomEnd, Radius.zero); - }); - test( - 'only should return BorderRadiusDirectionalAttribute with specified radius', - () { - final result = borderRadiusDirectional.only( - topStart: const Radius.circular(10), - topEnd: const Radius.circular(20), - bottomStart: const Radius.circular(30), - bottomEnd: const Radius.circular(40), - ); - expect(result.value.topStart, const Radius.circular(10)); - expect(result.value.topEnd, const Radius.circular(20)); - expect(result.value.bottomStart, const Radius.circular(30)); - expect(result.value.bottomEnd, const Radius.circular(40)); - }); + 'zero should return BorderRadiusDirectionalAttribute with zero radius', + () { + final result = borderRadiusDirectional.zero(); + expect(result.value.topStart, Radius.zero); + expect(result.value.topEnd, Radius.zero); + expect(result.value.bottomStart, Radius.zero); + expect(result.value.bottomEnd, Radius.zero); + }, + ); test( - 'all should return BorderRadiusDirectionalAttribute with specified radius', - () { - final result = borderRadiusDirectional.all.circular(10); - expect(result.value.topStart, const Radius.circular(10)); - expect(result.value.topEnd, const Radius.circular(10)); - expect(result.value.bottomStart, const Radius.circular(10)); - expect(result.value.bottomEnd, const Radius.circular(10)); - }); + 'only should return BorderRadiusDirectionalAttribute with specified radius', + () { + final result = borderRadiusDirectional.only( + topStart: const Radius.circular(10), + topEnd: const Radius.circular(20), + bottomStart: const Radius.circular(30), + bottomEnd: const Radius.circular(40), + ); + expect(result.value.topStart, const Radius.circular(10)); + expect(result.value.topEnd, const Radius.circular(20)); + expect(result.value.bottomStart, const Radius.circular(30)); + expect(result.value.bottomEnd, const Radius.circular(40)); + }, + ); - test('zero should return BorderRadiusDirectionalAttribute with zero radius', - () { - final result = borderRadiusDirectional.zero(); - expect(result.value.topStart, Radius.zero); - expect(result.value.topEnd, Radius.zero); - expect(result.value.bottomStart, Radius.zero); - expect(result.value.bottomEnd, Radius.zero); - }); + test( + 'all should return BorderRadiusDirectionalAttribute with specified radius', + () { + final result = borderRadiusDirectional.all.circular(10); + expect(result.value.topStart, const Radius.circular(10)); + expect(result.value.topEnd, const Radius.circular(10)); + expect(result.value.bottomStart, const Radius.circular(10)); + expect(result.value.bottomEnd, const Radius.circular(10)); + }, + ); // topStart test( - 'topStart should return BorderRadiusDirectionalAttribute with specified radius', - () { - final result = borderRadiusDirectional.topStart.circular(10); - expect(result.value.topStart, const Radius.circular(10)); - expect(result.value.topEnd, isNull); - expect(result.value.bottomStart, isNull); - expect(result.value.bottomEnd, isNull); - }); + 'topStart should return BorderRadiusDirectionalAttribute with specified radius', + () { + final result = borderRadiusDirectional.topStart.circular(10); + expect(result.value.topStart, const Radius.circular(10)); + expect(result.value.topEnd, isNull); + expect(result.value.bottomStart, isNull); + expect(result.value.bottomEnd, isNull); + }, + ); // topEnd test( - 'topEnd should return BorderRadiusDirectionalAttribute with specified radius', - () { - final result = borderRadiusDirectional.topEnd.circular(10); - expect(result.value.topStart, isNull); - expect(result.value.topEnd, const Radius.circular(10)); - expect(result.value.bottomStart, isNull); - expect(result.value.bottomEnd, isNull); - }); + 'topEnd should return BorderRadiusDirectionalAttribute with specified radius', + () { + final result = borderRadiusDirectional.topEnd.circular(10); + expect(result.value.topStart, isNull); + expect(result.value.topEnd, const Radius.circular(10)); + expect(result.value.bottomStart, isNull); + expect(result.value.bottomEnd, isNull); + }, + ); // bottomStart test( - 'bottomStart should return BorderRadiusDirectionalAttribute with specified radius', - () { - final result = borderRadiusDirectional.bottomStart.circular(10); - expect(result.value.topStart, isNull); - expect(result.value.topEnd, isNull); - expect(result.value.bottomStart, const Radius.circular(10)); - expect(result.value.bottomEnd, isNull); - }); + 'bottomStart should return BorderRadiusDirectionalAttribute with specified radius', + () { + final result = borderRadiusDirectional.bottomStart.circular(10); + expect(result.value.topStart, isNull); + expect(result.value.topEnd, isNull); + expect(result.value.bottomStart, const Radius.circular(10)); + expect(result.value.bottomEnd, isNull); + }, + ); // bottomEnd test( - 'bottomEnd should return BorderRadiusDirectionalAttribute with specified radius', - () { - final result = borderRadiusDirectional.bottomEnd.circular(10); - expect(result.value.topStart, isNull); - expect(result.value.topEnd, isNull); - expect(result.value.bottomStart, isNull); - expect(result.value.bottomEnd, const Radius.circular(10)); - }); + 'bottomEnd should return BorderRadiusDirectionalAttribute with specified radius', + () { + final result = borderRadiusDirectional.bottomEnd.circular(10); + expect(result.value.topStart, isNull); + expect(result.value.topEnd, isNull); + expect(result.value.bottomStart, isNull); + expect(result.value.bottomEnd, const Radius.circular(10)); + }, + ); }); } diff --git a/test/src/attributes/border/border_util_test.dart b/test/src/attributes/border/border_util_test.dart index 3e5508199..0bf031489 100644 --- a/test/src/attributes/border/border_util_test.dart +++ b/test/src/attributes/border/border_util_test.dart @@ -11,9 +11,9 @@ void main() { test('border.top()', () { final result = border.top( color: Colors.red, - width: 10.0, - style: BorderStyle.solid, strokeAlign: 0.5, + style: BorderStyle.solid, + width: 10.0, ); expect(result.value.top?.color?.value, Colors.red); @@ -38,9 +38,9 @@ void main() { test('border.bottom()', () { final result = border.bottom( color: Colors.red, - width: 10.0, - style: BorderStyle.solid, strokeAlign: 0.5, + style: BorderStyle.solid, + width: 10.0, ); expect(result.value.bottom?.color?.value, Colors.red); @@ -65,9 +65,9 @@ void main() { test('border.left()', () { final result = border.left( color: Colors.red, - width: 10.0, - style: BorderStyle.solid, strokeAlign: 0.5, + style: BorderStyle.solid, + width: 10.0, ); expect(result.value.left?.color?.value, Colors.red); expect(result.value.left?.width, 10.0); @@ -91,9 +91,9 @@ void main() { test('border.right()', () { final result = border.right( color: Colors.red, - width: 10.0, - style: BorderStyle.solid, strokeAlign: 0.5, + style: BorderStyle.solid, + width: 10.0, ); expect(result.value.right?.color?.value, Colors.red); expect(result.value.right?.width, 10.0); @@ -117,9 +117,9 @@ void main() { test('border.horizontal()', () { final result = border.horizontal( color: Colors.blue, - width: 5.0, - style: BorderStyle.solid, strokeAlign: 0.3, + style: BorderStyle.solid, + width: 5.0, ); expect(result.value.top?.color?.value, Colors.blue); expect(result.value.top?.width, 5.0); @@ -151,9 +151,9 @@ void main() { test('border.vertical()', () { final result = border.vertical( color: Colors.green, - width: 7.0, - style: BorderStyle.solid, strokeAlign: 0.2, + style: BorderStyle.solid, + width: 7.0, ); expect(result.value.left?.color?.value, Colors.green); expect(result.value.left?.width, 7.0); @@ -185,9 +185,9 @@ void main() { test('border.all()', () { final result = border.all( color: Colors.purple, - width: 3.0, - style: BorderStyle.solid, strokeAlign: 0.1, + style: BorderStyle.solid, + width: 3.0, ); expect(result.value.top?.color?.value, Colors.purple); expect(result.value.top?.width, 3.0); @@ -242,9 +242,9 @@ void main() { test('borderDirectional.top()', () { final result = borderDirectional.top( color: Colors.red, - width: 10.0, - style: BorderStyle.solid, strokeAlign: 0.5, + style: BorderStyle.solid, + width: 10.0, ); expect(result.value.top?.color?.value, Colors.red); @@ -269,9 +269,9 @@ void main() { test('borderDirectional.bottom()', () { final result = borderDirectional.bottom( color: Colors.red, - width: 10.0, - style: BorderStyle.solid, strokeAlign: 0.5, + style: BorderStyle.solid, + width: 10.0, ); expect(result.value.bottom?.color?.value, Colors.red); @@ -296,9 +296,9 @@ void main() { test('borderDirectional.start()', () { final result = borderDirectional.start( color: Colors.red, - width: 10.0, - style: BorderStyle.solid, strokeAlign: 0.5, + style: BorderStyle.solid, + width: 10.0, ); expect(result.value.start?.color?.value, Colors.red); expect(result.value.start?.width, 10.0); @@ -322,9 +322,9 @@ void main() { test('borderDirectional.end()', () { final result = borderDirectional.end( color: Colors.red, - width: 10.0, - style: BorderStyle.solid, strokeAlign: 0.5, + style: BorderStyle.solid, + width: 10.0, ); expect(result.value.end?.color?.value, Colors.red); expect(result.value.end?.width, 10.0); @@ -348,9 +348,9 @@ void main() { test('borderDirectional.horizontal()', () { final result = borderDirectional.horizontal( color: Colors.blue, - width: 5.0, - style: BorderStyle.solid, strokeAlign: 0.3, + style: BorderStyle.solid, + width: 5.0, ); expect(result.value.top?.color?.value, Colors.blue); expect(result.value.top?.width, 5.0); @@ -382,9 +382,9 @@ void main() { test('borderDirectional.vertical()', () { final result = borderDirectional.vertical( color: Colors.green, - width: 7.0, - style: BorderStyle.solid, strokeAlign: 0.2, + style: BorderStyle.solid, + width: 7.0, ); expect(result.value.start?.color?.value, Colors.green); expect(result.value.start?.width, 7.0); @@ -416,9 +416,9 @@ void main() { test('borderDirectional.all()', () { final result = borderDirectional.all( color: Colors.purple, - width: 3.0, - style: BorderStyle.solid, strokeAlign: 0.1, + style: BorderStyle.solid, + width: 3.0, ); expect(result.value.top?.color?.value, Colors.purple); expect(result.value.top?.width, 3.0); diff --git a/test/src/attributes/border/shape_border_dto_test.dart b/test/src/attributes/border/shape_border_dto_test.dart index bc116d811..ede6dcfff 100644 --- a/test/src/attributes/border/shape_border_dto_test.dart +++ b/test/src/attributes/border/shape_border_dto_test.dart @@ -10,25 +10,19 @@ void main() { test('merge should combine two RoundedRectangleBorderDtos correctly', () { const original = RoundedRectangleBorderDto( borderRadius: BorderRadiusGeometryDto( - bottomLeft: Radius.circular(5), - bottomRight: Radius.circular(10), topLeft: Radius.circular(15), topRight: Radius.circular(20), + bottomLeft: Radius.circular(5), + bottomRight: Radius.circular(10), ), - side: BorderSideDto( - color: ColorDto(Colors.red), - width: 1.0, - ), + side: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), ); final merged = original.merge( const RoundedRectangleBorderDto( borderRadius: BorderRadiusGeometryDto( topLeft: Radius.circular(25), ), - side: BorderSideDto( - color: ColorDto(Colors.blue), - width: 2.0, - ), + side: BorderSideDto(color: ColorDto(Colors.blue), width: 2.0), ), ) as RoundedRectangleBorderDto; @@ -42,52 +36,45 @@ void main() { }); test( - 'resolve should create a RoundedRectangleBorder with the correct values', - () { - const dto = RoundedRectangleBorderDto( - borderRadius: BorderRadiusGeometryDto( - bottomLeft: Radius.circular(5), - bottomRight: Radius.circular(10), - topLeft: Radius.circular(15), - topRight: Radius.circular(20), - ), - side: BorderSideDto( - color: ColorDto(Colors.red), - width: 1.0, - ), - ); + 'resolve should create a RoundedRectangleBorder with the correct values', + () { + const dto = RoundedRectangleBorderDto( + borderRadius: BorderRadiusGeometryDto( + topLeft: Radius.circular(15), + topRight: Radius.circular(20), + bottomLeft: Radius.circular(5), + bottomRight: Radius.circular(10), + ), + side: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), + ); - final roundedRectangleBorder = dto.resolve(EmptyMixData); + final roundedRectangleBorder = dto.resolve(EmptyMixData); - final borderRadius = roundedRectangleBorder.borderRadius as BorderRadius; + final borderRadius = + roundedRectangleBorder.borderRadius as BorderRadius; - expect(borderRadius.topLeft, const Radius.circular(15)); - expect(borderRadius.topRight, const Radius.circular(20)); - expect(borderRadius.bottomLeft, const Radius.circular(5)); - expect(borderRadius.bottomRight, const Radius.circular(10)); + expect(borderRadius.topLeft, const Radius.circular(15)); + expect(borderRadius.topRight, const Radius.circular(20)); + expect(borderRadius.bottomLeft, const Radius.circular(5)); + expect(borderRadius.bottomRight, const Radius.circular(10)); - expect(roundedRectangleBorder.side.color, Colors.red); - expect(roundedRectangleBorder.side.width, 1.0); - }); + expect(roundedRectangleBorder.side.color, Colors.red); + expect(roundedRectangleBorder.side.width, 1.0); + }, + ); }); // CircleBorderDto group('CircleBorderDto', () { test('merge should combine two CircleBorderDtos correctly', () { const original = CircleBorderDto( + side: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), eccentricity: 0.5, - side: BorderSideDto( - color: ColorDto(Colors.red), - width: 1.0, - ), ); final merged = original.merge( const CircleBorderDto( + side: BorderSideDto(color: ColorDto(Colors.blue), width: 2.0), eccentricity: 0.75, - side: BorderSideDto( - color: ColorDto(Colors.blue), - width: 2.0, - ), ), ) as CircleBorderDto; @@ -98,11 +85,8 @@ void main() { test('resolve should create a CircleBorder with the correct values', () { const dto = CircleBorderDto( + side: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), eccentricity: 0.5, - side: BorderSideDto( - color: ColorDto(Colors.red), - width: 1.0, - ), ); final circleBorder = dto.resolve(EmptyMixData); @@ -118,25 +102,19 @@ void main() { test('merge should combine two BeveledRectangleBorderDtos correctly', () { const original = BeveledRectangleBorderDto( borderRadius: BorderRadiusGeometryDto( - bottomLeft: Radius.circular(5), - bottomRight: Radius.circular(10), topLeft: Radius.circular(15), topRight: Radius.circular(20), + bottomLeft: Radius.circular(5), + bottomRight: Radius.circular(10), ), - side: BorderSideDto( - color: ColorDto(Colors.red), - width: 1.0, - ), + side: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), ); final merged = original.merge( const BeveledRectangleBorderDto( borderRadius: BorderRadiusGeometryDto( topLeft: Radius.circular(25), ), - side: BorderSideDto( - color: ColorDto(Colors.blue), - width: 2.0, - ), + side: BorderSideDto(color: ColorDto(Colors.blue), width: 2.0), ), ) as BeveledRectangleBorderDto; @@ -150,50 +128,43 @@ void main() { }); test( - 'resolve should create a BeveledRectangleBorder with the correct values', - () { - const dto = BeveledRectangleBorderDto( - borderRadius: BorderRadiusGeometryDto( - bottomLeft: Radius.circular(5), - bottomRight: Radius.circular(10), - topLeft: Radius.circular(15), - topRight: Radius.circular(20), - ), - side: BorderSideDto( - color: ColorDto(Colors.red), - width: 1.0, - ), - ); + 'resolve should create a BeveledRectangleBorder with the correct values', + () { + const dto = BeveledRectangleBorderDto( + borderRadius: BorderRadiusGeometryDto( + topLeft: Radius.circular(15), + topRight: Radius.circular(20), + bottomLeft: Radius.circular(5), + bottomRight: Radius.circular(10), + ), + side: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), + ); - final beveledRectangleBorder = dto.resolve(EmptyMixData); + final beveledRectangleBorder = dto.resolve(EmptyMixData); - final borderRadius = beveledRectangleBorder.borderRadius as BorderRadius; + final borderRadius = + beveledRectangleBorder.borderRadius as BorderRadius; - expect(borderRadius.topLeft, const Radius.circular(15)); - expect(borderRadius.topRight, const Radius.circular(20)); - expect(borderRadius.bottomLeft, const Radius.circular(5)); - expect(borderRadius.bottomRight, const Radius.circular(10)); + expect(borderRadius.topLeft, const Radius.circular(15)); + expect(borderRadius.topRight, const Radius.circular(20)); + expect(borderRadius.bottomLeft, const Radius.circular(5)); + expect(borderRadius.bottomRight, const Radius.circular(10)); - expect(beveledRectangleBorder.side.color, Colors.red); - expect(beveledRectangleBorder.side.width, 1.0); - }); + expect(beveledRectangleBorder.side.color, Colors.red); + expect(beveledRectangleBorder.side.width, 1.0); + }, + ); }); // StadiumBorderDto group('StadiumBorderDto', () { test('merge should combine two StadiumBorderDtos correctly', () { const original = StadiumBorderDto( - side: BorderSideDto( - color: ColorDto(Colors.red), - width: 1.0, - ), + side: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), ); final merged = original.merge( const StadiumBorderDto( - side: BorderSideDto( - color: ColorDto(Colors.blue), - width: 2.0, - ), + side: BorderSideDto(color: ColorDto(Colors.blue), width: 2.0), ), ) as StadiumBorderDto; @@ -203,10 +174,7 @@ void main() { test('resolve should create a StadiumBorder with the correct values', () { const dto = StadiumBorderDto( - side: BorderSideDto( - color: ColorDto(Colors.red), - width: 1.0, - ), + side: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), ); final stadiumBorder = dto.resolve(EmptyMixData); @@ -218,69 +186,63 @@ void main() { // ContinuousRectangleBorderDto group('ContinuousRectangleBorderDto', () { - test('merge should combine two ContinuousRectangleBorderDtos correctly', - () { - const original = ContinuousRectangleBorderDto( - borderRadius: BorderRadiusGeometryDto( - bottomLeft: Radius.circular(5), - bottomRight: Radius.circular(10), - topLeft: Radius.circular(15), - topRight: Radius.circular(20), - ), - side: BorderSideDto( - color: ColorDto(Colors.red), - width: 1.0, - ), - ); - final merged = original.merge( - const ContinuousRectangleBorderDto( + test( + 'merge should combine two ContinuousRectangleBorderDtos correctly', + () { + const original = ContinuousRectangleBorderDto( borderRadius: BorderRadiusGeometryDto( - topLeft: Radius.circular(25), + topLeft: Radius.circular(15), + topRight: Radius.circular(20), + bottomLeft: Radius.circular(5), + bottomRight: Radius.circular(10), ), - side: BorderSideDto( - color: ColorDto(Colors.blue), - width: 2.0, + side: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), + ); + final merged = original.merge( + const ContinuousRectangleBorderDto( + borderRadius: BorderRadiusGeometryDto( + topLeft: Radius.circular(25), + ), + side: BorderSideDto(color: ColorDto(Colors.blue), width: 2.0), ), - ), - ) as ContinuousRectangleBorderDto; + ) as ContinuousRectangleBorderDto; - expect(merged.borderRadius!.topLeft, const Radius.circular(25)); - expect(merged.borderRadius!.topRight, const Radius.circular(20)); - expect(merged.borderRadius!.bottomLeft, const Radius.circular(5)); - expect(merged.borderRadius!.bottomRight, const Radius.circular(10)); + expect(merged.borderRadius!.topLeft, const Radius.circular(25)); + expect(merged.borderRadius!.topRight, const Radius.circular(20)); + expect(merged.borderRadius!.bottomLeft, const Radius.circular(5)); + expect(merged.borderRadius!.bottomRight, const Radius.circular(10)); - expect(merged.side!.color, const ColorDto(Colors.blue)); - expect(merged.side!.width, 2.0); - }); + expect(merged.side!.color, const ColorDto(Colors.blue)); + expect(merged.side!.width, 2.0); + }, + ); test( - 'resolve should create a ContinuousRectangleBorder with the correct values', - () { - const dto = ContinuousRectangleBorderDto( - borderRadius: BorderRadiusGeometryDto( - bottomLeft: Radius.circular(5), - bottomRight: Radius.circular(10), - topLeft: Radius.circular(15), - topRight: Radius.circular(20), - ), - side: BorderSideDto( - color: ColorDto(Colors.red), - width: 1.0, - ), - ); + 'resolve should create a ContinuousRectangleBorder with the correct values', + () { + const dto = ContinuousRectangleBorderDto( + borderRadius: BorderRadiusGeometryDto( + topLeft: Radius.circular(15), + topRight: Radius.circular(20), + bottomLeft: Radius.circular(5), + bottomRight: Radius.circular(10), + ), + side: BorderSideDto(color: ColorDto(Colors.red), width: 1.0), + ); - final continuousRectangleBorder = dto.resolve(EmptyMixData); + final continuousRectangleBorder = dto.resolve(EmptyMixData); - final borderRadius = - continuousRectangleBorder.borderRadius as BorderRadius; + final borderRadius = + continuousRectangleBorder.borderRadius as BorderRadius; - expect(borderRadius.topLeft, const Radius.circular(15)); - expect(borderRadius.topRight, const Radius.circular(20)); - expect(borderRadius.bottomLeft, const Radius.circular(5)); - expect(borderRadius.bottomRight, const Radius.circular(10)); + expect(borderRadius.topLeft, const Radius.circular(15)); + expect(borderRadius.topRight, const Radius.circular(20)); + expect(borderRadius.bottomLeft, const Radius.circular(5)); + expect(borderRadius.bottomRight, const Radius.circular(10)); - expect(continuousRectangleBorder.side.color, Colors.red); - expect(continuousRectangleBorder.side.width, 1.0); - }); + expect(continuousRectangleBorder.side.color, Colors.red); + expect(continuousRectangleBorder.side.width, 1.0); + }, + ); }); } diff --git a/test/src/attributes/color/color_dto_test.dart b/test/src/attributes/color/color_dto_test.dart index 3a0c276ee..e8f2d797c 100644 --- a/test/src/attributes/color/color_dto_test.dart +++ b/test/src/attributes/color/color_dto_test.dart @@ -7,50 +7,45 @@ import '../../../helpers/testing_utils.dart'; void main() { group('ColorDto Tests', () { // Standard colors for basic testing - const colorList = [ - Colors.red, - Colors.green, - Colors.blue, - ]; + const colorList = [Colors.red, Colors.green, Colors.blue]; // Testing ColorDto.resolve with standard Colors for (var color in colorList) { test( - 'ColorDto.resolve should return the same color as provided for $color', - () { - final colorDto = ColorDto(color); - final resolvedValue = colorDto.resolve(EmptyMixData); - expect(resolvedValue, color); - }); + 'ColorDto.resolve should return the same color as provided for $color', + () { + final colorDto = ColorDto(color); + final resolvedValue = colorDto.resolve(EmptyMixData); + expect(resolvedValue, color); + }, + ); } // Testing ColorDto.resolve with ColorRef - testWidgets('ColorDto.resolve should resolve ColorRef correctly', - (tester) async { - const testColorToken = ColorToken('test'); - - await tester.pumpWithMixTheme( - Container(), - theme: MixThemeData( - colors: { - testColorToken: Colors.red, - }, - ), - ); + testWidgets( + 'ColorDto.resolve should resolve ColorRef correctly', + (tester) async { + const testColorToken = ColorToken('test'); - final buildContext = tester.element(find.byType(Container)); + await tester.pumpWithMixTheme( + Container(), + theme: MixThemeData(colors: {testColorToken: Colors.red}), + ); - final mockMixData = MixData.create(buildContext, Style()); + final buildContext = tester.element(find.byType(Container)); - final colorRef = testColorToken(); - final colorDto = ColorDto(colorRef); - final resolvedValue = colorDto.resolve(mockMixData); + final mockMixData = MixData.create(buildContext, Style()); - expect(colorRef, isA()); - expect(colorRef.token, testColorToken); - expect(resolvedValue, isA()); - expect(resolvedValue, Colors.red); - }); + final colorRef = testColorToken(); + final colorDto = ColorDto(colorRef); + final resolvedValue = colorDto.resolve(mockMixData); + + expect(colorRef, isA()); + expect(colorRef.token, testColorToken); + expect(resolvedValue, isA()); + expect(resolvedValue, Colors.red); + }, + ); // Testing maybeFrom method test('ColorDto.maybeFrom should handle null correctly', () { @@ -91,7 +86,9 @@ void main() { ); const colorDto3 = ColorDto.raw( - value: Colors.red, directives: [DarkenColorDirective(10)]); + value: Colors.red, + directives: [DarkenColorDirective(10)], + ); expect(colorDto1, colorDto2); expect(colorDto1, isNot(colorDto3)); diff --git a/test/src/attributes/color/color_util_test.dart b/test/src/attributes/color/color_util_test.dart index 20f367b58..c8324e186 100644 --- a/test/src/attributes/color/color_util_test.dart +++ b/test/src/attributes/color/color_util_test.dart @@ -43,10 +43,7 @@ void main() { final result = MockMixData(style); final value = result.resolvableOf()!; - expect( - value, - Colors.red.withOpacity(0.5), - ); + expect(value, Colors.red.withOpacity(0.5)); }); // withAlpha @@ -67,10 +64,7 @@ void main() { final result = MockMixData(style); final value = result.resolvableOf()!; - expect( - value, - Colors.red.withAlpha(50), - ); + expect(value, Colors.red.withAlpha(50)); }); // darken @@ -83,18 +77,12 @@ void main() { // darken resolves test('darken resolves the correct value', () { - final style = Style( - colorUtility(Colors.red), - colorUtility.darken(10), - ); + final style = Style(colorUtility(Colors.red), colorUtility.darken(10)); final result = MockMixData(style); final value = result.resolvableOf()!; - expect( - value, - Colors.red.darken(10), - ); + expect(value, Colors.red.darken(10)); }); // lighten @@ -115,10 +103,7 @@ void main() { final result = MockMixData(style); final value = result.resolvableOf()!; - expect( - value, - Colors.red.lighten(10), - ); + expect(value, Colors.red.lighten(10)); }); // saturate @@ -139,10 +124,7 @@ void main() { final result = MockMixData(style); final value = result.resolvableOf()!; - expect( - value, - Colors.red.saturate(10), - ); + expect(value, Colors.red.saturate(10)); }); // desaturate @@ -151,7 +133,9 @@ void main() { expect(attribute.value?.directives.length, 1); expect( - attribute.value?.directives.first, isA()); + attribute.value?.directives.first, + isA(), + ); }); // desaturate resolves @@ -164,10 +148,7 @@ void main() { final result = MockMixData(style); final value = result.resolvableOf()!; - expect( - value, - Colors.red.desaturate(10), - ); + expect(value, Colors.red.desaturate(10)); }); // tint @@ -180,17 +161,11 @@ void main() { // tint resolves test('tint resolves the correct value', () { - final style = Style( - colorUtility(Colors.red), - colorUtility.tint(10), - ); + final style = Style(colorUtility(Colors.red), colorUtility.tint(10)); final result = MockMixData(style); final value = result.resolvableOf()!; - expect( - value, - Colors.red.tint(10), - ); + expect(value, Colors.red.tint(10)); }); // shade @@ -203,18 +178,12 @@ void main() { // shade resolves test('shade resolves the correct value', () { - final style = Style( - colorUtility(Colors.red), - colorUtility.shade(10), - ); + final style = Style(colorUtility(Colors.red), colorUtility.shade(10)); final result = MockMixData(style); final value = result.resolvableOf()!; - expect( - value, - Colors.red.shade(10), - ); + expect(value, Colors.red.shade(10)); }); // brighten @@ -235,10 +204,7 @@ void main() { final result = MockMixData(style); final value = result.resolvableOf()!; - expect( - value, - Colors.red.brighten(10), - ); + expect(value, Colors.red.brighten(10)); }); // lighten and darken and opacity @@ -253,10 +219,7 @@ void main() { final result = MockMixData(style); final value = result.resolvableOf()!; - expect( - value, - Colors.red.lighten(10).darken(10).withOpacity(0.5), - ); + expect(value, Colors.red.lighten(10).darken(10).withOpacity(0.5)); }); }); } diff --git a/test/src/attributes/constraints/constraints_dto_test.dart b/test/src/attributes/constraints/constraints_dto_test.dart index c3e5635c5..cd83301f9 100644 --- a/test/src/attributes/constraints/constraints_dto_test.dart +++ b/test/src/attributes/constraints/constraints_dto_test.dart @@ -64,6 +64,7 @@ void main() { expect(resolved.maxWidth, double.infinity); expect(resolved.minHeight, 100); expect(resolved.maxHeight, double.infinity); + return const Placeholder(); }); test('Equality holds when all properties are the same', () { diff --git a/test/src/attributes/constraints/constraints_util_test.dart b/test/src/attributes/constraints/constraints_util_test.dart index bbb50bbeb..cd1492617 100644 --- a/test/src/attributes/constraints/constraints_util_test.dart +++ b/test/src/attributes/constraints/constraints_util_test.dart @@ -8,10 +8,10 @@ void main() { const boxConstraints = BoxConstraintsUtility(UtilityTestAttribute.new); test('boxConstraints()', () { final result = boxConstraints( - minWidth: 50.0, + maxHeight: 200.0, maxWidth: 150.0, minHeight: 100.0, - maxHeight: 200.0, + minWidth: 50.0, ); expect(result.value, isA()); diff --git a/test/src/attributes/decoration/decoration_dto_test.dart b/test/src/attributes/decoration/decoration_dto_test.dart index 3d3aa1207..660668b5d 100644 --- a/test/src/attributes/decoration/decoration_dto_test.dart +++ b/test/src/attributes/decoration/decoration_dto_test.dart @@ -8,9 +8,7 @@ import '../../../helpers/attribute_generator.dart'; import '../../../helpers/testing_utils.dart'; void main() { - const linearGradient = LinearGradient( - colors: Colors.accents, - ); + const linearGradient = LinearGradient(colors: Colors.accents); final linearGradientDto = LinearGradientDto( colors: Colors.accents.map(ColorDto.new).toList(), @@ -29,14 +27,18 @@ void main() { const attr = BoxDecorationDto(); final decoration = attr.resolve(EmptyMixData); expect(decoration, const BoxDecoration()); + return const Placeholder(); }); test('resolve returns correct BoxDecoration with specific values', () { final attr = BoxDecorationDto( - color: Colors.red.toDto(), gradient: linearGradientDto); + color: Colors.red.toDto(), + gradient: linearGradientDto, + ); final decoration = attr.resolve(EmptyMixData); expect(decoration.color, Colors.red); expect(decoration.gradient, linearGradient); + return const Placeholder(); }); test('Equality holds when all properties are the same', () { @@ -70,8 +72,8 @@ void main() { final boxShadow = RandomGenerator.boxShadow(); final decoration1 = ShapeDecorationDto( - gradient: linearGradientDto, shape: const CircleBorderDto(), + gradient: linearGradientDto, shadows: [boxShadow.toDto()], ); @@ -101,9 +103,11 @@ void main() { group('DecorationDto Merge Tests', () { const linearGradientDto = LinearGradientDto( - colors: [ColorDto(Colors.red), ColorDto(Colors.blue)]); + colors: [ColorDto(Colors.red), ColorDto(Colors.blue)], + ); const otherLinearGradientDto = LinearGradientDto( - colors: [ColorDto(Colors.yellow), ColorDto(Colors.green)]); + colors: [ColorDto(Colors.yellow), ColorDto(Colors.green)], + ); const boxShadowDto = BoxShadowDto( color: ColorDto(Colors.black), @@ -112,10 +116,11 @@ void main() { spreadRadius: 5.0, ); const otherBoxShadowDto = BoxShadowDto( - color: ColorDto(Colors.black), - offset: Offset(2, 2), - blurRadius: 10.0, - spreadRadius: 10.0); + color: ColorDto(Colors.black), + offset: Offset(2, 2), + blurRadius: 10.0, + spreadRadius: 10.0, + ); test('BoxDecorationDto merges with another BoxDecorationDto', () { const boxDeco1 = BoxDecorationDto( color: ColorDto(Colors.red), @@ -140,15 +145,15 @@ void main() { test('ShapeDecorationDto merges with another ShapeDecorationDto', () { const shapeDeco1 = ShapeDecorationDto( color: ColorDto(Colors.red), + shape: RoundedRectangleBorderDto(), gradient: linearGradientDto, shadows: [boxShadowDto], - shape: RoundedRectangleBorderDto(), ); const shapeDeco2 = ShapeDecorationDto( color: ColorDto(Colors.blue), + shape: BeveledRectangleBorderDto(), gradient: otherLinearGradientDto, shadows: [otherBoxShadowDto], - shape: BeveledRectangleBorderDto(), ); final merged = shapeDeco1.merge(shapeDeco2) as ShapeDecorationDto; @@ -207,10 +212,10 @@ void main() { test('ShapeDecorationDto cannot merge with BoxDecoration', () { const shapeDeco = ShapeDecorationDto( color: ColorDto(Colors.red), - gradient: linearGradientDto, - shadows: [boxShadowDto], // Cannot merge because it has shape shape: RoundedRectangleBorderDto(), + gradient: linearGradientDto, + shadows: [boxShadowDto], ); const boxDeco = BoxDecorationDto( diff --git a/test/src/attributes/decoration/decoration_util_test.dart b/test/src/attributes/decoration/decoration_util_test.dart index c1b3592cb..ce3647671 100644 --- a/test/src/attributes/decoration/decoration_util_test.dart +++ b/test/src/attributes/decoration/decoration_util_test.dart @@ -48,15 +48,23 @@ void main() { expect(result.value.gradient, isA()); expect(result.value.shape, isA()); - expect(result.value.border, - equals(BoxBorderDto.from(refBoxDecoration.border!))); - expect(result.value.borderRadius, - equals(BorderRadiusGeometryDto.from(refBoxDecoration.borderRadius!))); - expect(result.value.boxShadow, - equals(refBoxDecoration.boxShadow?.map((e) => BoxShadowDto.from(e)))); + expect( + result.value.border, + equals(BoxBorderDto.from(refBoxDecoration.border!)), + ); + expect( + result.value.borderRadius, + equals(BorderRadiusGeometryDto.from(refBoxDecoration.borderRadius!)), + ); + expect( + result.value.boxShadow, + equals(refBoxDecoration.boxShadow?.map((e) => BoxShadowDto.from(e))), + ); expect(result.value.color, equals(ColorDto(refBoxDecoration.color!))); - expect(result.value.gradient, - equals(GradientDto.from(refBoxDecoration.gradient!))); + expect( + result.value.gradient, + equals(GradientDto.from(refBoxDecoration.gradient!)), + ); expect(result.value.shape, equals(refBoxDecoration.shape)); }); test('color setting', () { @@ -72,14 +80,18 @@ void main() { test('border setting', () { final result = boxDecoration.border.all(color: Colors.red, width: 2.0); - expect(result.value.border?.resolve(EmptyMixData), - equals(Border.all(color: Colors.red, width: 2.0))); + expect( + result.value.border?.resolve(EmptyMixData), + equals(Border.all(color: Colors.red, width: 2.0)), + ); }); test('borderRadius setting', () { final result = boxDecoration.borderRadius(10.0); - expect(result.value.borderRadius?.resolve(EmptyMixData), - equals(BorderRadius.circular(10.0))); + expect( + result.value.borderRadius?.resolve(EmptyMixData), + equals(BorderRadius.circular(10.0)), + ); }); test('gradient setting', () { @@ -95,16 +107,16 @@ void main() { test('boxShadow setting', () { const boxShadow = BoxShadow( color: Colors.black, - blurRadius: 10.0, offset: Offset(5.0, 5.0), + blurRadius: 10.0, spreadRadius: 2.0, ); final result = boxDecoration.boxShadows([boxShadow]); final resultSingle = boxDecoration.boxShadow( - color: Colors.black, blurRadius: 10.0, + color: Colors.black, offset: const Offset(5.0, 5.0), spreadRadius: 2.0, ); @@ -125,8 +137,8 @@ void main() { const shapeDecoration = ShapeDecorationUtility(UtilityTestAttribute.new); const boxShadow = BoxShadow( color: Colors.black, - blurRadius: 10.0, offset: Offset(5.0, 5.0), + blurRadius: 10.0, ); const linearGradient = LinearGradient( @@ -145,15 +157,13 @@ void main() { expect(result.value.color, equals(Colors.blue.toDto())); expect( - result.value.gradient, - equals(GradientDto.from( - linearGradient, - ))); + result.value.gradient, + equals(GradientDto.from(linearGradient)), + ); expect( - result.value.shadows, - equals( - const [boxShadow].map((e) => BoxShadowDto.from(e)).toList(), - )); + result.value.shadows, + equals(const [boxShadow].map((e) => BoxShadowDto.from(e)).toList()), + ); }); // color() @@ -168,10 +178,9 @@ void main() { final result = shapeDecoration.gradient.as(linearGradient); expect( - result.value.gradient, - equals(GradientDto.from( - linearGradient, - ))); + result.value.gradient, + equals(GradientDto.from(linearGradient)), + ); }); // shadows() @@ -179,10 +188,9 @@ void main() { final result = shapeDecoration.shadows([boxShadow]); expect( - result.value.shadows, - equals( - const [boxShadow].map((e) => BoxShadowDto.from(e)).toList(), - )); + result.value.shadows, + equals(const [boxShadow].map((e) => BoxShadowDto.from(e)).toList()), + ); }); // shape() diff --git a/test/src/attributes/decoration/image/decoration_image_dto_test.dart b/test/src/attributes/decoration/image/decoration_image_dto_test.dart index f0f026364..e335abb07 100644 --- a/test/src/attributes/decoration/image/decoration_image_dto_test.dart +++ b/test/src/attributes/decoration/image/decoration_image_dto_test.dart @@ -57,7 +57,9 @@ void main() { expect(mergedDto.fit, equals(BoxFit.fill)); expect(mergedDto.alignment, equals(Alignment.bottomRight)); expect( - mergedDto.centerSlice, equals(const Rect.fromLTRB(50, 60, 70, 80))); + mergedDto.centerSlice, + equals(const Rect.fromLTRB(50, 60, 70, 80)), + ); expect(mergedDto.repeat, equals(ImageRepeat.repeatX)); expect(mergedDto.filterQuality, equals(FilterQuality.low)); expect(mergedDto.invertColors, equals(false)); diff --git a/test/src/attributes/gradient/gradient_dto_test.dart b/test/src/attributes/gradient/gradient_dto_test.dart index 3726a84d9..7cc383841 100644 --- a/test/src/attributes/gradient/gradient_dto_test.dart +++ b/test/src/attributes/gradient/gradient_dto_test.dart @@ -56,9 +56,9 @@ void main() { const gradientDto = LinearGradientDto( begin: Alignment.topLeft, end: Alignment.bottomRight, + tileMode: TileMode.clamp, colors: [ColorDto(Colors.red), ColorDto(Colors.blue)], stops: [0.0, 1.0], - tileMode: TileMode.clamp, ); expect(gradientDto.begin, Alignment.topLeft); @@ -68,21 +68,23 @@ void main() { expect(gradientDto.tileMode, TileMode.clamp); }); - test('from method correctly converts LinearGradient to LinearGradientDto', - () { - const linearGradient = LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [Colors.red, Colors.blue], - stops: [0.0, 1.0], - ); - final gradientDto = LinearGradientDto.from(linearGradient); - - expect(gradientDto.begin, linearGradient.begin); - expect(gradientDto.end, linearGradient.end); - expect(gradientDto.colors?.length, linearGradient.colors.length); - expect(gradientDto.stops, linearGradient.stops); - }); + test( + 'from method correctly converts LinearGradient to LinearGradientDto', + () { + const linearGradient = LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [Colors.red, Colors.blue], + stops: [0.0, 1.0], + ); + final gradientDto = LinearGradientDto.from(linearGradient); + + expect(gradientDto.begin, linearGradient.begin); + expect(gradientDto.end, linearGradient.end); + expect(gradientDto.colors?.length, linearGradient.colors.length); + expect(gradientDto.stops, linearGradient.stops); + }, + ); test('resolve method returns correct LinearGradient', () { const gradientDto = LinearGradientDto( @@ -162,9 +164,9 @@ void main() { const gradientDto = RadialGradientDto( center: Alignment.center, radius: 0.5, + tileMode: TileMode.clamp, colors: [ColorDto(Colors.red), ColorDto(Colors.blue)], stops: [0.0, 1.0], - tileMode: TileMode.clamp, ); expect(gradientDto.center, Alignment.center); @@ -174,21 +176,23 @@ void main() { expect(gradientDto.tileMode, TileMode.clamp); }); - test('from method correctly converts RadialGradient to RadialGradientDto', - () { - const radialGradient = RadialGradient( - center: Alignment.center, - radius: 0.5, - colors: [Colors.red, Colors.blue], - stops: [0.0, 1.0], - ); - final gradientDto = RadialGradientDto.from(radialGradient); - - expect(gradientDto.center, radialGradient.center); - expect(gradientDto.radius, radialGradient.radius); - expect(gradientDto.colors?.length, radialGradient.colors.length); - expect(gradientDto.stops, radialGradient.stops); - }); + test( + 'from method correctly converts RadialGradient to RadialGradientDto', + () { + const radialGradient = RadialGradient( + center: Alignment.center, + radius: 0.5, + colors: [Colors.red, Colors.blue], + stops: [0.0, 1.0], + ); + final gradientDto = RadialGradientDto.from(radialGradient); + + expect(gradientDto.center, radialGradient.center); + expect(gradientDto.radius, radialGradient.radius); + expect(gradientDto.colors?.length, radialGradient.colors.length); + expect(gradientDto.stops, radialGradient.stops); + }, + ); test('resolve method returns correct RadialGradient', () { const gradientDto = RadialGradientDto( @@ -269,9 +273,9 @@ void main() { center: Alignment.center, startAngle: 0.0, endAngle: 1.0, + tileMode: TileMode.clamp, colors: [ColorDto(Colors.red), ColorDto(Colors.blue)], stops: [0.0, 1.0], - tileMode: TileMode.clamp, ); expect(gradientDto.center, Alignment.center); expect(gradientDto.startAngle, 0.0); @@ -281,23 +285,25 @@ void main() { expect(gradientDto.tileMode, TileMode.clamp); }); - test('from method correctly converts SweepGradient to SweepGradientDto', - () { - const sweepGradient = SweepGradient( - center: Alignment.center, - startAngle: 0.0, - endAngle: 1.0, - colors: [Colors.red, Colors.blue], - stops: [0.0, 1.0], - ); - final gradientDto = SweepGradientDto.from(sweepGradient); - - expect(gradientDto.center, sweepGradient.center); - expect(gradientDto.startAngle, sweepGradient.startAngle); - expect(gradientDto.endAngle, sweepGradient.endAngle); - expect(gradientDto.colors?.length, sweepGradient.colors.length); - expect(gradientDto.stops, sweepGradient.stops); - }); + test( + 'from method correctly converts SweepGradient to SweepGradientDto', + () { + const sweepGradient = SweepGradient( + center: Alignment.center, + startAngle: 0.0, + endAngle: 1.0, + colors: [Colors.red, Colors.blue], + stops: [0.0, 1.0], + ); + final gradientDto = SweepGradientDto.from(sweepGradient); + + expect(gradientDto.center, sweepGradient.center); + expect(gradientDto.startAngle, sweepGradient.startAngle); + expect(gradientDto.endAngle, sweepGradient.endAngle); + expect(gradientDto.colors?.length, sweepGradient.colors.length); + expect(gradientDto.stops, sweepGradient.stops); + }, + ); test('resolve method returns correct SweepGradient', () { const gradientDto = SweepGradientDto( diff --git a/test/src/attributes/gradient/gradient_util_test.dart b/test/src/attributes/gradient/gradient_util_test.dart index b027c3430..01f117b74 100644 --- a/test/src/attributes/gradient/gradient_util_test.dart +++ b/test/src/attributes/gradient/gradient_util_test.dart @@ -56,12 +56,12 @@ void main() { const transform = GradientRotation(0.0); final attribute = radialUtility( - colors: colors, - stops: stops, center: center, - radius: radius, + colors: colors, focal: focal, focalRadius: focalRadius, + radius: radius, + stops: stops, tileMode: tileMode, transform: transform, ); @@ -193,12 +193,12 @@ void main() { const transform = GradientRotation(0.0); final attribute = radialUtility( - colors: colors, - stops: stops, center: center, - radius: radius, + colors: colors, focal: focal, focalRadius: focalRadius, + radius: radius, + stops: stops, tileMode: tileMode, transform: transform, ); @@ -252,10 +252,10 @@ void main() { const transform = GradientRotation(0.0); final attribute = linearUtility( - colors: colors, - stops: stops, begin: begin, + colors: colors, end: end, + stops: stops, tileMode: tileMode, transform: transform, ); @@ -359,10 +359,10 @@ void main() { const transform = GradientRotation(0.0); final attribute = linearUtility( - colors: colors, - stops: stops, begin: begin, + colors: colors, end: end, + stops: stops, tileMode: tileMode, transform: transform, ); @@ -410,11 +410,11 @@ void main() { const transform = GradientRotation(0.0); final attribute = sweepUtility( - colors: colors, - stops: stops, center: center, - startAngle: startAngle, + colors: colors, endAngle: endAngle, + startAngle: startAngle, + stops: stops, tileMode: tileMode, transform: transform, ); @@ -524,11 +524,11 @@ void main() { const transform = GradientRotation(0.0); final attribute = sweepUtility( - colors: colors, - stops: stops, center: center, - startAngle: startAngle, + colors: colors, endAngle: endAngle, + startAngle: startAngle, + stops: stops, tileMode: tileMode, transform: transform, ); diff --git a/test/src/attributes/nested_style/nested_style_attribute_test.dart b/test/src/attributes/nested_style/nested_style_attribute_test.dart index d32cf4fac..8e0110838 100644 --- a/test/src/attributes/nested_style/nested_style_attribute_test.dart +++ b/test/src/attributes/nested_style/nested_style_attribute_test.dart @@ -34,25 +34,27 @@ void main() { expect(mergedAttribute, same(attribute)); }); - test('should return a new object with merged values if other is not null', - () { - // Arrange - final styleMix1 = Style( - const MockDoubleScalarAttribute(1.0), - const MockIntScalarAttribute(2), - ); - final styleMix2 = Style(const MockDoubleScalarAttribute(2.0)); - - final attribute1 = NestedStyleAttribute(styleMix1); - final attribute2 = NestedStyleAttribute(styleMix2); - - // Act - final mergedAttribute = attribute1.merge(attribute2); - - // Assert - expect(mergedAttribute, isNot(same(attribute1))); - expect(mergedAttribute.value, equals(styleMix1.merge(styleMix2))); - }); + test( + 'should return a new object with merged values if other is not null', + () { + // Arrange + final styleMix1 = Style( + const MockDoubleScalarAttribute(1.0), + const MockIntScalarAttribute(2), + ); + final styleMix2 = Style(const MockDoubleScalarAttribute(2.0)); + + final attribute1 = NestedStyleAttribute(styleMix1); + final attribute2 = NestedStyleAttribute(styleMix2); + + // Act + final mergedAttribute = attribute1.merge(attribute2); + + // Assert + expect(mergedAttribute, isNot(same(attribute1))); + expect(mergedAttribute.value, equals(styleMix1.merge(styleMix2))); + }, + ); }); test('props should return a list containing the value', () { diff --git a/test/src/attributes/nested_style/style_mix_attribute_test.dart b/test/src/attributes/nested_style/style_mix_attribute_test.dart index d32cf4fac..8e0110838 100644 --- a/test/src/attributes/nested_style/style_mix_attribute_test.dart +++ b/test/src/attributes/nested_style/style_mix_attribute_test.dart @@ -34,25 +34,27 @@ void main() { expect(mergedAttribute, same(attribute)); }); - test('should return a new object with merged values if other is not null', - () { - // Arrange - final styleMix1 = Style( - const MockDoubleScalarAttribute(1.0), - const MockIntScalarAttribute(2), - ); - final styleMix2 = Style(const MockDoubleScalarAttribute(2.0)); - - final attribute1 = NestedStyleAttribute(styleMix1); - final attribute2 = NestedStyleAttribute(styleMix2); - - // Act - final mergedAttribute = attribute1.merge(attribute2); - - // Assert - expect(mergedAttribute, isNot(same(attribute1))); - expect(mergedAttribute.value, equals(styleMix1.merge(styleMix2))); - }); + test( + 'should return a new object with merged values if other is not null', + () { + // Arrange + final styleMix1 = Style( + const MockDoubleScalarAttribute(1.0), + const MockIntScalarAttribute(2), + ); + final styleMix2 = Style(const MockDoubleScalarAttribute(2.0)); + + final attribute1 = NestedStyleAttribute(styleMix1); + final attribute2 = NestedStyleAttribute(styleMix2); + + // Act + final mergedAttribute = attribute1.merge(attribute2); + + // Assert + expect(mergedAttribute, isNot(same(attribute1))); + expect(mergedAttribute.value, equals(styleMix1.merge(styleMix2))); + }, + ); }); test('props should return a list containing the value', () { diff --git a/test/src/attributes/scalars/scalar_util_test.dart b/test/src/attributes/scalars/scalar_util_test.dart index 030bdb04e..0678698df 100644 --- a/test/src/attributes/scalars/scalar_util_test.dart +++ b/test/src/attributes/scalars/scalar_util_test.dart @@ -30,7 +30,9 @@ void main() { expect(utility.hardEdge().value, Clip.hardEdge); expect(utility.antiAlias().value, Clip.antiAlias); expect( - utility.antiAliasWithSaveLayer().value, Clip.antiAliasWithSaveLayer); + utility.antiAliasWithSaveLayer().value, + Clip.antiAliasWithSaveLayer, + ); }); }); @@ -179,11 +181,13 @@ void main() { // only test('only() returns correct instance', () { final alignment = utility.only(x: 10, y: 8); - final alignmnetDirectional = utility.only(start: 10, y: 8); + final alignmnetDirectional = utility.only(y: 8, start: 10); expect(alignment.value, equals(const Alignment(10, 8))); - expect(alignmnetDirectional.value, - equals(const AlignmentDirectional(10, 8))); + expect( + alignmnetDirectional.value, + equals(const AlignmentDirectional(10, 8)), + ); expect(() => utility.only(x: 10, start: 8), throwsAssertionError); }); @@ -244,8 +248,10 @@ void main() { final shapeBorder = utility.roundedRectangle.borderRadius(20); expect(shapeBorder.value, isA()); - expect((shapeBorder.value as RoundedRectangleBorderDto).borderRadius, - BorderRadius.circular(20).toDto()); + expect( + (shapeBorder.value as RoundedRectangleBorderDto).borderRadius, + BorderRadius.circular(20).toDto(), + ); }); // beveled() @@ -343,8 +349,10 @@ void main() { test('translation', () { expect(utility.translationValues(20, 20, 20).value, isA()); - expect(utility.translationValues(20, 20, 20).value, - Matrix4.translationValues(20, 20, 20)); + expect( + utility.translationValues(20, 20, 20).value, + Matrix4.translationValues(20, 20, 20), + ); }); }); diff --git a/test/src/attributes/shadow/shadow_dto_test.dart b/test/src/attributes/shadow/shadow_dto_test.dart index 10e52f80b..636a799c6 100644 --- a/test/src/attributes/shadow/shadow_dto_test.dart +++ b/test/src/attributes/shadow/shadow_dto_test.dart @@ -22,9 +22,9 @@ void main() { test('from() creates correct instance', () { const shadow = Shadow( - blurRadius: 10.0, color: Colors.blue, offset: Offset(10, 10), + blurRadius: 10.0, ); final shadowDto = ShadowDto.from(shadow); @@ -36,9 +36,9 @@ void main() { test('maybeFrom() creates correct instance', () { const shadow = Shadow( - blurRadius: 10.0, color: Colors.blue, offset: Offset(10, 10), + blurRadius: 10.0, ); final shadowDto = ShadowDto.maybeFrom(shadow); @@ -86,9 +86,9 @@ void main() { group('BoxShadowDto', () { test('Constructor assigns correct properties', () { const boxShadowDto = BoxShadowDto( - blurRadius: 10.0, color: ColorDto(Colors.blue), offset: Offset(10, 10), + blurRadius: 10.0, spreadRadius: 5.0, ); @@ -100,9 +100,9 @@ void main() { test('from() creates correct instance', () { const boxShadow = BoxShadow( - blurRadius: 10.0, color: Colors.blue, offset: Offset(10, 10), + blurRadius: 10.0, spreadRadius: 5.0, ); @@ -116,9 +116,9 @@ void main() { test('maybeFrom() creates correct instance', () { const boxShadow = BoxShadow( - blurRadius: 10.0, color: Colors.blue, offset: Offset(10, 10), + blurRadius: 10.0, spreadRadius: 5.0, ); @@ -132,9 +132,9 @@ void main() { test('resolve() returns correct instance', () { const boxShadowDto = BoxShadowDto( - blurRadius: 10.0, color: ColorDto(Colors.blue), offset: Offset(10, 10), + blurRadius: 10.0, spreadRadius: 5.0, ); @@ -148,17 +148,17 @@ void main() { test('merge() returns correct instance', () { const boxShadowDto = BoxShadowDto( - blurRadius: 10.0, color: ColorDto(Colors.blue), offset: Offset(10, 10), + blurRadius: 10.0, spreadRadius: 5.0, ); final mergedBoxShadowDto = boxShadowDto.merge( const BoxShadowDto( - blurRadius: 20.0, color: ColorDto(Colors.red), offset: Offset(20, 20), + blurRadius: 20.0, spreadRadius: 10.0, ), ); diff --git a/test/src/attributes/spacing/spacing_dto_test.dart b/test/src/attributes/spacing/spacing_dto_test.dart index b030943b6..602a2350b 100644 --- a/test/src/attributes/spacing/spacing_dto_test.dart +++ b/test/src/attributes/spacing/spacing_dto_test.dart @@ -16,12 +16,7 @@ void main() { expect( spacingDto.resolve(EmptyMixData), - const EdgeInsets.only( - left: 30, - top: 10, - right: 40, - bottom: 20, - ), + const EdgeInsets.only(left: 30, top: 10, right: 40, bottom: 20), ); }); @@ -41,12 +36,7 @@ void main() { final mergedSpacingDto = spacingDto1.merge(spacingDto2); expect( mergedSpacingDto, - const SpacingDto.only( - top: 5, - bottom: 15, - left: 25, - right: 35, - ), + const SpacingDto.only(top: 5, bottom: 15, left: 25, right: 35), ); }); }); diff --git a/test/src/attributes/spacing/spacing_util_test.dart b/test/src/attributes/spacing/spacing_util_test.dart index 3e7576c58..195d3bc1e 100644 --- a/test/src/attributes/spacing/spacing_util_test.dart +++ b/test/src/attributes/spacing/spacing_util_test.dart @@ -29,7 +29,7 @@ void main() { test('spacingUtils.directional()', () { expect( spacingUtils.directional(10).value, - const SpacingDto.only(start: 10, end: 10, top: 10, bottom: 10), + const SpacingDto.only(top: 10, bottom: 10, start: 10, end: 10), reason: '1', ); expect( @@ -44,107 +44,73 @@ void main() { ); expect( spacingUtils.directional(10, 20, 30, 40).value, - const SpacingDto.only(top: 10, end: 20, bottom: 30, start: 40), + const SpacingDto.only(top: 10, bottom: 30, start: 40, end: 20), reason: '4', ); }); test('spacingUtils.from', () { expect( - spacingUtils - .as( - const EdgeInsets.all(10), - ) - .value, + spacingUtils.as(const EdgeInsets.all(10)).value, const SpacingDto.only(top: 10, bottom: 10, left: 10, right: 10), reason: '1', ); expect( - spacingUtils - .as( - const EdgeInsets.only(top: 10), - ) - .value, + spacingUtils.as(const EdgeInsets.only(top: 10)).value, const SpacingDto.only(top: 10, bottom: 0, left: 0, right: 0), reason: '2', ); expect( - spacingUtils - .as( - const EdgeInsets.only(left: 10), - ) - .value, - const SpacingDto.only(left: 10, bottom: 0, top: 0, right: 0), + spacingUtils.as(const EdgeInsets.only(left: 10)).value, + const SpacingDto.only(top: 0, bottom: 0, left: 10, right: 0), reason: '3', ); expect( - spacingUtils - .as( - const EdgeInsets.only(right: 10), - ) - .value, - const SpacingDto.only(right: 10, bottom: 0, top: 0, left: 0), + spacingUtils.as(const EdgeInsets.only(right: 10)).value, + const SpacingDto.only(top: 0, bottom: 0, left: 0, right: 10), reason: '4', ); expect( - spacingUtils - .as( - const EdgeInsets.only(bottom: 10), - ) - .value, - const SpacingDto.only(bottom: 10, top: 0, left: 0, right: 0), + spacingUtils.as(const EdgeInsets.only(bottom: 10)).value, + const SpacingDto.only(top: 0, bottom: 10, left: 0, right: 0), reason: '5', ); expect( - spacingUtils - .as( - const EdgeInsets.symmetric(horizontal: 10), - ) - .value, - const SpacingDto.only(left: 10, right: 10, top: 0, bottom: 0), + spacingUtils.as(const EdgeInsets.symmetric(horizontal: 10)).value, + const SpacingDto.only(top: 0, bottom: 0, left: 10, right: 10), reason: '6', ); expect( - spacingUtils - .as( - const EdgeInsets.symmetric(vertical: 10), - ) - .value, + spacingUtils.as(const EdgeInsets.symmetric(vertical: 10)).value, const SpacingDto.only(top: 10, bottom: 10, left: 0, right: 0), reason: '7', ); expect( spacingUtils.directional - .as( - const EdgeInsetsDirectional.only(start: 10), - ) + .as(const EdgeInsetsDirectional.only(start: 10)) .value, - const SpacingDto.only(start: 10, end: 0, top: 0, bottom: 0), + const SpacingDto.only(top: 0, bottom: 0, start: 10, end: 0), reason: '8', ); expect( spacingUtils.directional - .as( - const EdgeInsetsDirectional.only(end: 10), - ) + .as(const EdgeInsetsDirectional.only(end: 10)) .value, - const SpacingDto.only(end: 10, start: 0, top: 0, bottom: 0), + const SpacingDto.only(top: 0, bottom: 0, start: 0, end: 10), reason: '9', ); expect( spacingUtils.directional - .as( - const EdgeInsetsDirectional.only(top: 10), - ) + .as(const EdgeInsetsDirectional.only(top: 10)) .value, const SpacingDto.only(top: 10, bottom: 0, start: 0, end: 0), reason: '10', @@ -152,31 +118,27 @@ void main() { expect( spacingUtils.directional - .as( - const EdgeInsetsDirectional.only(bottom: 10), - ) + .as(const EdgeInsetsDirectional.only(bottom: 10)) .value, - const SpacingDto.only(bottom: 10, top: 0, start: 0, end: 0), + const SpacingDto.only(top: 0, bottom: 10, start: 0, end: 0), reason: '11', ); expect( spacingUtils.directional - .as( - const EdgeInsetsDirectional.only(start: 10, end: 20), - ) + .as(const EdgeInsetsDirectional.only(start: 10, end: 20)) .value, - const SpacingDto.only(start: 10, end: 20, top: 0, bottom: 0), + const SpacingDto.only(top: 0, bottom: 0, start: 10, end: 20), reason: '12', ); expect( spacingUtils.directional .as( - const EdgeInsetsDirectional.only(start: 10, end: 20, top: 30), + const EdgeInsetsDirectional.only(start: 10, top: 30, end: 20), ) .value, - const SpacingDto.only(start: 10, end: 20, top: 30, bottom: 0), + const SpacingDto.only(top: 30, bottom: 0, start: 10, end: 20), reason: '13', ); @@ -185,13 +147,13 @@ void main() { .as( const EdgeInsetsDirectional.only( start: 10, - end: 20, top: 30, + end: 20, bottom: 40, ), ) .value, - const SpacingDto.only(start: 10, end: 20, top: 30, bottom: 40), + const SpacingDto.only(top: 30, bottom: 40, start: 10, end: 20), reason: '14', ); }); @@ -219,10 +181,7 @@ void main() { }); test('spacingUtils.top', () { - expect( - spacingUtils.top(10).value, - const SpacingDto.only(top: 10), - ); + expect(spacingUtils.top(10).value, const SpacingDto.only(top: 10)); }); test('spacingUtils.bottom', () { @@ -233,17 +192,11 @@ void main() { }); test('spacingUtils.left', () { - expect( - spacingUtils.left(10).value, - const SpacingDto.only(left: 10), - ); + expect(spacingUtils.left(10).value, const SpacingDto.only(left: 10)); }); test('spacingUtils.right', () { - expect( - spacingUtils.right(10).value, - const SpacingDto.only(right: 10), - ); + expect(spacingUtils.right(10).value, const SpacingDto.only(right: 10)); }); test('spacingUtils.directional.start', () { @@ -298,15 +251,15 @@ void main() { ); expect( - spacingUtils.directional.only(start: 10, end: 20, top: 30).value, - const SpacingDto.only(start: 10, end: 20, top: 30), + spacingUtils.directional.only(top: 30, start: 10, end: 20).value, + const SpacingDto.only(top: 30, start: 10, end: 20), ); expect( spacingUtils.directional - .only(start: 10, end: 20, top: 30, bottom: 40) + .only(top: 30, bottom: 40, start: 10, end: 20) .value, - const SpacingDto.only(start: 10, end: 20, top: 30, bottom: 40), + const SpacingDto.only(top: 30, bottom: 40, start: 10, end: 20), ); }); }); diff --git a/test/src/attributes/strut_style/strut_style_dto_test.dart b/test/src/attributes/strut_style/strut_style_dto_test.dart index 63496a42c..513f99806 100644 --- a/test/src/attributes/strut_style/strut_style_dto_test.dart +++ b/test/src/attributes/strut_style/strut_style_dto_test.dart @@ -11,10 +11,10 @@ void main() { const strutStyle = StrutStyleDto( fontFamily: 'Roboto', fontSize: 24.0, - height: 2.0, - leading: 1.0, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic, + height: 2.0, + leading: 1.0, forceStrutHeight: true, ); @@ -31,7 +31,7 @@ void main() { test('merge returns merged object correctly', () { const strutStyle1 = StrutStyleDto(fontFamily: 'Roboto', fontSize: 24.0); const strutStyle2 = - StrutStyleDto(height: 2.0, leading: 1.0, fontWeight: FontWeight.bold); + StrutStyleDto(fontWeight: FontWeight.bold, height: 2.0, leading: 1.0); final merged = strutStyle1.merge(strutStyle2); expect(merged.fontFamily, 'Roboto'); @@ -46,10 +46,10 @@ void main() { const strutStyle = StrutStyleDto( fontFamily: 'Roboto', fontSize: 24.0, - height: 2.0, - leading: 1.0, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic, + height: 2.0, + leading: 1.0, ); final resolvedValue = strutStyle.resolve(EmptyMixData); diff --git a/test/src/attributes/strut_style/strut_style_util_test.dart b/test/src/attributes/strut_style/strut_style_util_test.dart index b5bab41e7..f4178d483 100644 --- a/test/src/attributes/strut_style/strut_style_util_test.dart +++ b/test/src/attributes/strut_style/strut_style_util_test.dart @@ -13,14 +13,14 @@ void main() { final strutStyle = strutStyleUtility( fontFamily: 'Roboto', fontSize: 24.0, - height: 2.0, - leading: 1.0, - fontWeight: FontWeight.bold, fontStyle: FontStyle.italic, + fontWeight: FontWeight.bold, forceStrutHeight: true, + height: 2.0, + leading: 1.0, ); - expect(strutStyleUtility.call, isA()); + expect(strutStyleUtility(), isA()); expect(strutStyle.value, isA()); expect(strutStyle.value.fontFamily, 'Roboto'); expect(strutStyle.value.fontSize, 24.0); diff --git a/test/src/attributes/text_style/text_style_dto_test.dart b/test/src/attributes/text_style/text_style_dto_test.dart index fdc1ee9b9..92aeccd18 100644 --- a/test/src/attributes/text_style/text_style_dto_test.dart +++ b/test/src/attributes/text_style/text_style_dto_test.dart @@ -16,31 +16,31 @@ void main() { final attr1 = TextStyleDto.only( color: Colors.red.toDto(), fontSize: 24.0, - decoration: TextDecoration.underline, - decorationColor: Colors.blue.toDto(), - decorationStyle: TextDecorationStyle.dashed, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic, letterSpacing: 1.0, wordSpacing: 2.0, - height: 2.0, - locale: const Locale('en', 'US'), textBaseline: TextBaseline.ideographic, + decoration: TextDecoration.underline, + decorationColor: Colors.blue.toDto(), + decorationStyle: TextDecorationStyle.dashed, + locale: const Locale('en', 'US'), + height: 2.0, ); final attr2 = TextStyleDto.only( color: Colors.blue.toDto(), fontSize: 30.0, - decoration: TextDecoration.lineThrough, - decorationColor: Colors.red.toDto(), - decorationStyle: TextDecorationStyle.dotted, fontWeight: FontWeight.w100, fontStyle: FontStyle.normal, letterSpacing: 2.0, wordSpacing: 3.0, - height: 3.0, - locale: const Locale('en', 'US'), textBaseline: TextBaseline.alphabetic, + decoration: TextDecoration.lineThrough, + decorationColor: Colors.red.toDto(), + decorationStyle: TextDecorationStyle.dotted, + locale: const Locale('en', 'US'), + height: 3.0, ); final merged = attr1.merge(attr2).resolve(EmptyMixData); @@ -62,16 +62,16 @@ void main() { final attr = TextStyleDto.only( color: Colors.red.toDto(), fontSize: 24.0, - decoration: TextDecoration.underline, - decorationColor: Colors.blue.toDto(), - decorationStyle: TextDecorationStyle.dashed, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic, letterSpacing: 1.0, wordSpacing: 2.0, - height: 2.0, - locale: const Locale('en', 'US'), textBaseline: TextBaseline.ideographic, + decoration: TextDecoration.underline, + decorationColor: Colors.blue.toDto(), + decorationStyle: TextDecorationStyle.dashed, + locale: const Locale('en', 'US'), + height: 2.0, ); final textStyle = attr.resolve(EmptyMixData); expect(textStyle.color, Colors.red); @@ -84,11 +84,9 @@ void main() { expect(textStyle.letterSpacing, 1.0); expect(textStyle.wordSpacing, 2.0); expect(textStyle.height, 2.0); - expect( - textStyle.locale, - const Locale('en', 'US'), - ); + expect(textStyle.locale, const Locale('en', 'US')); expect(textStyle.textBaseline, TextBaseline.ideographic); + return const Placeholder(); }); test('Equality holds when all attributes are the same', () { diff --git a/test/src/attributes/text_style/text_style_util_test.dart b/test/src/attributes/text_style/text_style_util_test.dart index e6f0d90f5..8a0ea5ce1 100644 --- a/test/src/attributes/text_style/text_style_util_test.dart +++ b/test/src/attributes/text_style/text_style_util_test.dart @@ -14,29 +14,29 @@ void main() { final yellowPaint = Paint()..color = Colors.yellow; final purplePaint = Paint()..color = Colors.purple; final attr = textStyle( + backgroundColor: Colors.blue, + color: Colors.red, + debugLabel: 'debugLabel', + decoration: TextDecoration.underline, + decorationColor: Colors.green, + decorationStyle: TextDecorationStyle.dashed, fontFamily: 'Roboto', - fontWeight: FontWeight.bold, - fontStyle: FontStyle.italic, + fontFeatures: [const FontFeature.alternative(4)], fontSize: 16.0, + fontStyle: FontStyle.italic, + fontWeight: FontWeight.bold, + height: 2.0, letterSpacing: 1.0, - wordSpacing: 2.0, - debugLabel: 'debugLabel', - textBaseline: TextBaseline.ideographic, + locale: const Locale('en', 'US'), shadows: [ const Shadow( - blurRadius: 1.0, color: Colors.black, offset: Offset(1.0, 1.0), + blurRadius: 1.0, ), ], - color: Colors.red, - backgroundColor: Colors.blue, - fontFeatures: [const FontFeature.alternative(4)], - decoration: TextDecoration.underline, - decorationColor: Colors.green, - decorationStyle: TextDecorationStyle.dashed, - locale: const Locale('en', 'US'), - height: 2.0, + textBaseline: TextBaseline.ideographic, + wordSpacing: 2.0, ); final attrWithPaint = textStyle( @@ -55,10 +55,7 @@ void main() { expect(resolvedValue.textBaseline, TextBaseline.ideographic); expect(resolvedValue.shadows?.length, 1); expect(resolvedValue.shadows?.first.blurRadius, 1.0); - expect( - resolvedValue.shadows?.first.color, - Colors.black, - ); + expect(resolvedValue.shadows?.first.color, Colors.black); expect(resolvedValue.shadows?.first.offset, const Offset(1.0, 1.0)); expect(resolvedValue.color, Colors.red); expect(resolvedValue.backgroundColor, Colors.blue); @@ -67,22 +64,13 @@ void main() { resolvedValue.fontFeatures?.first, const FontFeature.alternative(4), ); - expect( - resolvedValue.decoration, - TextDecoration.underline, - ); - expect( - resolvedValue.decorationColor, - Colors.green, - ); + expect(resolvedValue.decoration, TextDecoration.underline); + expect(resolvedValue.decorationColor, Colors.green); expect(resolvedValue.decorationStyle, TextDecorationStyle.dashed); // expect(textStyleAttribute.value.foreground, yellowPaint); // expect(textStyleAttribute.value.background, purplePaint); expect(resolvedValue.debugLabel, 'debugLabel'); - expect( - resolvedValue.locale, - const Locale('en', 'US'), - ); + expect(resolvedValue.locale, const Locale('en', 'US')); expect(resolvedValue.height, 2.0); expect(resolvedWithPaint.foreground, yellowPaint); expect(resolvedWithPaint.background, purplePaint); @@ -153,9 +141,9 @@ void main() { test('shadows() creates TextStyleAttribute correctly', () { const shadow = Shadow( - blurRadius: 1.0, color: Colors.black, offset: Offset(1.0, 1.0), + blurRadius: 1.0, ); final attribute = textStyle.shadow( blurRadius: 1.0, diff --git a/test/src/core/extensions/color_ext_test.dart b/test/src/core/extensions/color_ext_test.dart index 85208edbd..481fc28fb 100644 --- a/test/src/core/extensions/color_ext_test.dart +++ b/test/src/core/extensions/color_ext_test.dart @@ -10,8 +10,10 @@ void main() { test('mix() should return the correct color', () { final mixedColor = color1.mix(color2, 50); - expect(mixedColor, - const Color.fromARGB(255, 139, 109, 149)); // Colors.purple + expect( + mixedColor, + const Color.fromARGB(255, 139, 109, 149), + ); // Colors.purple }); test('lighten() should return the correct color', () { diff --git a/test/src/core/extensions/values_ext_test.dart b/test/src/core/extensions/values_ext_test.dart index 0a5efab31..cb4cbdd0a 100644 --- a/test/src/core/extensions/values_ext_test.dart +++ b/test/src/core/extensions/values_ext_test.dart @@ -11,10 +11,10 @@ void main() { fontFamily: 'Roboto', fontFamilyFallback: ['Arial', 'Helvetica'], fontSize: 14.0, - fontWeight: FontWeight.bold, - fontStyle: FontStyle.italic, height: 1.2, leading: 5.0, + fontWeight: FontWeight.bold, + fontStyle: FontStyle.italic, forceStrutHeight: true, ); @@ -26,9 +26,9 @@ void main() { test('ShapeDecoration', () { const value = ShapeDecoration( - shape: CircleBorder(), gradient: RadialGradient(colors: [Colors.red, Colors.blue]), shadows: [BoxShadow(blurRadius: 5.0)], + shape: CircleBorder(), ); final dto = ShapeDecorationDto.from(value); @@ -56,8 +56,8 @@ void main() { color: Colors.blue, border: Border.all(), borderRadius: BorderRadius.circular(10.0), - gradient: const LinearGradient(colors: [Colors.red, Colors.blue]), boxShadow: const [BoxShadow(blurRadius: 5.0)], + gradient: const LinearGradient(colors: [Colors.red, Colors.blue]), ); final dto = BoxDecorationDto.from(value); @@ -112,7 +112,7 @@ void main() { }); test('Shadow', () { - const value = BoxShadow(blurRadius: 10.0, color: Colors.black); + const value = BoxShadow(color: Colors.black, blurRadius: 10.0); final dto = BoxShadowDto.from(value); @@ -126,7 +126,7 @@ void main() { }); test('BoxShadow', () { - const value = BoxShadow(blurRadius: 5.0, color: Colors.grey); + const value = BoxShadow(color: Colors.grey, blurRadius: 5.0); final dto = BoxShadowDto.from(value); diff --git a/test/src/decorators/widget_decorator_widget_test.dart b/test/src/decorators/widget_decorator_widget_test.dart index 652b84b63..b33a5aaef 100644 --- a/test/src/decorators/widget_decorator_widget_test.dart +++ b/test/src/decorators/widget_decorator_widget_test.dart @@ -19,16 +19,10 @@ void main() { group('RenderWidgetDecorators', () { testWidgets('Renders decorators in the correct order', (tester) async { await tester.pumpMaterialApp( - RenderWidgetDecorators( - mix: mixData, - child: const Text('child'), - ), + RenderWidgetDecorators(mix: mixData, child: const Text('child')), ); - expect( - find.byType(RenderWidgetDecorators), - findsOneWidget, - ); + expect(find.byType(RenderWidgetDecorators), findsOneWidget); expect( find.descendant( @@ -80,238 +74,239 @@ void main() { ); }); - testWidgets('Renders decorators in the correct order', (tester) async { - await tester.pumpMaterialApp( - RenderWidgetDecorators( - mix: mixData, - orderOfDecorators: const [ - ClipDecorator, - AspectRatioDecorator, - ScaleDecorator, - OpacityDecorator, - VisibilityDecorator, - ], - child: const Text('child'), - ), - ); + testWidgets( + 'Renders decorators in the correct order with many overrides', + (tester) async { + await tester.pumpMaterialApp( + RenderWidgetDecorators( + mix: mixData, + orderOfDecorators: const [ + ClipDecorator, + AspectRatioDecorator, + ScaleDecorator, + OpacityDecorator, + VisibilityDecorator, + ], + child: const Text('child'), + ), + ); - expect( - find.byType(RenderWidgetDecorators), - findsOneWidget, - ); + expect(find.byType(RenderWidgetDecorators), findsOneWidget); - expect( - find.descendant( - of: find.byType(RenderWidgetDecorators), - matching: find.byType(ClipOval), - ), - findsOneWidget, - ); + expect( + find.descendant( + of: find.byType(RenderWidgetDecorators), + matching: find.byType(ClipOval), + ), + findsOneWidget, + ); - expect( - find.descendant( - of: find.byType(ClipOval), - matching: find.byType(AspectRatio), - ), - findsOneWidget, - ); + expect( + find.descendant( + of: find.byType(ClipOval), + matching: find.byType(AspectRatio), + ), + findsOneWidget, + ); - expect( - find.descendant( - of: find.byType(AspectRatio), - matching: find.byType(Transform), - ), - findsOneWidget, - ); + expect( + find.descendant( + of: find.byType(AspectRatio), + matching: find.byType(Transform), + ), + findsOneWidget, + ); - expect( - find.descendant( - of: find.byType(Transform), - matching: find.byType(Opacity), - ), - findsOneWidget, - ); + expect( + find.descendant( + of: find.byType(Transform), + matching: find.byType(Opacity), + ), + findsOneWidget, + ); - expect( - find.descendant( - of: find.byType(Opacity), - matching: find.byType(Padding), - ), - findsOneWidget, - ); + expect( + find.descendant( + of: find.byType(Opacity), + matching: find.byType(Padding), + ), + findsOneWidget, + ); - expect( - find.descendant( - of: find.byType(Padding), - matching: find.text('child'), - ), - findsOneWidget, - ); - }); + expect( + find.descendant( + of: find.byType(Padding), + matching: find.text('child'), + ), + findsOneWidget, + ); + }, + ); // Allow for only a few overrides - testWidgets('Renders decorators in the correct order', (tester) async { - await tester.pumpMaterialApp( - RenderWidgetDecorators( - mix: mixData, - orderOfDecorators: const [ - ClipDecorator, - AspectRatioDecorator, - ], - child: const Text('child'), - ), - ); + testWidgets( + 'Renders decorators in the correct order with a few overrides', + (tester) async { + await tester.pumpMaterialApp( + RenderWidgetDecorators( + mix: mixData, + orderOfDecorators: const [ClipDecorator, AspectRatioDecorator], + child: const Text('child'), + ), + ); - expect( - find.byType(RenderWidgetDecorators), - findsOneWidget, - ); + expect(find.byType(RenderWidgetDecorators), findsOneWidget); - expect( - find.descendant( - of: find.byType(RenderWidgetDecorators), - matching: find.byType(ClipOval), - ), - findsOneWidget, - ); + expect( + find.descendant( + of: find.byType(RenderWidgetDecorators), + matching: find.byType(ClipOval), + ), + findsOneWidget, + ); - expect( - find.descendant( - of: find.byType(ClipOval), - matching: find.byType(AspectRatio), - ), - findsOneWidget, - ); + expect( + find.descendant( + of: find.byType(ClipOval), + matching: find.byType(AspectRatio), + ), + findsOneWidget, + ); - expect( - find.descendant( - of: find.byType(AspectRatio), - matching: find.byType(Visibility), - ), - findsOneWidget, - ); + expect( + find.descendant( + of: find.byType(AspectRatio), + matching: find.byType(Visibility), + ), + findsOneWidget, + ); - expect( - find.descendant( - of: find.byType(Visibility), - matching: find.byType(Transform), - ), - findsOneWidget, - ); + expect( + find.descendant( + of: find.byType(Visibility), + matching: find.byType(Transform), + ), + findsOneWidget, + ); - expect( - find.descendant( - of: find.byType(Transform), - matching: find.byType(Opacity), - ), - findsOneWidget, - ); + expect( + find.descendant( + of: find.byType(Transform), + matching: find.byType(Opacity), + ), + findsOneWidget, + ); - expect( - find.descendant( - of: find.byType(Opacity), - matching: find.byType(Padding), - ), - findsOneWidget, - ); + expect( + find.descendant( + of: find.byType(Opacity), + matching: find.byType(Padding), + ), + findsOneWidget, + ); - expect( - find.descendant( - of: find.byType(Padding), - matching: find.text('child'), - ), - findsOneWidget, - ); - }); + expect( + find.descendant( + of: find.byType(Padding), + matching: find.text('child'), + ), + findsOneWidget, + ); + }, + ); }); group('Decorators attributes', () { testWidgets( - 'should be applied to the first one. The children wont inherit even though the second one is set to inherit', - (tester) async { - const key = Key('box'); - - await tester.pumpWidget( - Box( - style: Style( - scale(2.0), - opacity(0.5), - visibility.on(), - clip.oval(), - aspectRatio(2.0), + 'should be applied to the first one. The children wont inherit even though the second one is set to inherit', + (tester) async { + const key = Key('box'); + + await tester.pumpWidget( + Box( + style: Style( + scale(2.0), + opacity(0.5), + visibility.on(), + clip.oval(), + aspectRatio(2.0), + ), + child: Box( + key: key, + inherit: true, + child: Builder(builder: (context) { + final inheritedMix = MixProvider.maybeOf(context)!; + + expect(inheritedMix.attributes.length, 0); + + return const SizedBox(); + }), + ), ), - child: Box( - key: key, - inherit: true, - child: Builder(builder: (context) { - final inheritedMix = MixProvider.maybeOf(context)!; - - expect(inheritedMix.attributes.length, 0); - return const SizedBox(); - }), - ), - ), - ); + ); - expect( + expect( find.descendant( of: find.byKey(key), matching: find.byType(Transform), ), - findsNothing); + findsNothing, + ); - expect( + expect( find.descendant( of: find.byKey(key), matching: find.byType(Opacity), ), - findsNothing); + findsNothing, + ); - expect( + expect( find.descendant( of: find.byKey(key), matching: find.byType(RotatedBox), ), - findsNothing); + findsNothing, + ); - expect( + expect( find.descendant( of: find.byKey(key), matching: find.byType(Visibility), ), - findsNothing); + findsNothing, + ); - expect( + expect( find.descendant( of: find.byKey(key), matching: find.byType(AspectRatio), ), - findsNothing); - }); + findsNothing, + ); + }, + ); testWidgets( - 'If there are no decorator attributes in Style, RenderWidgetDecorators shouldnt exist in the widget tree', - (tester) async { - const key = Key('box'); - - await tester.pumpWidget( - Box( - key: key, - style: Style( - backgroundColor.red(), - height(100), - width(100), + 'If there are no decorator attributes in Style, RenderWidgetDecorators shouldnt exist in the widget tree', + (tester) async { + const key = Key('box'); + + await tester.pumpWidget( + Box( + style: Style(backgroundColor.red(), height(100), width(100)), + key: key, ), - ), - ); + ); - expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(RenderWidgetDecorators), - ), - findsNothing, - ); - }); + expect( + find.descendant( + of: find.byKey(key), + matching: find.byType(RenderWidgetDecorators), + ), + findsNothing, + ); + }, + ); }); } diff --git a/test/src/decorators/widget_decorators_test.dart b/test/src/decorators/widget_decorators_test.dart index bccb2e67a..30c809371 100644 --- a/test/src/decorators/widget_decorators_test.dart +++ b/test/src/decorators/widget_decorators_test.dart @@ -33,22 +33,24 @@ void main() { }); testWidgets( - 'Build method creates AspectRatio widget with correct aspectRatio', - (WidgetTester tester) async { - const aspectRatio = 2.0; - const decorator = AspectRatioDecorator(aspectRatio); + 'Build method creates AspectRatio widget with correct aspectRatio', + (WidgetTester tester) async { + const aspectRatio = 2.0; + const decorator = AspectRatioDecorator(aspectRatio); - await tester.pumpMaterialApp(decorator.build(EmptyMixData, Container())); + await tester + .pumpMaterialApp(decorator.build(EmptyMixData, Container())); - final AspectRatio aspectRatioWidget = - tester.widget(find.byType(AspectRatio)); + final AspectRatio aspectRatioWidget = + tester.widget(find.byType(AspectRatio)); - expect(find.byType(AspectRatio), findsOneWidget); - expect(aspectRatioWidget.aspectRatio, aspectRatio); + expect(find.byType(AspectRatio), findsOneWidget); + expect(aspectRatioWidget.aspectRatio, aspectRatio); - expect(aspectRatioWidget.child, isA()); - expect(aspectRatioWidget.aspectRatio, aspectRatio); - }); + expect(aspectRatioWidget.child, isA()); + expect(aspectRatioWidget.aspectRatio, aspectRatio); + }, + ); }); group('VisibilityDecorator Tests', () { @@ -81,20 +83,22 @@ void main() { }); testWidgets( - 'Build method creates Visibility widget with correct visible property', - (WidgetTester tester) async { - const visible = true; - const decorator = VisibilityDecorator(visible); - - await tester.pumpMaterialApp(decorator.build(EmptyMixData, Container())); - - final Visibility visibilityWidget = - tester.widget(find.byType(Visibility)); - - expect(find.byType(Visibility), findsOneWidget); - expect(visibilityWidget.visible, visible); - expect(visibilityWidget.child, isA()); - }); + 'Build method creates Visibility widget with correct visible property', + (WidgetTester tester) async { + const visible = true; + const decorator = VisibilityDecorator(visible); + + await tester + .pumpMaterialApp(decorator.build(EmptyMixData, Container())); + + final Visibility visibilityWidget = + tester.widget(find.byType(Visibility)); + + expect(find.byType(Visibility), findsOneWidget); + expect(visibilityWidget.visible, visible); + expect(visibilityWidget.child, isA()); + }, + ); }); group('OpacityDecorator Tests', () { @@ -124,19 +128,22 @@ void main() { expect(decorator1.hashCode == decorator3.hashCode, false); }); - testWidgets('Build method creates Opacity widget with correct opacity', - (WidgetTester tester) async { - const opacity = 0.5; - const decorator = OpacityDecorator(opacity); + testWidgets( + 'Build method creates Opacity widget with correct opacity', + (WidgetTester tester) async { + const opacity = 0.5; + const decorator = OpacityDecorator(opacity); - await tester.pumpMaterialApp(decorator.build(EmptyMixData, Container())); + await tester + .pumpMaterialApp(decorator.build(EmptyMixData, Container())); - final Opacity opacityWidget = tester.widget(find.byType(Opacity)); + final Opacity opacityWidget = tester.widget(find.byType(Opacity)); - expect(find.byType(Opacity), findsOneWidget); - expect(opacityWidget.opacity, opacity); - expect(opacityWidget.child, isA()); - }); + expect(find.byType(Opacity), findsOneWidget); + expect(opacityWidget.opacity, opacity); + expect(opacityWidget.child, isA()); + }, + ); }); group('FlexibleDecorator Tests', () { @@ -179,27 +186,24 @@ void main() { }); testWidgets( - 'Build method creates Flexible widget with correct flex and fit', - (WidgetTester tester) async { - const flex = 2; - const fit = FlexFit.tight; - const decorator = FlexibleDecorator(flex: flex, fit: fit); - - await tester.pumpMaterialApp( - Row( - children: [ - decorator.build(EmptyMixData, Container()), - ], - ), - ); - - final Flexible flexibleWidget = tester.widget(find.byType(Flexible)); - - expect(find.byType(Flexible), findsOneWidget); - expect(flexibleWidget.flex, flex); - expect(flexibleWidget.fit, fit); - expect(flexibleWidget.child, isA()); - }); + 'Build method creates Flexible widget with correct flex and fit', + (WidgetTester tester) async { + const flex = 2; + const fit = FlexFit.tight; + const decorator = FlexibleDecorator(flex: flex, fit: fit); + + await tester.pumpMaterialApp( + Row(children: [decorator.build(EmptyMixData, Container())]), + ); + + final Flexible flexibleWidget = tester.widget(find.byType(Flexible)); + + expect(find.byType(Flexible), findsOneWidget); + expect(flexibleWidget.flex, flex); + expect(flexibleWidget.fit, fit); + expect(flexibleWidget.child, isA()); + }, + ); }); group('RotateDecorator Tests', () { @@ -230,20 +234,22 @@ void main() { }); testWidgets( - 'Build method creates RotatedBox widget with correct quarterTurns', - (WidgetTester tester) async { - const quarterTurns = 1; - const decorator = RotateDecorator(quarterTurns); - - await tester.pumpMaterialApp(decorator.build(EmptyMixData, Container())); - - final RotatedBox rotatedBoxWidget = - tester.widget(find.byType(RotatedBox)); - - expect(find.byType(RotatedBox), findsOneWidget); - expect(rotatedBoxWidget.quarterTurns, quarterTurns); - expect(rotatedBoxWidget.child, isA()); - }); + 'Build method creates RotatedBox widget with correct quarterTurns', + (WidgetTester tester) async { + const quarterTurns = 1; + const decorator = RotateDecorator(quarterTurns); + + await tester + .pumpMaterialApp(decorator.build(EmptyMixData, Container())); + + final RotatedBox rotatedBoxWidget = + tester.widget(find.byType(RotatedBox)); + + expect(find.byType(RotatedBox), findsOneWidget); + expect(rotatedBoxWidget.quarterTurns, quarterTurns); + expect(rotatedBoxWidget.child, isA()); + }, + ); }); group('ScaleDecorator Tests', () { @@ -274,28 +280,32 @@ void main() { }); testWidgets( - 'Build method creates Transform.scale widget with correct scale', - (WidgetTester tester) async { - const scale = 1.5; - const decorator = ScaleDecorator(scale); - - await tester.pumpMaterialApp(decorator.build(EmptyMixData, Container())); - - final Transform transformWidget = tester.widget(find.byType(Transform)); - - expect(find.byType(Transform), findsOneWidget); - expect(transformWidget.transform, - Matrix4.diagonal3Values(scale, scale, 1.0)); - expect(transformWidget.child, isA()); - }); + 'Build method creates Transform.scale widget with correct scale', + (WidgetTester tester) async { + const scale = 1.5; + const decorator = ScaleDecorator(scale); + + await tester + .pumpMaterialApp(decorator.build(EmptyMixData, Container())); + + final Transform transformWidget = tester.widget(find.byType(Transform)); + + expect(find.byType(Transform), findsOneWidget); + expect( + transformWidget.transform, + Matrix4.diagonal3Values(scale, scale, 1.0), + ); + expect(transformWidget.child, isA()); + }, + ); }); group('ClipDecorator Tests', () { test('Constructor assigns properties correctly', () { const clipType = ClipType.rect; const clipBehavior = Clip.antiAlias; - final clipper = RectClipper(); - final decorator = ClipDecorator( + const clipper = RectClipper(); + const decorator = ClipDecorator( clipType: clipType, clipBehavior: clipBehavior, clipper: clipper, @@ -334,57 +344,73 @@ void main() { expect(afterResult.clipBehavior, Clip.hardEdge); }); - testWidgets('Build method creates ClipRect widget', - (WidgetTester tester) async { - const decorator = ClipDecorator(clipType: ClipType.rect); - - await tester.pumpMaterialApp(decorator.build(EmptyMixData, Container())); - - expect(find.byType(ClipRect), findsOneWidget); - }); + testWidgets( + 'Build method creates ClipRect widget', + (WidgetTester tester) async { + const decorator = ClipDecorator(clipType: ClipType.rect); - testWidgets('Build method creates ClipOval widget', - (WidgetTester tester) async { - const decorator = ClipDecorator(clipType: ClipType.oval); + await tester + .pumpMaterialApp(decorator.build(EmptyMixData, Container())); - await tester.pumpMaterialApp(decorator.build(EmptyMixData, Container())); + expect(find.byType(ClipRect), findsOneWidget); + }, + ); - expect(find.byType(ClipOval), findsOneWidget); - }); + testWidgets( + 'Build method creates ClipOval widget', + (WidgetTester tester) async { + const decorator = ClipDecorator(clipType: ClipType.oval); - testWidgets('Build method creates ClipPath widget for triangle', - (WidgetTester tester) async { - const decorator = ClipDecorator(clipType: ClipType.triangle); + await tester + .pumpMaterialApp(decorator.build(EmptyMixData, Container())); - await tester.pumpMaterialApp(decorator.build(EmptyMixData, Container())); + expect(find.byType(ClipOval), findsOneWidget); + }, + ); - expect(find.byType(ClipPath), findsOneWidget); - }); + testWidgets( + 'Build method creates ClipPath widget for triangle', + (WidgetTester tester) async { + const decorator = ClipDecorator(clipType: ClipType.triangle); - testWidgets('Build method creates ClipPath widget for path', - (WidgetTester tester) async { - const decorator = ClipDecorator(clipType: ClipType.path); + await tester + .pumpMaterialApp(decorator.build(EmptyMixData, Container())); - await tester.pumpMaterialApp(decorator.build(EmptyMixData, Container())); + expect(find.byType(ClipPath), findsOneWidget); + }, + ); - expect(find.byType(ClipPath), findsOneWidget); - }); + testWidgets( + 'Build method creates ClipPath widget for path', + (WidgetTester tester) async { + const decorator = ClipDecorator(clipType: ClipType.path); - testWidgets('Build method creates ClipRRect widget', - (WidgetTester tester) async { - const decorator = ClipDecorator( - clipType: ClipType.rRect, - borderRadius: BorderRadius.all(Radius.circular(10.0)), - ); + await tester + .pumpMaterialApp(decorator.build(EmptyMixData, Container())); - await tester.pumpMaterialApp(decorator.build(EmptyMixData, Container())); + expect(find.byType(ClipPath), findsOneWidget); + }, + ); - expect(find.byType(ClipRRect), findsOneWidget); - }); + testWidgets( + 'Build method creates ClipRRect widget', + (WidgetTester tester) async { + const decorator = ClipDecorator( + clipType: ClipType.rRect, + borderRadius: BorderRadius.all(Radius.circular(10.0)), + ); + + await tester + .pumpMaterialApp(decorator.build(EmptyMixData, Container())); + + expect(find.byType(ClipRRect), findsOneWidget); + }, + ); }); } class RectClipper extends CustomClipper { + const RectClipper(); @override Rect getClip(Size size) { return Rect.zero; diff --git a/test/src/decorators/widget_decorators_util_test.dart b/test/src/decorators/widget_decorators_util_test.dart index 7b0501c60..8e1468b0c 100644 --- a/test/src/decorators/widget_decorators_util_test.dart +++ b/test/src/decorators/widget_decorators_util_test.dart @@ -79,21 +79,27 @@ void main() { clip.rrect(borderRadius: BorderRadius.circular(10.0)); expect( - clipRRectDecorator.value.borderRadius, BorderRadius.circular(10.0)); + clipRRectDecorator.value.borderRadius, + BorderRadius.circular(10.0), + ); }); test('clipOval creates ClipOvalDecorator correctly', () { final clipOvalDecorator = clip.oval(); - expect(clipOvalDecorator.value.build(EmptyMixData, const Empty()), - isA()); + expect( + clipOvalDecorator.value.build(EmptyMixData, const Empty()), + isA(), + ); }); test('clipPath creates ClipPathDecorator correctly', () { final clipPathDecorator = clip.path(); - expect(clipPathDecorator.value.build(EmptyMixData, const Empty()), - isA()); + expect( + clipPathDecorator.value.build(EmptyMixData, const Empty()), + isA(), + ); }); test('clipTriangle creates ClipPathDecorator correctly', () { diff --git a/test/src/factory/mix_provider_data_test.dart b/test/src/factory/mix_provider_data_test.dart index 1ea665759..d94dbe14c 100644 --- a/test/src/factory/mix_provider_data_test.dart +++ b/test/src/factory/mix_provider_data_test.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mix/mix.dart'; -import 'package:mix/src/theme/token_resolver.dart'; import '../../helpers/testing_utils.dart'; @@ -9,16 +8,15 @@ void main() { final autoApplyVariant = ContextVariant('mock', (context) => true); test('MixData create', () { final mixData = MixData.create( - MockBuildContext(), - Style( - const MockIntScalarAttribute(1), - const MockStringScalarAttribute('test'), - const MockDoubleScalarAttribute(3.0), - const MockBooleanScalarAttribute(false), - autoApplyVariant( - const MockDoubleScalarAttribute(2.0), - ), - )); + MockBuildContext(), + Style( + const MockIntScalarAttribute(1), + const MockStringScalarAttribute('test'), + const MockDoubleScalarAttribute(3.0), + const MockBooleanScalarAttribute(false), + autoApplyVariant(const MockDoubleScalarAttribute(2.0)), + ), + ); // Test that the `MixData` object is created with the correct properties. expect(mixData, isInstanceOf()); @@ -28,85 +26,107 @@ void main() { expect(mixData.attributes, isInstanceOf()); expect(mixData.tokens, isInstanceOf()); expect(mixData.attributes.length, 4); - expect(mixData.attributeOf(), - isInstanceOf()); - expect(mixData.attributeOf(), - const MockStringScalarAttribute('test')); - expect(mixData.attributeOf(), - isInstanceOf()); - expect(mixData.attributeOf(), - const MockDoubleScalarAttribute(2.0)); - - expect(mixData.attributeOf(), - const MockBooleanScalarAttribute(false)); + expect( + mixData.attributeOf(), + isInstanceOf(), + ); + expect( + mixData.attributeOf(), + const MockStringScalarAttribute('test'), + ); + expect( + mixData.attributeOf(), + isInstanceOf(), + ); + expect( + mixData.attributeOf(), + const MockDoubleScalarAttribute(2.0), + ); + + expect( + mixData.attributeOf(), + const MockBooleanScalarAttribute(false), + ); }); test('MixData merge', () { final mixData = MixData.create( - MockBuildContext(), - Style( - const MockIntScalarAttribute(1), - const MockStringScalarAttribute('test'), - const MockDoubleScalarAttribute(3.0), - const MockBooleanScalarAttribute(true), - autoApplyVariant( - const MockDoubleScalarAttribute(2.0), - ), - )); + MockBuildContext(), + Style( + const MockIntScalarAttribute(1), + const MockStringScalarAttribute('test'), + const MockDoubleScalarAttribute(3.0), + const MockBooleanScalarAttribute(true), + autoApplyVariant(const MockDoubleScalarAttribute(2.0)), + ), + ); final mixData2 = MixData.create( - MockBuildContext(), - Style( - const MockDoubleScalarAttribute(5.0), - autoApplyVariant( - const MockDoubleScalarAttribute(4.0), - ), - )); + MockBuildContext(), + Style( + const MockDoubleScalarAttribute(5.0), + autoApplyVariant(const MockDoubleScalarAttribute(4.0)), + ), + ); final mergedMixData = mixData.merge(mixData2); expect(mergedMixData, isInstanceOf()); expect(mergedMixData.attributes.length, 4); - expect(mergedMixData.attributeOf(), - isInstanceOf()); - expect(mergedMixData.attributeOf(), - isInstanceOf()); - expect(mergedMixData.attributeOf(), - isInstanceOf()); - - expect(mergedMixData.attributeOf(), - const MockBooleanScalarAttribute(true)); - - expect(mergedMixData.attributeOf(), - const MockIntScalarAttribute(1)); - expect(mergedMixData.attributeOf(), - const MockStringScalarAttribute('test')); - expect(mergedMixData.attributeOf(), - const MockDoubleScalarAttribute(4.0)); + expect( + mergedMixData.attributeOf(), + isInstanceOf(), + ); + expect( + mergedMixData.attributeOf(), + isInstanceOf(), + ); + expect( + mergedMixData.attributeOf(), + isInstanceOf(), + ); + + expect( + mergedMixData.attributeOf(), + const MockBooleanScalarAttribute(true), + ); + + expect( + mergedMixData.attributeOf(), + const MockIntScalarAttribute(1), + ); + expect( + mergedMixData.attributeOf(), + const MockStringScalarAttribute('test'), + ); + expect( + mergedMixData.attributeOf(), + const MockDoubleScalarAttribute(4.0), + ); }); - testWidgets('MixData.inherited shouldnt have attributes non inheritable', - (WidgetTester tester) async { - await tester.pumpWidget( - MixProvider( - data: MixData.create( - MockBuildContext(), - Style( - const _NonInheritableAttribute(), - icon.color.black(), + testWidgets( + 'MixData.inherited shouldnt have attributes non inheritable', + (WidgetTester tester) async { + await tester.pumpWidget( + MixProvider( + data: MixData.create( + MockBuildContext(), + Style(const _NonInheritableAttribute(), icon.color.black()), ), + child: Builder(builder: (context) { + final inheritedMix = MixData.inherited(context); + final iconSpec = IconSpec.of(inheritedMix!); + + expect(inheritedMix.attributes.length, 1); + expect(iconSpec.color, Colors.black); + + return const SizedBox(); + }), ), - child: Builder(builder: (context) { - final inheritedMix = MixData.inherited(context); - final iconSpec = IconSpec.of(inheritedMix!); - - expect(inheritedMix.attributes.length, 1); - expect(iconSpec.color, Colors.black); - return const SizedBox(); - }), - ), - ); - }); + ); + }, + ); } class _NonInheritableAttribute diff --git a/test/src/factory/style_mix_ext_test.dart b/test/src/factory/style_mix_ext_test.dart index 008613afa..22ded159a 100644 --- a/test/src/factory/style_mix_ext_test.dart +++ b/test/src/factory/style_mix_ext_test.dart @@ -6,65 +6,53 @@ void main() { final keyOne = UniqueKey(); final keyTwo = UniqueKey(); final keyThree = UniqueKey(); - testWidgets('Style.container matches StyledContainer(style:Style)', - (tester) async { - final style = Style( - box.decoration( - border: Border.all( - color: Colors.red, - ), - ), - ); - - await tester.pumpWidget( - MaterialApp( - home: Column( - children: [ - style.container(child: const SizedBox(), key: keyOne), - Box( - key: keyTwo, - style: style, - child: const SizedBox(), - ), - Box( - key: keyThree, - style: const Style.empty(), - child: const SizedBox(), - ), - ], + testWidgets( + 'Style.container matches StyledContainer(style:Style)', + (tester) async { + final style = Style( + box.decoration(border: Border.all(color: Colors.red)), + ); + + await tester.pumpWidget( + MaterialApp( + home: Column( + children: [ + style.container(key: keyOne, child: const SizedBox()), + Box(style: style, key: keyTwo, child: const SizedBox()), + Box( + style: const Style.empty(), + key: keyThree, + child: const SizedBox(), + ), + ], + ), ), - ), - ); + ); - final containerOne = tester.widget(find.byKey(keyOne)); - final containerTwo = tester.widget(find.byKey(keyTwo)); - final containerThree = tester.widget(find.byKey(keyThree)); + final containerOne = tester.widget(find.byKey(keyOne)); + final containerTwo = tester.widget(find.byKey(keyTwo)); + final containerThree = tester.widget(find.byKey(keyThree)); - expect(containerOne.style, style); - expect(containerTwo.style, style); - expect(containerThree.style, isNot(style)); - }); + expect(containerOne.style, style); + expect(containerTwo.style, style); + expect(containerThree.style, isNot(style)); + }, + ); testWidgets('Style.box matches StyledContainer(style:Style)', (tester) async { final style = Style( - box.decoration( - border: Border.all(color: Colors.red), - ), + box.decoration(border: Border.all(color: Colors.red)), ); await tester.pumpWidget( MaterialApp( home: Column( children: [ - style.box(child: const SizedBox(), key: keyOne), + style.box(key: keyOne, child: const SizedBox()), + Box(style: style, key: keyTwo, child: const SizedBox()), Box( - key: keyTwo, - style: style, - child: const SizedBox(), - ), - Box( - key: keyThree, style: const Style.empty(), + key: keyThree, child: const SizedBox(), ), ], @@ -88,12 +76,8 @@ void main() { MaterialApp( home: Column( children: [ - style.hbox(children: [const SizedBox()], key: keyOne), - HBox( - style: style, - key: keyTwo, - children: const [SizedBox()], - ), + style.hbox(key: keyOne, children: [const SizedBox()]), + HBox(style: style, key: keyTwo, children: const [SizedBox()]), HBox( style: const Style.empty(), key: keyThree, @@ -115,24 +99,22 @@ void main() { testWidgets('Style.row matches StyledRow(style:Style)', (tester) async { final style = Style( - box.decoration( - border: Border.all(color: Colors.red), - ), + box.decoration(border: Border.all(color: Colors.red)), ); await tester.pumpWidget( MaterialApp( home: Column( children: [ - style.row(children: [const SizedBox()], key: keyOne), + style.row(key: keyOne, children: [const SizedBox()]), StyledRow( - key: keyTwo, style: style, + key: keyTwo, children: const [SizedBox()], ), StyledRow( - key: keyThree, style: const Style.empty(), + key: keyThree, children: const [SizedBox()], ), ], @@ -157,16 +139,8 @@ void main() { home: Column( children: [ style.text('text', key: keyOne), - StyledText( - 'text', - key: keyTwo, - style: style, - ), - StyledText( - 'text', - key: keyThree, - style: const Style.empty(), - ), + StyledText('text', style: style, key: keyTwo), + StyledText('text', style: const Style.empty(), key: keyThree), ], ), ), @@ -188,12 +162,8 @@ void main() { MaterialApp( home: Column( children: [ - style.vbox(children: [const SizedBox()], key: keyOne), - VBox( - style: style, - key: keyTwo, - children: const [SizedBox()], - ), + style.vbox(key: keyOne, children: [const SizedBox()]), + VBox(style: style, key: keyTwo, children: const [SizedBox()]), VBox( style: const Style.empty(), key: keyThree, @@ -215,26 +185,22 @@ void main() { testWidgets('Style.column matches StyledColumn(style:Style)', (tester) async { final style = Style( - box.decoration( - border: Border.all( - color: Colors.red, - ), - ), + box.decoration(border: Border.all(color: Colors.red)), ); await tester.pumpWidget( MaterialApp( home: Column( children: [ - style.column(children: [const SizedBox()], key: keyOne), + style.column(key: keyOne, children: [const SizedBox()]), StyledColumn( - key: keyTwo, style: style, + key: keyTwo, children: const [SizedBox()], ), StyledColumn( - key: keyThree, style: const Style.empty(), + key: keyThree, children: const [SizedBox()], ), ], @@ -259,15 +225,11 @@ void main() { home: Column( children: [ style.icon(Icons.ac_unit, key: keyOne), + StyledIcon(Icons.ac_unit, style: style, key: keyTwo), StyledIcon( Icons.ac_unit, - key: keyTwo, - style: style, - ), - StyledIcon( - Icons.ac_unit, - key: keyThree, style: const Style.empty(), + key: keyThree, ), ], ), diff --git a/test/src/factory/style_mix_test.dart b/test/src/factory/style_mix_test.dart index e854e4396..f5c49e525 100644 --- a/test/src/factory/style_mix_test.dart +++ b/test/src/factory/style_mix_test.dart @@ -190,7 +190,7 @@ void main() { final multiVariant = MultiVariant.and([ variantAttr3, - MultiVariant.or(const [variantAttr1, variantAttr2]) + MultiVariant.or(const [variantAttr1, variantAttr2]), ]); final style = Style(attr1, attr2, multiVariant(attr3)); @@ -276,54 +276,52 @@ void main() { }); test( - 'should return the same value if the parameter don`t satisfy the logic expression with 3 variants combined with `and` operator', - () { - const variantAttr3 = Variant('variantAttr3'); - - final style = Style( - box.color.red(), - (variantAttr1 & variantAttr2 & variantAttr3)( - icon.color.black(), - ), - ); - - final a = style.applyVariants([variantAttr3]); - final b = style.applyVariants([variantAttr2]); - final c = style.applyVariants([variantAttr1]); - final d = style.applyVariants([variantAttr2, variantAttr3]); - final e = style.applyVariants([variantAttr1, variantAttr3]); - final f = style.applyVariants([variantAttr2, variantAttr1]); - - expect(a, style); - expect(a, b); - expect(a, c); - expect(a, d); - expect(a, e); - expect(a, f); - }); + 'should return the same value if the parameter don`t satisfy the logic expression with 3 variants combined with `and` operator', + () { + const variantAttr3 = Variant('variantAttr3'); + + final style = Style( + box.color.red(), + (variantAttr1 & variantAttr2 & variantAttr3)(icon.color.black()), + ); + + final a = style.applyVariants([variantAttr3]); + final b = style.applyVariants([variantAttr2]); + final c = style.applyVariants([variantAttr1]); + final d = style.applyVariants([variantAttr2, variantAttr3]); + final e = style.applyVariants([variantAttr1, variantAttr3]); + final f = style.applyVariants([variantAttr2, variantAttr1]); + + expect(a, style); + expect(a, b); + expect(a, c); + expect(a, d); + expect(a, e); + expect(a, f); + }, + ); test( - 'should return the same value if the parameter don`t satisfy the logic expression with 3 variants combined with `or` operator', - () { - const variantAttr3 = Variant('variantAttr3'); + 'should return the same value if the parameter don`t satisfy the logic expression with 3 variants combined with `or` operator', + () { + const variantAttr3 = Variant('variantAttr3'); - const extraVariant1 = Variant('extraVariant1'); - const extraVariant2 = Variant('extraVariant2'); + const extraVariant1 = Variant('extraVariant1'); + const extraVariant2 = Variant('extraVariant2'); - final style = Style( - box.color.red(), - (variantAttr1 | variantAttr2 | variantAttr3)( - icon.color.black(), - ), - ); + final style = Style( + box.color.red(), + (variantAttr1 | variantAttr2 | variantAttr3)(icon.color.black()), + ); - final a = style.applyVariants([extraVariant1]); - final b = style.applyVariants([extraVariant2]); - final c = style.applyVariants([extraVariant1, extraVariant2]); + final a = style.applyVariants([extraVariant1]); + final b = style.applyVariants([extraVariant2]); + final c = style.applyVariants([extraVariant1, extraVariant2]); - expect(a, b); - expect(a, c); - }); + expect(a, b); + expect(a, c); + }, + ); }); group('Style.pickVariants', () { @@ -341,13 +339,8 @@ void main() { final style = Style( attr1, attr2, - outlinedVariant( - stringAttr1, - stringAttr2, - ), - smallVariant( - stringAttr3, - ), + outlinedVariant(stringAttr1, stringAttr2), + smallVariant(stringAttr3), ); final pickedMix = style.pickVariants([outlinedVariant, smallVariant]); @@ -423,7 +416,7 @@ void main() { final updatedStyle = style.variantSwitcher([ const SwitchCondition(useVariant1, variant1), - const SwitchCondition(useVariant2, variant2) + const SwitchCondition(useVariant2, variant2), ]); expect(style.styles.length, 2); @@ -435,18 +428,20 @@ void main() { expect(updatedStyle.values.contains(variant2(attribute4)), isTrue); }); - test('variantChooser returns the same style when no conditions are met', - () { - const useVariant1 = false; - const useVariant2 = false; - - final updatedStyle = style.variantSwitcher([ - const SwitchCondition(useVariant1, variant1), - const SwitchCondition(useVariant2, variant2) - ]); - - expect(updatedStyle, equals(style)); - }); + test( + 'variantChooser returns the same style when no conditions are met', + () { + const useVariant1 = false; + const useVariant2 = false; + + final updatedStyle = style.variantSwitcher([ + const SwitchCondition(useVariant1, variant1), + const SwitchCondition(useVariant2, variant2), + ]); + + expect(updatedStyle, equals(style)); + }, + ); test('Returns both styles when both conditions are true', () { const useVariant1 = true; @@ -454,15 +449,21 @@ void main() { final updatedStyle = style.variantSwitcher([ const SwitchCondition(useVariant1, variant1), - const SwitchCondition(useVariant2, variant2) + const SwitchCondition(useVariant2, variant2), ]); expect(updatedStyle.values.contains(attribute4), isTrue, reason: '1'); expect(updatedStyle.values.contains(attribute3), isTrue, reason: '2'); - expect(updatedStyle.values.contains(variant1(attribute3)), isFalse, - reason: '3'); - expect(updatedStyle.values.contains(variant2(attribute4)), isFalse, - reason: '4'); + expect( + updatedStyle.values.contains(variant1(attribute3)), + isFalse, + reason: '3', + ); + expect( + updatedStyle.values.contains(variant2(attribute4)), + isFalse, + reason: '4', + ); }); }); } diff --git a/test/src/helpers/build_context_ext_test.dart b/test/src/helpers/build_context_ext_test.dart index e36d9b386..6b5a0f9a5 100644 --- a/test/src/helpers/build_context_ext_test.dart +++ b/test/src/helpers/build_context_ext_test.dart @@ -49,7 +49,6 @@ void main() { final theme = ThemeData.light(useMaterial3: true); await tester.pumpWidget( MaterialApp( - theme: theme, home: MixTheme( data: const MixThemeData.empty(), child: Builder( @@ -58,6 +57,7 @@ void main() { }, ), ), + theme: theme, ), ); @@ -74,10 +74,14 @@ void main() { expect(context.textTheme, Theme.of(context).textTheme); expect(context.mixTheme, const MixThemeData.empty()); expect(context.isDarkMode, Theme.of(context).brightness == Brightness.dark); - expect(context.isLandscape, - MediaQuery.of(context).orientation == Orientation.landscape); - expect(context.isPortrait, - MediaQuery.of(context).orientation == Orientation.portrait); + expect( + context.isLandscape, + MediaQuery.of(context).orientation == Orientation.landscape, + ); + expect( + context.isPortrait, + MediaQuery.of(context).orientation == Orientation.portrait, + ); // addTearDown(tester.view.resetPhysicalSize); }); diff --git a/test/src/helpers/deep_collection_equality_test.dart b/test/src/helpers/deep_collection_equality_test.dart index dc945eb37..290b5798d 100644 --- a/test/src/helpers/deep_collection_equality_test.dart +++ b/test/src/helpers/deep_collection_equality_test.dart @@ -17,24 +17,34 @@ void main() { test('checks Map equality with simple types', () { expect(deepEquality.equals({'key': 'value'}, {'key': 'value'}), isTrue); expect( - deepEquality.equals({'key1': 'value'}, {'key2': 'value'}), isFalse); + deepEquality.equals({'key1': 'value'}, {'key2': 'value'}), + isFalse, + ); expect( - deepEquality.equals({'key': 'value1'}, {'key': 'value2'}), isFalse); + deepEquality.equals({'key': 'value1'}, {'key': 'value2'}), + isFalse, + ); expect(deepEquality.equals({}, {}), isTrue); expect( - deepEquality - .equals({'key': 'value'}, {'key': 'value', 'extra': 'value'}), - isFalse); + deepEquality + .equals({'key': 'value'}, {'key': 'value', 'extra': 'value'}), + isFalse, + ); }); test('checks Set equality with simple types', () { expect(deepEquality.equals({1, 2, 3}, {1, 2, 3}), isTrue); expect(deepEquality.equals({1, 2}, {1, 2, 3}), isFalse); - expect(deepEquality.equals({3, 2, 1}, {1, 2, 3}), - isTrue); // Order should not matter in sets + expect( + deepEquality.equals({3, 2, 1}, {1, 2, 3}), + isTrue, + ); // Order should not matter in sets // ignore: equal_elements_in_set - expect(deepEquality.equals({1}, {1, 1, 1}), - isTrue); // Duplicate elements in a set + expect( + // ignore: equal_elements_in_set + deepEquality.equals({1}, {1, 1, 1}), + isTrue, + ); // Duplicate elements in a set }); test('checks Iterable equality with simple types', () { @@ -46,56 +56,76 @@ void main() { test('checks nested collection equality', () { expect( - deepEquality.equals([ + deepEquality.equals( + [ {'key': 'value'}, - {'key2': 'value2'} - ], [ + {'key2': 'value2'}, + ], + [ {'key': 'value'}, - {'key2': 'value2'} - ]), - isTrue); + {'key2': 'value2'}, + ], + ), + isTrue, + ); expect( - deepEquality.equals({ - 'outer': {'inner': 'value'} - }, { - 'outer': {'inner': 'value'} - }), - isTrue); + deepEquality.equals( + { + 'outer': {'inner': 'value'}, + }, + { + 'outer': {'inner': 'value'}, + }, + ), + isTrue, + ); expect( - deepEquality.equals({ - 'set': {1, 2, 3} - }, { - 'set': {3, 2, 1} - }), - isTrue); + deepEquality.equals( + { + 'set': {1, 2, 3}, + }, + { + 'set': {3, 2, 1}, + }, + ), + isTrue, + ); expect( - deepEquality.equals([ + deepEquality.equals( + [ 1, [ 2, - [3, 4] - ] - ], [ + [3, 4], + ], + ], + [ 1, [ 2, - [3, 4] - ] - ]), - isTrue); + [3, 4], + ], + ], + ), + isTrue, + ); expect( - deepEquality.equals({ - 'set': {1, 2, 3} - }, { - 'set': {1, 2} - }), - isFalse); + deepEquality.equals( + { + 'set': {1, 2, 3}, + }, + { + 'set': {1, 2}, + }, + ), + isFalse, + ); }); test('checks custom object equality', () { - final obj1 = CustomObject(id: 1, value: 'Test'); - final obj2 = CustomObject(id: 1, value: 'Test'); - final obj3 = CustomObject(id: 2, value: 'Test'); + const obj1 = CustomObject(id: 1, value: 'Test'); + const obj2 = CustomObject(id: 1, value: 'Test'); + const obj3 = CustomObject(id: 2, value: 'Test'); expect(deepEquality.equals(obj1, obj2), isTrue); expect(deepEquality.equals(obj1, obj3), isFalse); @@ -125,18 +155,19 @@ void main() { }); test( - 'nested collections with identical contents produce the same hash code', - () { - var nestedList1 = [ - [1, 2], - {'a': 1} - ]; - var nestedList2 = [ - [1, 2], - {'a': 1} - ]; - expect(deepEquality.hash(nestedList1), deepEquality.hash(nestedList2)); - }); + 'nested collections with identical contents produce the same hash code', + () { + var nestedList1 = [ + [1, 2], + {'a': 1}, + ]; + var nestedList2 = [ + [1, 2], + {'a': 1}, + ]; + expect(deepEquality.hash(nestedList1), deepEquality.hash(nestedList2)); + }, + ); test('unordered collections produce consistent hash codes', () { var iterable1 = {3, 2, 1}; @@ -144,12 +175,14 @@ void main() { expect(deepEquality.hash(iterable1), deepEquality.hash(iterable2)); }); - test('custom objects with the same properties produce the same hash code', - () { - var object1 = CustomObject(id: 1, value: 'test'); - var object2 = CustomObject(id: 1, value: 'test'); - expect(deepEquality.hash(object1), deepEquality.hash(object2)); - }); + test( + 'custom objects with the same properties produce the same hash code', + () { + var object1 = const CustomObject(id: 1, value: 'test'); + var object2 = const CustomObject(id: 1, value: 'test'); + expect(deepEquality.hash(object1), deepEquality.hash(object2)); + }, + ); test('different collections do not produce the same hash code', () { var list = [1, 2, 3]; @@ -159,15 +192,18 @@ void main() { }); test( - 'collections with null values handled properly in hash code computation', - () { - var listWithNull = [null, 2, 3]; - var listWithoutNull = [1, 2, 3]; - // Should not throw an exception and should not be equal - expect(() => deepEquality.hash(listWithNull), returnsNormally); - expect(deepEquality.hash(listWithNull), - isNot(deepEquality.hash(listWithoutNull))); - }); + 'collections with null values handled properly in hash code computation', + () { + var listWithNull = [null, 2, 3]; + var listWithoutNull = [1, 2, 3]; + // Should not throw an exception and should not be equal + expect(() => deepEquality.hash(listWithNull), returnsNormally); + expect( + deepEquality.hash(listWithNull), + isNot(deepEquality.hash(listWithoutNull)), + ); + }, + ); test('hash code computation is efficient for large collections', () { var largeList = List.generate(100000, (index) => index); @@ -175,11 +211,13 @@ void main() { deepEquality.hash(largeList); var timeEnd = DateTime.now(); expect( - timeEnd.difference(timeStart), lessThan(const Duration(seconds: 1))); + timeEnd.difference(timeStart), + lessThan(const Duration(seconds: 1)), + ); }); test('checks nested custom object equality', () { - final nestedObj1 = AnotherCustomObject( + const nestedObj1 = AnotherCustomObject( id: 1, name: 'Nested', children: [ @@ -189,13 +227,13 @@ void main() { id: 4, name: 'Child2', children: [ - AnotherCustomObject(id: 5, name: 'Child3', children: []) + AnotherCustomObject(id: 5, name: 'Child3', children: []), ], ), ], ); - final nestedObj2 = AnotherCustomObject( + const nestedObj2 = AnotherCustomObject( id: 1, name: 'Nested', children: [ @@ -205,13 +243,13 @@ void main() { id: 4, name: 'Child2', children: [ - AnotherCustomObject(id: 5, name: 'Child3', children: []) + AnotherCustomObject(id: 5, name: 'Child3', children: []), ], ), ], ); - final nestedObjDifferent = AnotherCustomObject( + const nestedObjDifferent = AnotherCustomObject( id: 1, name: 'Nested', children: [ @@ -221,7 +259,7 @@ void main() { id: 4, name: 'ChildX', children: [ - AnotherCustomObject(id: 5, name: 'Child3', children: []) + AnotherCustomObject(id: 5, name: 'Child3', children: []), ], ), ], @@ -238,7 +276,7 @@ class CustomObject { final int id; final String value; - CustomObject({required this.id, required this.value}); + const CustomObject({required this.id, required this.value}); @override bool operator ==(Object other) { @@ -256,8 +294,11 @@ class AnotherCustomObject { final String name; final List children; - AnotherCustomObject( - {required this.id, required this.name, this.children = const []}); + const AnotherCustomObject({ + required this.id, + required this.name, + this.children = const [], + }); @override bool operator ==(Object other) => @@ -273,5 +314,7 @@ class AnotherCustomObject { id.hashCode ^ name.hashCode ^ children.fold( - 0, (previousValue, element) => previousValue ^ element.hashCode); + 0, + (previousValue, element) => previousValue ^ element.hashCode, + ); } diff --git a/test/src/helpers/iterable_ext_test.dart b/test/src/helpers/iterable_ext_test.dart index 345e1ad45..bc94e3976 100644 --- a/test/src/helpers/iterable_ext_test.dart +++ b/test/src/helpers/iterable_ext_test.dart @@ -11,7 +11,7 @@ void main() { expect(list.sorted((a, b) => b.compareTo(a)), [5, 4, 3, 2, 1]); }); - test('Mock Iterable extension methods', () { + test('Mock Iterable extension methods empty list', () { final list = []; expect(list.firstMaybeNull, null); expect(list.firstWhereOrNull((element) => element == 3), null); diff --git a/test/src/specs/container/box_attribute_test.dart b/test/src/specs/container/box_attribute_test.dart index ac51c243a..d3dca8e1d 100644 --- a/test/src/specs/container/box_attribute_test.dart +++ b/test/src/specs/container/box_attribute_test.dart @@ -9,42 +9,42 @@ void main() { test('Constructor assigns correct properties', () { final containerSpecAttribute = BoxSpecAttribute( alignment: Alignment.center, - clipBehavior: Clip.antiAlias, - constraints: const BoxConstraintsDto(maxHeight: 100), - decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), - height: 100, + padding: + const SpacingDto.only(top: 20, bottom: 20, left: 20, right: 20), margin: const SpacingDto.only( + top: 10, bottom: 10, left: 10, right: 10, - top: 10, ), - padding: - const SpacingDto.only(bottom: 20, left: 20, right: 20, top: 20), + constraints: const BoxConstraintsDto(maxHeight: 100), + decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), transform: Matrix4.identity(), + clipBehavior: Clip.antiAlias, width: 100, + height: 100, ); expect(containerSpecAttribute.alignment, Alignment.center); expect(containerSpecAttribute.clipBehavior, Clip.antiAlias); - expect(containerSpecAttribute.constraints, - const BoxConstraintsDto(maxHeight: 100)); - expect(containerSpecAttribute.decoration, - const BoxDecorationDto(color: ColorDto(Colors.blue))); + expect( + containerSpecAttribute.constraints, + const BoxConstraintsDto(maxHeight: 100), + ); + expect( + containerSpecAttribute.decoration, + const BoxDecorationDto(color: ColorDto(Colors.blue)), + ); expect(containerSpecAttribute.height, 100); expect( - containerSpecAttribute.margin, - const SpacingDto.only( - bottom: 10, - left: 10, - right: 10, - top: 10, - )); + containerSpecAttribute.margin, + const SpacingDto.only(top: 10, bottom: 10, left: 10, right: 10), + ); expect( containerSpecAttribute.padding, - const SpacingDto.only(bottom: 20, left: 20, right: 20, top: 20), + const SpacingDto.only(top: 20, bottom: 20, left: 20, right: 20), ); expect(containerSpecAttribute.transform, Matrix4.identity()); expect(containerSpecAttribute.width, 100); @@ -54,20 +54,20 @@ void main() { test('resolve() returns correct instance', () { final containerSpecAttribute = BoxSpecAttribute( alignment: Alignment.center, - clipBehavior: Clip.antiAlias, - constraints: const BoxConstraintsDto(maxHeight: 100), - decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), - height: 100, + padding: + const SpacingDto.only(top: 20, bottom: 20, left: 20, right: 20), margin: const SpacingDto.only( + top: 10, bottom: 10, left: 10, right: 10, - top: 10, ), - padding: - const SpacingDto.only(bottom: 20, left: 20, right: 20, top: 20), + constraints: const BoxConstraintsDto(maxHeight: 100), + decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), transform: Matrix4.identity(), + clipBehavior: Clip.antiAlias, width: 100, + height: 100, ); final containerSpec = containerSpecAttribute.resolve(EmptyMixData); @@ -75,22 +75,20 @@ void main() { expect(containerSpec.alignment, Alignment.center); expect(containerSpec.clipBehavior, Clip.antiAlias); - expect(containerSpec.constraints, - const BoxConstraints(maxHeight: 100, maxWidth: double.infinity)); + expect( + containerSpec.constraints, + const BoxConstraints(maxWidth: double.infinity, maxHeight: 100), + ); expect(containerSpec.decoration, const BoxDecoration(color: Colors.blue)); expect(containerSpec.height, 100); expect( - containerSpec.margin, - const EdgeInsets.only( - bottom: 10, - left: 10, - right: 10, - top: 10, - )); + containerSpec.margin, + const EdgeInsets.only(left: 10, top: 10, right: 10, bottom: 10), + ); expect( containerSpec.padding, - const EdgeInsets.only(bottom: 20, left: 20, right: 20, top: 20), + const EdgeInsets.only(left: 20, top: 20, right: 20, bottom: 20), ); expect(containerSpec.transform, Matrix4.identity()); expect(containerSpec.width, 100); @@ -100,62 +98,62 @@ void main() { test('merge() returns correct instance', () { final containerSpecAttribute = BoxSpecAttribute( alignment: Alignment.center, - clipBehavior: Clip.antiAlias, - constraints: const BoxConstraintsDto(maxHeight: 100), - decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), - height: 100, + padding: + const SpacingDto.only(top: 20, bottom: 20, left: 20, right: 20), margin: const SpacingDto.only( + top: 10, bottom: 10, left: 10, right: 10, - top: 10, ), - padding: - const SpacingDto.only(bottom: 20, left: 20, right: 20, top: 20), + constraints: const BoxConstraintsDto(maxHeight: 100), + decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), transform: Matrix4.identity(), + clipBehavior: Clip.antiAlias, width: 100, + height: 100, ); final mergedBoxSpecAttribute = containerSpecAttribute.merge( BoxSpecAttribute( alignment: Alignment.centerLeft, - clipBehavior: Clip.antiAliasWithSaveLayer, - constraints: const BoxConstraintsDto(maxHeight: 200), - decoration: const BoxDecorationDto(color: ColorDto(Colors.red)), - height: 200, + padding: + const SpacingDto.only(top: 30, bottom: 30, left: 30, right: 30), margin: const SpacingDto.only( + top: 20, bottom: 20, left: 20, right: 20, - top: 20, ), - padding: - const SpacingDto.only(bottom: 30, left: 30, right: 30, top: 30), + constraints: const BoxConstraintsDto(maxHeight: 200), + decoration: const BoxDecorationDto(color: ColorDto(Colors.red)), transform: Matrix4.identity(), + clipBehavior: Clip.antiAliasWithSaveLayer, width: 200, + height: 200, ), ); expect(mergedBoxSpecAttribute.alignment, Alignment.centerLeft); expect(mergedBoxSpecAttribute.clipBehavior, Clip.antiAliasWithSaveLayer); - expect(mergedBoxSpecAttribute.constraints, - const BoxConstraintsDto(maxHeight: 200)); - expect(mergedBoxSpecAttribute.decoration, - const BoxDecorationDto(color: ColorDto(Colors.red))); + expect( + mergedBoxSpecAttribute.constraints, + const BoxConstraintsDto(maxHeight: 200), + ); + expect( + mergedBoxSpecAttribute.decoration, + const BoxDecorationDto(color: ColorDto(Colors.red)), + ); expect(mergedBoxSpecAttribute.height, 200); expect( - mergedBoxSpecAttribute.margin, - const SpacingDto.only( - bottom: 20, - left: 20, - right: 20, - top: 20, - )); + mergedBoxSpecAttribute.margin, + const SpacingDto.only(top: 20, bottom: 20, left: 20, right: 20), + ); expect( mergedBoxSpecAttribute.padding, - const SpacingDto.only(bottom: 30, left: 30, right: 30, top: 30), + const SpacingDto.only(top: 30, bottom: 30, left: 30, right: 30), ); expect(mergedBoxSpecAttribute.transform, Matrix4.identity()); expect(mergedBoxSpecAttribute.width, 200); @@ -165,20 +163,20 @@ void main() { test('equality', () { final containerSpecAttribute = BoxSpecAttribute( alignment: Alignment.center, - clipBehavior: Clip.antiAlias, - constraints: const BoxConstraintsDto(maxHeight: 100), - decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), - height: 100, + padding: + const SpacingDto.only(top: 20, bottom: 20, left: 20, right: 20), margin: const SpacingDto.only( + top: 10, bottom: 10, left: 10, right: 10, - top: 10, ), - padding: - const SpacingDto.only(bottom: 20, left: 20, right: 20, top: 20), + constraints: const BoxConstraintsDto(maxHeight: 100), + decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), transform: Matrix4.identity(), + clipBehavior: Clip.antiAlias, width: 100, + height: 100, ); expect( @@ -186,20 +184,20 @@ void main() { equals( BoxSpecAttribute( alignment: Alignment.center, - clipBehavior: Clip.antiAlias, - constraints: const BoxConstraintsDto(maxHeight: 100), - decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), - height: 100, + padding: + const SpacingDto.only(top: 20, bottom: 20, left: 20, right: 20), margin: const SpacingDto.only( + top: 10, bottom: 10, left: 10, right: 10, - top: 10, ), - padding: - const SpacingDto.only(bottom: 20, left: 20, right: 20, top: 20), + constraints: const BoxConstraintsDto(maxHeight: 100), + decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), transform: Matrix4.identity(), + clipBehavior: Clip.antiAlias, width: 100, + height: 100, ), ), ); @@ -209,20 +207,20 @@ void main() { test('not equals', () { final containerSpecAttribute = BoxSpecAttribute( alignment: Alignment.center, - clipBehavior: Clip.antiAlias, - constraints: const BoxConstraintsDto(maxHeight: 100), - decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), - height: 100, + padding: + const SpacingDto.only(top: 20, bottom: 20, left: 20, right: 20), margin: const SpacingDto.only( + top: 10, bottom: 10, left: 10, right: 10, - top: 10, ), - padding: - const SpacingDto.only(bottom: 20, left: 20, right: 20, top: 20), + constraints: const BoxConstraintsDto(maxHeight: 100), + decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), transform: Matrix4.identity(), + clipBehavior: Clip.antiAlias, width: 100, + height: 100, ); expect( @@ -231,20 +229,24 @@ void main() { equals( BoxSpecAttribute( alignment: Alignment.centerLeft, - clipBehavior: Clip.antiAliasWithSaveLayer, - constraints: const BoxConstraintsDto(maxHeight: 200), - decoration: const BoxDecorationDto(color: ColorDto(Colors.red)), - height: 200, + padding: const SpacingDto.only( + top: 30, + bottom: 30, + left: 30, + right: 30, + ), margin: const SpacingDto.only( + top: 20, bottom: 20, left: 20, right: 20, - top: 20, ), - padding: const SpacingDto.only( - bottom: 30, left: 30, right: 30, top: 30), + constraints: const BoxConstraintsDto(maxHeight: 200), + decoration: const BoxDecorationDto(color: ColorDto(Colors.red)), transform: Matrix4.identity(), + clipBehavior: Clip.antiAliasWithSaveLayer, width: 200, + height: 200, ), ), ), diff --git a/test/src/specs/container/box_spec_test.dart b/test/src/specs/container/box_spec_test.dart index 172c9f91e..dce185929 100644 --- a/test/src/specs/container/box_spec_test.dart +++ b/test/src/specs/container/box_spec_test.dart @@ -40,10 +40,12 @@ void main() { final spec = mix.attributeOf()!.resolve(mix); expect(spec.alignment, Alignment.center); - expect(spec.padding, const EdgeInsets.only(bottom: 16.0, top: 8.0)); + expect(spec.padding, const EdgeInsets.only(top: 8.0, bottom: 16.0)); expect(spec.margin, const EdgeInsets.only(top: 10.0, bottom: 12.0)); - expect(spec.constraints, - const BoxConstraints(maxWidth: 300.0, minHeight: 200.0)); + expect( + spec.constraints, + const BoxConstraints(maxWidth: 300.0, minHeight: 200.0), + ); expect(spec.decoration, const BoxDecoration(color: Colors.blue)); expect(spec.transform, Matrix4.translationValues(10.0, 10.0, 0.0)); @@ -53,8 +55,6 @@ void main() { test('copyWith', () { final spec = BoxSpec( alignment: Alignment.center, - width: 300, - height: 200, padding: const EdgeInsets.all(16.0), margin: const EdgeInsets.only(top: 8.0, bottom: 8.0), constraints: const BoxConstraints(maxWidth: 300.0, minHeight: 200.0), @@ -62,6 +62,8 @@ void main() { foregroundDecoration: const BoxDecoration(color: Colors.purple), transform: Matrix4.translationValues(10.0, 10.0, 0.0), clipBehavior: Clip.antiAlias, + width: 300, + height: 200, ); final copiedSpec = spec.copyWith(width: 250.0, height: 150.0); @@ -69,11 +71,15 @@ void main() { expect(copiedSpec.alignment, Alignment.center); expect(copiedSpec.padding, const EdgeInsets.all(16.0)); expect(copiedSpec.margin, const EdgeInsets.only(top: 8.0, bottom: 8.0)); - expect(copiedSpec.constraints, - const BoxConstraints(maxWidth: 300.0, minHeight: 200.0)); + expect( + copiedSpec.constraints, + const BoxConstraints(maxWidth: 300.0, minHeight: 200.0), + ); expect(copiedSpec.decoration, const BoxDecoration(color: Colors.blue)); - expect(copiedSpec.foregroundDecoration, - const BoxDecoration(color: Colors.purple)); + expect( + copiedSpec.foregroundDecoration, + const BoxDecoration(color: Colors.purple), + ); expect(copiedSpec.transform, Matrix4.translationValues(10.0, 10.0, 0.0)); expect(copiedSpec.clipBehavior, Clip.antiAlias); @@ -84,8 +90,6 @@ void main() { test('lerp', () { final spec1 = BoxSpec( alignment: Alignment.topLeft, - width: 300, - height: 200, padding: const EdgeInsets.all(8.0), margin: const EdgeInsets.only(top: 4.0), constraints: const BoxConstraints(maxWidth: 200.0), @@ -93,12 +97,12 @@ void main() { foregroundDecoration: const BoxDecoration(color: Colors.blue), transform: Matrix4.identity(), clipBehavior: Clip.none, + width: 300, + height: 200, ); final spec2 = BoxSpec( alignment: Alignment.bottomRight, - width: 400, - height: 300, padding: const EdgeInsets.all(16.0), margin: const EdgeInsets.only(top: 8.0), constraints: const BoxConstraints(maxWidth: 400.0), @@ -106,46 +110,65 @@ void main() { foregroundDecoration: const BoxDecoration(color: Colors.red), transform: Matrix4.rotationZ(0.5), clipBehavior: Clip.antiAlias, + width: 400, + height: 300, ); const t = 0.5; final lerpedSpec = spec1.lerp(spec2, t); - expect(lerpedSpec.alignment, - Alignment.lerp(Alignment.topLeft, Alignment.bottomRight, t)); expect( - lerpedSpec.padding, - EdgeInsets.lerp( - const EdgeInsets.all(8.0), const EdgeInsets.all(16.0), t)); + lerpedSpec.alignment, + Alignment.lerp(Alignment.topLeft, Alignment.bottomRight, t), + ); expect( - lerpedSpec.margin, - EdgeInsets.lerp(const EdgeInsets.only(top: 4.0), - const EdgeInsets.only(top: 8.0), t)); + lerpedSpec.padding, + EdgeInsets.lerp( + const EdgeInsets.all(8.0), + const EdgeInsets.all(16.0), + t, + ), + ); expect( - lerpedSpec.constraints, - BoxConstraints.lerp(const BoxConstraints(maxWidth: 200.0), - const BoxConstraints(maxWidth: 400.0), t)); + lerpedSpec.margin, + EdgeInsets.lerp( + const EdgeInsets.only(top: 4.0), + const EdgeInsets.only(top: 8.0), + t, + ), + ); + expect( + lerpedSpec.constraints, + BoxConstraints.lerp( + const BoxConstraints(maxWidth: 200.0), + const BoxConstraints(maxWidth: 400.0), + t, + ), + ); expect( - lerpedSpec.decoration, - DecorationTween( - begin: const BoxDecoration(color: Colors.red), - end: const BoxDecoration(color: Colors.blue)) - .lerp(t)); + lerpedSpec.decoration, + DecorationTween( + begin: const BoxDecoration(color: Colors.red), + end: const BoxDecoration(color: Colors.blue), + ).lerp(t), + ); expect( - lerpedSpec.foregroundDecoration, - DecorationTween( - begin: const BoxDecoration(color: Colors.blue), - end: const BoxDecoration(color: Colors.red)) - .lerp(t)); + lerpedSpec.foregroundDecoration, + DecorationTween( + begin: const BoxDecoration(color: Colors.blue), + end: const BoxDecoration(color: Colors.red), + ).lerp(t), + ); expect(lerpedSpec.width, lerpDouble(300, 400, t)); expect(lerpedSpec.height, lerpDouble(200, 300, t)); expect( - lerpedSpec.transform, - Matrix4Tween(begin: Matrix4.identity(), end: Matrix4.rotationZ(0.5)) - .lerp(t)); + lerpedSpec.transform, + Matrix4Tween(begin: Matrix4.identity(), end: Matrix4.rotationZ(0.5)) + .lerp(t), + ); expect(lerpedSpec.clipBehavior, t < 0.5 ? Clip.none : Clip.antiAlias); }); @@ -153,8 +176,6 @@ void main() { test('equality', () { final spec1 = BoxSpec( alignment: Alignment.topLeft, - width: 300, - height: 200, padding: const EdgeInsets.all(8.0), margin: const EdgeInsets.only(top: 4.0), constraints: const BoxConstraints(maxWidth: 200.0), @@ -162,12 +183,12 @@ void main() { foregroundDecoration: const BoxDecoration(color: Colors.blue), transform: Matrix4.identity(), clipBehavior: Clip.none, + width: 300, + height: 200, ); final spec2 = BoxSpec( alignment: Alignment.topLeft, - width: 300, - height: 200, padding: const EdgeInsets.all(8.0), margin: const EdgeInsets.only(top: 4.0), constraints: const BoxConstraints(maxWidth: 200.0), @@ -175,6 +196,8 @@ void main() { foregroundDecoration: const BoxDecoration(color: Colors.blue), transform: Matrix4.identity(), clipBehavior: Clip.none, + width: 300, + height: 200, ); expect(spec1, spec2); @@ -184,72 +207,70 @@ void main() { test('merge() returns correct instance', () { final containerSpecAttribute = BoxSpecAttribute( alignment: Alignment.center, - clipBehavior: Clip.antiAlias, - constraints: const BoxConstraintsDto(maxHeight: 100), - decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), - foregroundDecoration: - const BoxDecorationDto(color: ColorDto(Colors.blue)), - height: 100, + padding: + const SpacingDto.only(top: 20, bottom: 20, left: 20, right: 20), margin: const SpacingDto.only( + top: 10, bottom: 10, left: 10, right: 10, - top: 10, ), - padding: - const SpacingDto.only(bottom: 20, left: 20, right: 20, top: 20), + constraints: const BoxConstraintsDto(maxHeight: 100), + decoration: const BoxDecorationDto(color: ColorDto(Colors.blue)), + foregroundDecoration: + const BoxDecorationDto(color: ColorDto(Colors.blue)), transform: Matrix4.identity(), + clipBehavior: Clip.antiAlias, width: 100, + height: 100, ); final mergedBoxSpecAttribute = containerSpecAttribute.merge( BoxSpecAttribute( alignment: Alignment.centerLeft, - clipBehavior: Clip.antiAliasWithSaveLayer, - constraints: const BoxConstraintsDto(maxHeight: 200), - decoration: const BoxDecorationDto(color: ColorDto(Colors.red)), - foregroundDecoration: - const BoxDecorationDto(color: ColorDto(Colors.amber)), - height: 200, + padding: + const SpacingDto.only(top: 30, bottom: 30, left: 30, right: 30), margin: const SpacingDto.only( + top: 20, bottom: 20, left: 20, right: 20, - top: 20, ), - padding: - const SpacingDto.only(bottom: 30, left: 30, right: 30, top: 30), + constraints: const BoxConstraintsDto(maxHeight: 200), + decoration: const BoxDecorationDto(color: ColorDto(Colors.red)), + foregroundDecoration: + const BoxDecorationDto(color: ColorDto(Colors.amber)), transform: Matrix4.identity(), + clipBehavior: Clip.antiAliasWithSaveLayer, width: 200, + height: 200, ), ); expect(mergedBoxSpecAttribute.alignment, Alignment.centerLeft); expect(mergedBoxSpecAttribute.clipBehavior, Clip.antiAliasWithSaveLayer); - expect(mergedBoxSpecAttribute.constraints, - const BoxConstraintsDto(maxHeight: 200)); - expect(mergedBoxSpecAttribute.decoration, - const BoxDecorationDto(color: ColorDto(Colors.red))); - expect(mergedBoxSpecAttribute.foregroundDecoration, - const BoxDecorationDto(color: ColorDto(Colors.amber))); + expect( + mergedBoxSpecAttribute.constraints, + const BoxConstraintsDto(maxHeight: 200), + ); + expect( + mergedBoxSpecAttribute.decoration, + const BoxDecorationDto(color: ColorDto(Colors.red)), + ); + expect( + mergedBoxSpecAttribute.foregroundDecoration, + const BoxDecorationDto(color: ColorDto(Colors.amber)), + ); expect(mergedBoxSpecAttribute.height, 200); expect( - mergedBoxSpecAttribute.margin, - const SpacingDto.only( - bottom: 20, - left: 20, - right: 20, - top: 20, - )); + mergedBoxSpecAttribute.margin, + const SpacingDto.only(top: 20, bottom: 20, left: 20, right: 20), + ); expect( - mergedBoxSpecAttribute.padding, - const SpacingDto.only( - bottom: 30, - left: 30, - right: 30, - top: 30, - )); + mergedBoxSpecAttribute.padding, + const SpacingDto.only(top: 30, bottom: 30, left: 30, right: 30), + ); expect(mergedBoxSpecAttribute.transform, Matrix4.identity()); expect(mergedBoxSpecAttribute.width, 200); }); diff --git a/test/src/specs/container/box_util_test.dart b/test/src/specs/container/box_util_test.dart index b2baffec7..e3166c6f3 100644 --- a/test/src/specs/container/box_util_test.dart +++ b/test/src/specs/container/box_util_test.dart @@ -3,140 +3,130 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mix/mix.dart'; void main() { - group( - 'BoxUtility', - () { - const boxUtility = BoxSpecUtility(); - test('call() returns correct instance', () { - const constraints = BoxConstraintsDto( - maxHeight: 100, - maxWidth: 200, - minWidth: 50, - minHeight: 40, - ); - - const spacing = SpacingDto.all(10); - - final container = boxUtility.only( - alignment: Alignment.center, - clipBehavior: Clip.antiAlias, - constraints: constraints, - height: 10, - margin: spacing, - padding: spacing, - transform: Matrix4.identity(), - width: 10, - ); - - expect(container.alignment, Alignment.center); - expect(container.clipBehavior, Clip.antiAlias); - - expect( - container.constraints, - constraints, - ); - - expect(container.height, 10); - expect( - container.margin, - spacing, - ); - expect( - container.padding, - spacing, - ); - expect(container.transform, Matrix4.identity()); - expect(container.width, 10); - }); - - test('alignment() returns correct instance', () { - final container = boxUtility.alignment(Alignment.center); - - expect(container.alignment, Alignment.center); - }); - - test('clipBehavior() returns correct instance', () { - final container = boxUtility.clipBehavior(Clip.antiAlias); - - expect(container.clipBehavior, Clip.antiAlias); - }); - - test('color() returns correct instance', () { - final container = boxUtility.color(Colors.blue); - - expect((container.decoration as BoxDecorationDto).color, - const ColorDto(Colors.blue)); - }); - - test('constraints() returns correct instance', () { - expect(box.constraints, isA()); - }); - - test('shape() returns correct instance', () { - expect(boxUtility.shapeDecoration, isA()); - }); - - test('height() returns correct instance', () { - final container = boxUtility.height(10); - - expect(container.height, 10); - }); - - test('margin() returns correct instance', () { - expect(boxUtility.margin, isA()); - }); - - test('padding() returns correct instance', () { - expect(boxUtility.padding, isA()); - }); - - test('transform() returns correct instance', () { - final container = boxUtility.transform(Matrix4.identity()); - - expect(container.transform, Matrix4.identity()); - }); - - test('width() returns correct instance', () { - final container = boxUtility.width(10); - - expect(container.width, 10); - }); - - test('decoration() returns correct instance', () { - final container = boxUtility.decoration( - color: Colors.amber, - borderRadius: BorderRadius.circular(10), - ); - - expect(container.decoration!.color, const ColorDto(Colors.amber)); - - final decorationDTO = container.decoration as BoxDecorationDto; - expect( - decorationDTO.borderRadius, - BorderRadiusGeometryDto.from(BorderRadius.circular(10)), - ); - }); - - test('foregroundDecoration() returns correct instance', () { - final container = boxUtility.foregroundDecoration( - color: Colors.amber, - borderRadius: BorderRadius.circular(10), - ); - - expect( - container.foregroundDecoration!.color, - const ColorDto(Colors.amber), - reason: 'The color is not correct', - ); - - final foregroundDecorationDTO = - container.foregroundDecoration as BoxDecorationDto; - expect( - foregroundDecorationDTO.borderRadius, - BorderRadiusGeometryDto.from(BorderRadius.circular(10)), - reason: 'The BorderRadius is not correct', - ); - }); - }, - ); + group('BoxUtility', () { + const boxUtility = BoxSpecUtility(); + test('call() returns correct instance', () { + const constraints = BoxConstraintsDto( + minWidth: 50, + maxWidth: 200, + minHeight: 40, + maxHeight: 100, + ); + + const spacing = SpacingDto.all(10); + + final container = boxUtility.only( + alignment: Alignment.center, + padding: spacing, + margin: spacing, + constraints: constraints, + width: 10, + height: 10, + transform: Matrix4.identity(), + clipBehavior: Clip.antiAlias, + ); + + expect(container.alignment, Alignment.center); + expect(container.clipBehavior, Clip.antiAlias); + + expect(container.constraints, constraints); + + expect(container.height, 10); + expect(container.margin, spacing); + expect(container.padding, spacing); + expect(container.transform, Matrix4.identity()); + expect(container.width, 10); + }); + + test('alignment() returns correct instance', () { + final container = boxUtility.alignment(Alignment.center); + + expect(container.alignment, Alignment.center); + }); + + test('clipBehavior() returns correct instance', () { + final container = boxUtility.clipBehavior(Clip.antiAlias); + + expect(container.clipBehavior, Clip.antiAlias); + }); + + test('color() returns correct instance', () { + final container = boxUtility.color(Colors.blue); + + expect( + (container.decoration as BoxDecorationDto).color, + const ColorDto(Colors.blue), + ); + }); + + test('constraints() returns correct instance', () { + expect(box.constraints, isA()); + }); + + test('shape() returns correct instance', () { + expect(boxUtility.shapeDecoration, isA()); + }); + + test('height() returns correct instance', () { + final container = boxUtility.height(10); + + expect(container.height, 10); + }); + + test('margin() returns correct instance', () { + expect(boxUtility.margin, isA()); + }); + + test('padding() returns correct instance', () { + expect(boxUtility.padding, isA()); + }); + + test('transform() returns correct instance', () { + final container = boxUtility.transform(Matrix4.identity()); + + expect(container.transform, Matrix4.identity()); + }); + + test('width() returns correct instance', () { + final container = boxUtility.width(10); + + expect(container.width, 10); + }); + + test('decoration() returns correct instance', () { + final container = boxUtility.decoration( + borderRadius: BorderRadius.circular(10), + color: Colors.amber, + ); + + expect(container.decoration!.color, const ColorDto(Colors.amber)); + + final decorationDTO = container.decoration as BoxDecorationDto; + expect( + decorationDTO.borderRadius, + BorderRadiusGeometryDto.from(BorderRadius.circular(10)), + ); + }); + + test('foregroundDecoration() returns correct instance', () { + final container = boxUtility.foregroundDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.amber, + ); + + expect( + container.foregroundDecoration!.color, + const ColorDto(Colors.amber), + reason: 'The color is not correct', + ); + + final foregroundDecorationDTO = + container.foregroundDecoration as BoxDecorationDto; + expect( + foregroundDecorationDTO.borderRadius, + BorderRadiusGeometryDto.from(BorderRadius.circular(10)), + reason: 'The BorderRadius is not correct', + ); + }); + }); } diff --git a/test/src/specs/container/box_widget_test.dart b/test/src/specs/container/box_widget_test.dart index fb2ed399a..df5d416d6 100644 --- a/test/src/specs/container/box_widget_test.dart +++ b/test/src/specs/container/box_widget_test.dart @@ -39,10 +39,10 @@ void main() { expect( containerWidget.decoration, BoxDecoration( + color: Colors.red, border: Border.all(color: Colors.red, width: 1, style: BorderStyle.solid), borderRadius: BorderRadius.circular(10), - color: Colors.red, ), ); }); diff --git a/test/src/specs/flex/flex_spec_test.dart b/test/src/specs/flex/flex_spec_test.dart index bfed7bed8..6d92d22b5 100644 --- a/test/src/specs/flex/flex_spec_test.dart +++ b/test/src/specs/flex/flex_spec_test.dart @@ -13,11 +13,11 @@ void main() { MockBuildContext(), Style( const FlexSpecAttribute( - crossAxisAlignment: CrossAxisAlignment.center, + direction: Axis.horizontal, mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min, verticalDirection: VerticalDirection.down, - direction: Axis.horizontal, textDirection: TextDirection.ltr, textBaseline: TextBaseline.alphabetic, clipBehavior: Clip.antiAlias, @@ -53,11 +53,11 @@ void main() { ); final copiedSpec = spec.copyWith( - crossAxisAlignment: CrossAxisAlignment.start, + direction: Axis.vertical, mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, verticalDirection: VerticalDirection.up, - direction: Axis.vertical, textDirection: TextDirection.rtl, textBaseline: TextBaseline.ideographic, clipBehavior: Clip.none, @@ -106,18 +106,9 @@ void main() { final lerpedSpec = spec1.lerp(spec2, t); expect(lerpedSpec.crossAxisAlignment, CrossAxisAlignment.end); - expect( - lerpedSpec.mainAxisAlignment, - MainAxisAlignment.end, - ); - expect( - lerpedSpec.mainAxisSize, - MainAxisSize.max, - ); - expect( - lerpedSpec.verticalDirection, - VerticalDirection.up, - ); + expect(lerpedSpec.mainAxisAlignment, MainAxisAlignment.end); + expect(lerpedSpec.mainAxisSize, MainAxisSize.max); + expect(lerpedSpec.verticalDirection, VerticalDirection.up); expect(lerpedSpec.direction, Axis.vertical); expect(lerpedSpec.textDirection, TextDirection.rtl); expect(lerpedSpec.textBaseline, TextBaseline.ideographic); diff --git a/test/src/specs/flex/flex_widget_test.dart b/test/src/specs/flex/flex_widget_test.dart index e09c3a47f..5c6b76079 100644 --- a/test/src/specs/flex/flex_widget_test.dart +++ b/test/src/specs/flex/flex_widget_test.dart @@ -6,76 +6,62 @@ import '../../../helpers/testing_utils.dart'; void main() { testWidgets( - 'Verify if widgets are wrapped with Padding when there are 2 children', - (tester) async { - await tester.pumpWidget( - VBox( - style: Style( - flex.gap(10), + 'Verify if widgets are wrapped with Padding when there are 2 children', + (tester) async { + await tester.pumpWidget( + VBox( + style: Style(flex.gap(10)), + children: const [SizedBox(), SizedBox()], ), - children: const [ - SizedBox(), - SizedBox(), - ], - ), - ); - - final mixedFlex = find.byType(MixedFlex); - - expect( - find.descendant(of: mixedFlex, matching: find.byType(Padding)), - findsNWidgets(1), - ); - }); + ); + + final mixedFlex = find.byType(MixedFlex); + + expect( + find.descendant(of: mixedFlex, matching: find.byType(Padding)), + findsNWidgets(1), + ); + }, + ); testWidgets( - 'Verify if widgets are wrapped with Padding when there are 1 children', - (tester) async { - await tester.pumpWidget( - VBox( - style: Style( - flex.gap(10), - ), - children: const [ - SizedBox(), - ], - ), - ); - - final mixedFlex = find.byType(MixedFlex); - - expect( - find.descendant(of: mixedFlex, matching: find.byType(Padding)), - findsNWidgets(0), - ); - }); + 'Verify if widgets are wrapped with Padding when there are 1 children', + (tester) async { + await tester.pumpWidget( + VBox(style: Style(flex.gap(10)), children: const [SizedBox()]), + ); - test('Verify if widgets are wrapped with Padding when there are 3 children', - () { - var sut = MixedFlex( - mix: EmptyMixData, - direction: Axis.horizontal, - children: const [ - SizedBox(), - SizedBox(), - SizedBox(), - ], - ).buildChildren(10); + final mixedFlex = find.byType(MixedFlex); - expect(sut.length, 3); + expect( + find.descendant(of: mixedFlex, matching: find.byType(Padding)), + findsNWidgets(0), + ); + }, + ); - for (var i = 0; i < sut.length; i++) { - expect(sut[i], i == sut.length - 1 ? isA() : isA()); - } - }); + test( + 'Verify if widgets are wrapped with Padding when there are 3 children', + () { + var sut = MixedFlex( + mix: EmptyMixData, + direction: Axis.horizontal, + children: const [SizedBox(), SizedBox(), SizedBox()], + ).buildChildren(10); + + expect(sut.length, 3); + + for (var i = 0; i < sut.length; i++) { + expect(sut[i], i == sut.length - 1 ? isA() : isA()); + } + }, + ); test('Verify if widgets are wrapped with Padding when there is 1 child', () { var sut = MixedFlex( mix: EmptyMixData, direction: Axis.horizontal, - children: const [ - SizedBox(), - ], + children: const [SizedBox()], ).buildChildren(10); expect(sut.length, 1); @@ -86,54 +72,50 @@ void main() { }); test( - 'Verify if when MixedFlex has direction horizontal the padding is only in the right', - () { - var sut = MixedFlex( - mix: EmptyMixData, - direction: Axis.horizontal, - children: const [ - SizedBox(), - SizedBox(), - ], - ).buildChildren(10); - - for (var i = 0; i < sut.length; i++) { - if (i == sut.length - 1) continue; - - final paddingWidget = sut[i] as Padding; - final edgeInsets = paddingWidget.padding.resolve(TextDirection.ltr); - - expect(edgeInsets.right, 10); - expect(edgeInsets.left, 0); - expect(edgeInsets.top, 0); - expect(edgeInsets.bottom, 0); - } - }); + 'Verify if when MixedFlex has direction horizontal the padding is only in the right', + () { + var sut = MixedFlex( + mix: EmptyMixData, + direction: Axis.horizontal, + children: const [SizedBox(), SizedBox()], + ).buildChildren(10); + + for (var i = 0; i < sut.length; i++) { + if (i == sut.length - 1) continue; + + final paddingWidget = sut[i] as Padding; + final edgeInsets = paddingWidget.padding.resolve(TextDirection.ltr); + + expect(edgeInsets.right, 10); + expect(edgeInsets.left, 0); + expect(edgeInsets.top, 0); + expect(edgeInsets.bottom, 0); + } + }, + ); test( - 'Verify if when MixedFlex has direction horizontal the padding is only in the right', - () { - var sut = MixedFlex( - mix: EmptyMixData, - direction: Axis.vertical, - children: const [ - SizedBox(), - SizedBox(), - ], - ).buildChildren(10); - - for (var i = 0; i < sut.length; i++) { - if (i == sut.length - 1) continue; - - final paddingWidget = sut[i] as Padding; - final edgeInsets = paddingWidget.padding.resolve(TextDirection.ltr); - - expect(edgeInsets.right, 0); - expect(edgeInsets.left, 0); - expect(edgeInsets.top, 0); - expect(edgeInsets.bottom, 10); - } - }); + 'Verify if when MixedFlex has direction vertical the padding is only in the right', + () { + var sut = MixedFlex( + mix: EmptyMixData, + direction: Axis.vertical, + children: const [SizedBox(), SizedBox()], + ).buildChildren(10); + + for (var i = 0; i < sut.length; i++) { + if (i == sut.length - 1) continue; + + final paddingWidget = sut[i] as Padding; + final edgeInsets = paddingWidget.padding.resolve(TextDirection.ltr); + + expect(edgeInsets.right, 0); + expect(edgeInsets.left, 0); + expect(edgeInsets.top, 0); + expect(edgeInsets.bottom, 10); + } + }, + ); testWidgets( 'HBox with gap() rendered correctly in complex widget tree', @@ -145,13 +127,8 @@ void main() { Row( children: [ HBox( - style: Style( - flex.gap(10), - ), - children: const [ - StyledText('test'), - StyledText('case'), - ], + style: Style(flex.gap(10)), + children: const [StyledText('test'), StyledText('case')], ), ], ), @@ -172,13 +149,8 @@ void main() { Column( children: [ VBox( - style: Style( - flex.gap(10), - ), - children: const [ - StyledText('test'), - StyledText('case'), - ], + style: Style(flex.gap(10)), + children: const [StyledText('test'), StyledText('case')], ), ], ), diff --git a/test/src/specs/icon/icon_attribute_test.dart b/test/src/specs/icon/icon_attribute_test.dart index e4177d7e4..410cf0551 100644 --- a/test/src/specs/icon/icon_attribute_test.dart +++ b/test/src/specs/icon/icon_attribute_test.dart @@ -5,42 +5,30 @@ import 'package:mix/mix.dart'; import '../../../helpers/testing_utils.dart'; void main() { - group( - 'IconMixAttribute', - () { - test( - 'resolve should return an instance of IconSpec', - () { - const attribute = IconSpecAttribute(); - final resolvedSpec = attribute.resolve(EmptyMixData); - expect(resolvedSpec, isA()); - }, - ); + group('IconMixAttribute', () { + test('resolve should return an instance of IconSpec', () { + const attribute = IconSpecAttribute(); + final resolvedSpec = attribute.resolve(EmptyMixData); + expect(resolvedSpec, isA()); + }); - test( - 'merge should return a new instance of IconMixAttribute', - () { - const attribute1 = - IconSpecAttribute(size: 24, color: ColorDto(Colors.red)); - const attribute2 = - IconSpecAttribute(size: 32, color: ColorDto(Colors.green)); - final mergedAttribute = attribute1.merge(attribute2); - expect(mergedAttribute, isA()); - expect(mergedAttribute.size, equals(32)); - expect(mergedAttribute.color, equals(const ColorDto(Colors.green))); - }, - ); + test('merge should return a new instance of IconMixAttribute', () { + const attribute1 = + IconSpecAttribute(size: 24, color: ColorDto(Colors.red)); + const attribute2 = + IconSpecAttribute(size: 32, color: ColorDto(Colors.green)); + final mergedAttribute = attribute1.merge(attribute2); + expect(mergedAttribute, isA()); + expect(mergedAttribute.size, equals(32)); + expect(mergedAttribute.color, equals(const ColorDto(Colors.green))); + }); - test( - 'props should return a list of size and color', - () { - const attribute = - IconSpecAttribute(size: 24, color: ColorDto(Colors.red)); - final props = attribute.props; - expect(props, contains(24)); - expect(props, contains(const ColorDto(Colors.red))); - }, - ); - }, - ); + test('props should return a list of size and color', () { + const attribute = + IconSpecAttribute(size: 24, color: ColorDto(Colors.red)); + final props = attribute.props; + expect(props, contains(24)); + expect(props, contains(const ColorDto(Colors.red))); + }); + }); } diff --git a/test/src/specs/icon/icon_spec_test.dart b/test/src/specs/icon/icon_spec_test.dart index d7a067e1d..81e53ed65 100644 --- a/test/src/specs/icon/icon_spec_test.dart +++ b/test/src/specs/icon/icon_spec_test.dart @@ -12,9 +12,7 @@ void main() { test('resolve', () { final mix = MixData.create( MockBuildContext(), - Style( - IconSpecAttribute(color: Colors.red.toDto(), size: 20.0), - ), + Style(IconSpecAttribute(size: 20.0, color: Colors.red.toDto())), ); final spec = IconSpec.of(mix); @@ -24,10 +22,7 @@ void main() { }); test('copyWith', () { - const spec = IconSpec( - color: Colors.red, - size: 20.0, - ); + const spec = IconSpec(color: Colors.red, size: 20.0); final copiedSpec = spec.copyWith(color: Colors.blue, size: 30.0); @@ -36,15 +31,9 @@ void main() { }); test('lerp', () { - const spec1 = IconSpec( - color: Colors.red, - size: 20.0, - ); + const spec1 = IconSpec(color: Colors.red, size: 20.0); - const spec2 = IconSpec( - color: Colors.blue, - size: 30.0, - ); + const spec2 = IconSpec(color: Colors.blue, size: 30.0); const t = 0.5; final lerpedSpec = spec1.lerp(spec2, t); diff --git a/test/src/specs/icon_spec_test.dart b/test/src/specs/icon_spec_test.dart index f4034ccc1..46285ce0b 100644 --- a/test/src/specs/icon_spec_test.dart +++ b/test/src/specs/icon_spec_test.dart @@ -12,9 +12,7 @@ void main() { test('resolve', () { final mix = MixData.create( MockBuildContext(), - Style( - IconSpecAttribute(color: Colors.red.toDto(), size: 20.0), - ), + Style(IconSpecAttribute(size: 20.0, color: Colors.red.toDto())), ); final spec = IconSpec.of(mix); @@ -24,10 +22,7 @@ void main() { }); test('copyWith', () { - const spec = IconSpec( - color: Colors.red, - size: 20.0, - ); + const spec = IconSpec(color: Colors.red, size: 20.0); final copiedSpec = spec.copyWith(color: Colors.blue, size: 30.0); @@ -36,15 +31,9 @@ void main() { }); test('lerp', () { - const spec1 = IconSpec( - color: Colors.red, - size: 20.0, - ); + const spec1 = IconSpec(color: Colors.red, size: 20.0); - const spec2 = IconSpec( - color: Colors.blue, - size: 30.0, - ); + const spec2 = IconSpec(color: Colors.blue, size: 30.0); const t = 0.5; final lerpedSpec = spec1.lerp(spec2, t); diff --git a/test/src/specs/image/image_attribute_test.dart b/test/src/specs/image/image_attribute_test.dart index 2626f5f52..560b67c66 100644 --- a/test/src/specs/image/image_attribute_test.dart +++ b/test/src/specs/image/image_attribute_test.dart @@ -50,15 +50,15 @@ void main() { test('props returns correct list of properties', () { const attribute = ImageSpecAttribute( + centerSlice: Rect.zero, width: 100, height: 200, color: ColorDto(Colors.black), repeat: ImageRepeat.repeat, fit: BoxFit.cover, alignment: Alignment.bottomCenter, - centerSlice: Rect.zero, - filterQuality: FilterQuality.low, colorBlendMode: BlendMode.srcOver, + filterQuality: FilterQuality.low, ); final props = attribute.props; diff --git a/test/src/specs/image/image_widget_test.dart b/test/src/specs/image/image_widget_test.dart index b6394c036..bf9efea66 100644 --- a/test/src/specs/image/image_widget_test.dart +++ b/test/src/specs/image/image_widget_test.dart @@ -63,26 +63,28 @@ void main() { expect(opacityWidget.opacity, 0.5); }); - testWidgets('can inherit style from the parent StyledWidget', - (WidgetTester tester) async { - await tester.pumpWidget( - Box( - style: Style( - image.width(152), - image.height(152), - image.color.black(), - ), - child: const StyledImage( - image: AssetImage('test_resources/logo.png'), + testWidgets( + 'can inherit style from the parent StyledWidget', + (WidgetTester tester) async { + await tester.pumpWidget( + Box( + style: Style( + image.width(152), + image.height(152), + image.color.black(), + ), + child: const StyledImage( + image: AssetImage('test_resources/logo.png'), + ), ), - ), - ); + ); - final imageWidget = tester.element(find.byType(Image)).widget as Image; + final imageWidget = tester.element(find.byType(Image)).widget as Image; - expect(imageWidget.width, 152); - expect(imageWidget.height, 152); - expect(imageWidget.color, Colors.black); - }); + expect(imageWidget.width, 152); + expect(imageWidget.height, 152); + expect(imageWidget.color, Colors.black); + }, + ); }); } diff --git a/test/src/specs/stack/stack_attribute_test.dart b/test/src/specs/stack/stack_attribute_test.dart index 440f4c64d..6b3df2c26 100644 --- a/test/src/specs/stack/stack_attribute_test.dart +++ b/test/src/specs/stack/stack_attribute_test.dart @@ -7,18 +7,19 @@ import '../../../helpers/testing_utils.dart'; void main() { group('StackMixAttribute', () { test( - 'of returns default attribute when mix does not have StackMixAttribute', - () { - final mix = MixData.create(MockBuildContext(), Style()); - final attribute = StackSpecAttribute.of(mix); + 'of returns default attribute when mix does not have StackMixAttribute', + () { + final mix = MixData.create(MockBuildContext(), Style()); + final attribute = StackSpecAttribute.of(mix); - final resolved = attribute.resolve(mix); + final resolved = attribute.resolve(mix); - expect(resolved.alignment, null); - expect(resolved.fit, null); - expect(resolved.textDirection, null); - expect(resolved.clipBehavior, null); - }); + expect(resolved.alignment, null); + expect(resolved.fit, null); + expect(resolved.textDirection, null); + expect(resolved.clipBehavior, null); + }, + ); test('resolve returns correct StackSpec', () { const attribute = StackSpecAttribute( diff --git a/test/src/specs/stack/stack_spec_test.dart b/test/src/specs/stack/stack_spec_test.dart index dee4588ad..cbab55a90 100644 --- a/test/src/specs/stack/stack_spec_test.dart +++ b/test/src/specs/stack/stack_spec_test.dart @@ -11,10 +11,10 @@ void main() { MockBuildContext(), Style( const StackSpecAttribute( - fit: StackFit.expand, - clipBehavior: Clip.antiAlias, alignment: Alignment.center, + fit: StackFit.expand, textDirection: TextDirection.ltr, + clipBehavior: Clip.antiAlias, ), ), ); @@ -66,8 +66,10 @@ void main() { const t = 0.5; final lerpedSpec = spec1.lerp(spec2, t); - expect(lerpedSpec.alignment, - Alignment.lerp(Alignment.topLeft, Alignment.bottomRight, t)); + expect( + lerpedSpec.alignment, + Alignment.lerp(Alignment.topLeft, Alignment.bottomRight, t), + ); expect(lerpedSpec.fit, StackFit.expand); expect(lerpedSpec.textDirection, TextDirection.rtl); expect(lerpedSpec.clipBehavior, Clip.antiAlias); diff --git a/test/src/specs/stack/stack_widget_test.dart b/test/src/specs/stack/stack_widget_test.dart index 96982baa0..fc1bf1daf 100644 --- a/test/src/specs/stack/stack_widget_test.dart +++ b/test/src/specs/stack/stack_widget_test.dart @@ -16,16 +16,8 @@ void main() { StyledStack( style: style, children: [ - Container( - height: 100, - width: 100, - color: const Color(0xFF000000), - ), - Container( - height: 50, - width: 50, - color: const Color(0xFF0000FF), - ), + Container(color: const Color(0xFF000000), width: 100, height: 100), + Container(color: const Color(0xFF0000FF), width: 50, height: 50), ], ), ); @@ -49,12 +41,7 @@ void main() { backgroundColor(Colors.red), ); - await tester.pumpMaterialApp( - ZBox( - style: style, - children: const [], - ), - ); + await tester.pumpMaterialApp(ZBox(style: style, children: const [])); final stackWidget = tester.widget(find.byType(Stack)); final container = tester.widget(find.byType(Container)); diff --git a/test/src/specs/text/text_attribute_test.dart b/test/src/specs/text/text_attribute_test.dart index 2f0cca386..9f8422ae7 100644 --- a/test/src/specs/text/text_attribute_test.dart +++ b/test/src/specs/text/text_attribute_test.dart @@ -17,9 +17,9 @@ void main() { textScaleFactor: 1.5, maxLines: 2, style: TextStyleDto.only( - fontFamily: 'Roboto', fontSize: 12, fontWeight: FontWeight.w500, + fontFamily: 'Roboto', ), textWidthBasis: TextWidthBasis.longestLine, textHeightBehavior: const TextHeightBehavior( @@ -57,9 +57,9 @@ void main() { textScaleFactor: 1.5, maxLines: 2, style: TextStyleDto.only( - fontFamily: 'Helvetica', fontSize: 16, fontWeight: FontWeight.w200, + fontFamily: 'Helvetica', ), textWidthBasis: TextWidthBasis.longestLine, textHeightBehavior: const TextHeightBehavior( diff --git a/test/src/specs/text/text_spec_test.dart b/test/src/specs/text/text_spec_test.dart index 5eed6b997..65b1c4d45 100644 --- a/test/src/specs/text/text_spec_test.dart +++ b/test/src/specs/text/text_spec_test.dart @@ -12,17 +12,17 @@ void main() { Style( TextSpecAttribute( overflow: TextOverflow.ellipsis, - textDirection: TextDirection.ltr, - textAlign: TextAlign.center, - style: TextStyleDto.only(color: const ColorDto(Colors.red)), strutStyle: const StrutStyleDto(fontSize: 20.0), + textAlign: TextAlign.center, textScaleFactor: 1.0, maxLines: 2, + style: TextStyleDto.only(color: const ColorDto(Colors.red)), textWidthBasis: TextWidthBasis.longestLine, textHeightBehavior: const TextHeightBehavior( applyHeightToFirstAscent: true, applyHeightToLastDescent: true, ), + textDirection: TextDirection.ltr, softWrap: true, ), ), @@ -39,9 +39,12 @@ void main() { expect(spec.style, const TextStyle(color: Colors.red)); expect(spec.textWidthBasis, TextWidthBasis.longestLine); expect( - spec.textHeightBehavior, - const TextHeightBehavior( - applyHeightToFirstAscent: true, applyHeightToLastDescent: true)); + spec.textHeightBehavior, + const TextHeightBehavior( + applyHeightToFirstAscent: true, + applyHeightToLastDescent: true, + ), + ); expect(spec.textDirection, TextDirection.ltr); expect(spec.softWrap, true); }); @@ -56,12 +59,15 @@ void main() { style: TextStyle(color: Colors.red), textWidthBasis: TextWidthBasis.longestLine, textHeightBehavior: TextHeightBehavior( - applyHeightToFirstAscent: true, applyHeightToLastDescent: true), + applyHeightToFirstAscent: true, + applyHeightToLastDescent: true, + ), textDirection: TextDirection.ltr, softWrap: true, ); final copiedSpec = spec.copyWith( + softWrap: false, overflow: TextOverflow.fade, strutStyle: const StrutStyle(fontSize: 30.0), textAlign: TextAlign.start, @@ -70,9 +76,10 @@ void main() { style: const TextStyle(color: Colors.blue), textWidthBasis: TextWidthBasis.parent, textHeightBehavior: const TextHeightBehavior( - applyHeightToFirstAscent: false, applyHeightToLastDescent: false), + applyHeightToFirstAscent: false, + applyHeightToLastDescent: false, + ), textDirection: TextDirection.rtl, - softWrap: false, ); expect(copiedSpec.overflow, TextOverflow.fade); @@ -83,10 +90,12 @@ void main() { expect(copiedSpec.style, const TextStyle(color: Colors.blue)); expect(copiedSpec.textWidthBasis, TextWidthBasis.parent); expect( - copiedSpec.textHeightBehavior, - const TextHeightBehavior( - applyHeightToFirstAscent: false, - applyHeightToLastDescent: false)); + copiedSpec.textHeightBehavior, + const TextHeightBehavior( + applyHeightToFirstAscent: false, + applyHeightToLastDescent: false, + ), + ); expect(copiedSpec.textDirection, TextDirection.rtl); expect(copiedSpec.softWrap, false); @@ -135,17 +144,22 @@ void main() { expect(lerpedSpec.textScaleFactor, 1.5); expect(lerpedSpec.maxLines, 3); expect( - lerpedSpec.style, - TextStyle.lerp(const TextStyle(color: Colors.red), - const TextStyle(color: Colors.blue), t)); + lerpedSpec.style, + TextStyle.lerp( + const TextStyle(color: Colors.red), + const TextStyle(color: Colors.blue), + t, + ), + ); expect(lerpedSpec.textWidthBasis, TextWidthBasis.parent); expect( - lerpedSpec.textHeightBehavior, - const TextHeightBehavior( - applyHeightToFirstAscent: false, - applyHeightToLastDescent: false, - )); + lerpedSpec.textHeightBehavior, + const TextHeightBehavior( + applyHeightToFirstAscent: false, + applyHeightToLastDescent: false, + ), + ); expect(lerpedSpec.textDirection, TextDirection.rtl); expect(lerpedSpec.softWrap, false); diff --git a/test/src/theme/material/material_tokens_test.dart b/test/src/theme/material/material_tokens_test.dart index cdb34ebe0..cdb472de6 100644 --- a/test/src/theme/material/material_tokens_test.dart +++ b/test/src/theme/material/material_tokens_test.dart @@ -9,7 +9,8 @@ import '../../../helpers/testing_utils.dart'; void main() { // Create a test that checks if all the values of these tokens match the ThemeData from the MaterialApp group('Material tokens', () { - Value refResolver, T extends MixToken, + // ignore: avoid-unused-generics + Value refResolver, R extends TokenRef, Value>(R ref, BuildContext context) { return ref.token.resolve(context); } @@ -24,24 +25,40 @@ void main() { final colors = const MaterialTokens().colorScheme; expect(refResolver(colors.primary(), context), theme.colorScheme.primary); - expect(refResolver(colors.secondary(), context), - theme.colorScheme.secondary); expect( - refResolver(colors.tertiary(), context), theme.colorScheme.tertiary); + refResolver(colors.secondary(), context), + theme.colorScheme.secondary, + ); + expect( + refResolver(colors.tertiary(), context), + theme.colorScheme.tertiary, + ); expect(refResolver(colors.surface(), context), theme.colorScheme.surface); - expect(refResolver(colors.background(), context), - theme.colorScheme.background); + expect( + refResolver(colors.background(), context), + theme.colorScheme.background, + ); expect(refResolver(colors.error(), context), theme.colorScheme.error); - expect(refResolver(colors.onPrimary(), context), - theme.colorScheme.onPrimary); - expect(refResolver(colors.onSecondary(), context), - theme.colorScheme.onSecondary); - expect(refResolver(colors.onTertiary(), context), - theme.colorScheme.onTertiary); - expect(refResolver(colors.onSurface(), context), - theme.colorScheme.onSurface); - expect(refResolver(colors.onBackground(), context), - theme.colorScheme.onBackground); + expect( + refResolver(colors.onPrimary(), context), + theme.colorScheme.onPrimary, + ); + expect( + refResolver(colors.onSecondary(), context), + theme.colorScheme.onSecondary, + ); + expect( + refResolver(colors.onTertiary(), context), + theme.colorScheme.onTertiary, + ); + expect( + refResolver(colors.onSurface(), context), + theme.colorScheme.onSurface, + ); + expect( + refResolver(colors.onBackground(), context), + theme.colorScheme.onBackground, + ); expect(refResolver(colors.onError(), context), theme.colorScheme.onError); }); @@ -55,36 +72,66 @@ void main() { final theme = Theme.of(context); final textStyles = const MaterialTokens().textTheme; - expect(refResolver(textStyles.displayLarge(), context), - theme.textTheme.displayLarge); - expect(refResolver(textStyles.displayMedium(), context), - theme.textTheme.displayMedium); - expect(refResolver(textStyles.displaySmall(), context), - theme.textTheme.displaySmall); - expect(refResolver(textStyles.headlineLarge(), context), - theme.textTheme.headlineLarge); - expect(refResolver(textStyles.headlineMedium(), context), - theme.textTheme.headlineMedium); - expect(refResolver(textStyles.headlineSmall(), context), - theme.textTheme.headlineSmall); - expect(refResolver(textStyles.titleLarge(), context), - theme.textTheme.titleLarge); - expect(refResolver(textStyles.titleMedium(), context), - theme.textTheme.titleMedium); - expect(refResolver(textStyles.titleSmall(), context), - theme.textTheme.titleSmall); - expect(refResolver(textStyles.bodyLarge(), context), - theme.textTheme.bodyLarge); - expect(refResolver(textStyles.bodyMedium(), context), - theme.textTheme.bodyMedium); - expect(refResolver(textStyles.bodySmall(), context), - theme.textTheme.bodySmall); - expect(refResolver(textStyles.labelLarge(), context), - theme.textTheme.labelLarge); - expect(refResolver(textStyles.labelMedium(), context), - theme.textTheme.labelMedium); - expect(refResolver(textStyles.labelSmall(), context), - theme.textTheme.labelSmall); + expect( + refResolver(textStyles.displayLarge(), context), + theme.textTheme.displayLarge, + ); + expect( + refResolver(textStyles.displayMedium(), context), + theme.textTheme.displayMedium, + ); + expect( + refResolver(textStyles.displaySmall(), context), + theme.textTheme.displaySmall, + ); + expect( + refResolver(textStyles.headlineLarge(), context), + theme.textTheme.headlineLarge, + ); + expect( + refResolver(textStyles.headlineMedium(), context), + theme.textTheme.headlineMedium, + ); + expect( + refResolver(textStyles.headlineSmall(), context), + theme.textTheme.headlineSmall, + ); + expect( + refResolver(textStyles.titleLarge(), context), + theme.textTheme.titleLarge, + ); + expect( + refResolver(textStyles.titleMedium(), context), + theme.textTheme.titleMedium, + ); + expect( + refResolver(textStyles.titleSmall(), context), + theme.textTheme.titleSmall, + ); + expect( + refResolver(textStyles.bodyLarge(), context), + theme.textTheme.bodyLarge, + ); + expect( + refResolver(textStyles.bodyMedium(), context), + theme.textTheme.bodyMedium, + ); + expect( + refResolver(textStyles.bodySmall(), context), + theme.textTheme.bodySmall, + ); + expect( + refResolver(textStyles.labelLarge(), context), + theme.textTheme.labelLarge, + ); + expect( + refResolver(textStyles.labelMedium(), context), + theme.textTheme.labelMedium, + ); + expect( + refResolver(textStyles.labelSmall(), context), + theme.textTheme.labelSmall, + ); }); testWidgets('Material 2 text styles', (tester) async { @@ -97,31 +144,55 @@ void main() { final theme = Theme.of(context); final textStyles = const MaterialTokens().textTheme; - expect(refResolver(textStyles.headline1(), context), - theme.textTheme.headline1); - expect(refResolver(textStyles.headline2(), context), - theme.textTheme.headline2); - expect(refResolver(textStyles.headline3(), context), - theme.textTheme.headline3); - expect(refResolver(textStyles.headline4(), context), - theme.textTheme.headline4); - expect(refResolver(textStyles.headline5(), context), - theme.textTheme.headline5); - expect(refResolver(textStyles.headline6(), context), - theme.textTheme.headline6); - expect(refResolver(textStyles.subtitle1(), context), - theme.textTheme.subtitle1); - expect(refResolver(textStyles.subtitle2(), context), - theme.textTheme.subtitle2); - expect(refResolver(textStyles.bodyText1(), context), - theme.textTheme.bodyText1); - expect(refResolver(textStyles.bodyText2(), context), - theme.textTheme.bodyText2); - expect( - refResolver(textStyles.caption(), context), theme.textTheme.caption); + expect( + refResolver(textStyles.headline1(), context), + theme.textTheme.headline1, + ); + expect( + refResolver(textStyles.headline2(), context), + theme.textTheme.headline2, + ); + expect( + refResolver(textStyles.headline3(), context), + theme.textTheme.headline3, + ); + expect( + refResolver(textStyles.headline4(), context), + theme.textTheme.headline4, + ); + expect( + refResolver(textStyles.headline5(), context), + theme.textTheme.headline5, + ); + expect( + refResolver(textStyles.headline6(), context), + theme.textTheme.headline6, + ); + expect( + refResolver(textStyles.subtitle1(), context), + theme.textTheme.subtitle1, + ); + expect( + refResolver(textStyles.subtitle2(), context), + theme.textTheme.subtitle2, + ); + expect( + refResolver(textStyles.bodyText1(), context), + theme.textTheme.bodyText1, + ); + expect( + refResolver(textStyles.bodyText2(), context), + theme.textTheme.bodyText2, + ); + expect( + refResolver(textStyles.caption(), context), + theme.textTheme.caption, + ); expect(refResolver(textStyles.button(), context), theme.textTheme.button); - expect(refResolver(textStyles.overline(), context), - theme.textTheme.overline); + expect( + refResolver(textStyles.overline(), context), + theme.textTheme.overline, + ); }); }); } diff --git a/test/src/theme/mix_theme_test.dart b/test/src/theme/mix_theme_test.dart index 90c4c4fcc..9edd54e09 100644 --- a/test/src/theme/mix_theme_test.dart +++ b/test/src/theme/mix_theme_test.dart @@ -7,29 +7,24 @@ import '../../helpers/testing_utils.dart'; void main() { const primaryColor = ColorToken('primary'); final theme = MixThemeData( + breakpoints: { + $breakpoints.small: const Breakpoint(minWidth: 0, maxWidth: 599), + }, colors: { primaryColor: Colors.blue, $md.colorScheme.error: Colors.redAccent, }, - breakpoints: { - $breakpoints.small: const Breakpoint( - minWidth: 0, - maxWidth: 599, - ), - }, - radii: { - $radii.small: const Radius.circular(200), - $radii.large: const Radius.circular(2000), - }, - space: { - $space.small: 30, - }, + space: {$space.small: 30}, textStyles: { $md.textTheme.bodyLarge: const TextStyle( fontSize: 200, fontWeight: FontWeight.w300, ), }, + radii: { + $radii.small: const Radius.circular(200), + $radii.large: const Radius.circular(2000), + }, ); group('MixTheme', () { @@ -43,56 +38,48 @@ void main() { }); testWidgets( - 'when applied to Box via Style, it must reproduce the same values than the theme', - (tester) async { - const key = Key('box'); + 'when applied to Box via Style, it must reproduce the same values than the theme', + (tester) async { + const key = Key('box'); - await tester.pumpWithMixTheme( - Box( - key: key, - style: Style( - box.color.of(primaryColor), - box.borderRadius.all.of($radii.small), - box.padding.horizontal.of($space.small), - text.style.of($md.textTheme.bodyLarge), + await tester.pumpWithMixTheme( + Box( + style: Style( + box.color.of(primaryColor), + box.borderRadius.all.of($radii.small), + box.padding.horizontal.of($space.small), + text.style.of($md.textTheme.bodyLarge), + ), + key: key, + child: const StyledText('Hello'), ), - child: const StyledText('Hello'), - ), - theme: theme, - ); + theme: theme, + ); - final container = tester.widget( - find.descendant( - of: find.byKey(key), - matching: find.byType(Container), - ), - ); + final container = tester.widget( + find.descendant( + of: find.byKey(key), + matching: find.byType(Container), + ), + ); - expect( - container.decoration, - BoxDecoration( - color: theme.colors[primaryColor], - borderRadius: BorderRadius.all(theme.radii[$radii.small]!), - ), - ); + expect( + container.decoration, + BoxDecoration( + color: theme.colors[primaryColor], + borderRadius: BorderRadius.all(theme.radii[$radii.small]!), + ), + ); - expect( - container.padding!.horizontal / 2, - theme.space[$space.small], - ); + expect(container.padding!.horizontal / 2, theme.space[$space.small]); - final textWidget = tester.widget( - find.descendant( - of: find.byKey(key), - matching: find.byType(Text), - ), - ); + final textWidget = tester.widget( + find.descendant(of: find.byKey(key), matching: find.byType(Text)), + ); - expect( - textWidget.style, - theme.textStyles[$md.textTheme.bodyLarge], - ); - }); + expect(textWidget.style, theme.textStyles[$md.textTheme.bodyLarge]); + }, + ); // maybeOf testWidgets('MixTheme.maybeOf', (tester) async { diff --git a/test/src/theme/tokens/breakpoints_token_test.dart b/test/src/theme/tokens/breakpoints_token_test.dart index 1a167fa7a..04ff86a0e 100644 --- a/test/src/theme/tokens/breakpoints_token_test.dart +++ b/test/src/theme/tokens/breakpoints_token_test.dart @@ -16,18 +16,9 @@ void main() { large, const Breakpoint(minWidth: 1440, maxWidth: double.infinity), ); - expect( - medium, - const Breakpoint(minWidth: 1024, maxWidth: 1439), - ); - expect( - small, - const Breakpoint(minWidth: 600, maxWidth: 1023), - ); - expect( - xsmall, - const Breakpoint(minWidth: 0, maxWidth: 599), - ); + expect(medium, const Breakpoint(minWidth: 1024, maxWidth: 1439)); + expect(small, const Breakpoint(minWidth: 600, maxWidth: 1023)); + expect(xsmall, const Breakpoint(minWidth: 0, maxWidth: 599)); }); test('MixBreakpointsTokens large matches correctly', () { @@ -35,15 +26,9 @@ void main() { final large = breakpoints[BreakpointToken.large]!; - expect( - large.matches(const Size(1440, 1024)), - true, - ); + expect(large.matches(const Size(1440, 1024)), true); - expect( - large.matches(const Size(1439, 1024)), - false, - ); + expect(large.matches(const Size(1439, 1024)), false); }); test('MixBreakpointsTokens medium matches correctly', () { @@ -51,15 +36,9 @@ void main() { final medium = breakpoints[BreakpointToken.medium]!; - expect( - medium.matches(const Size(1024, 1024)), - true, - ); + expect(medium.matches(const Size(1024, 1024)), true); - expect( - medium.matches(const Size(1023, 1024)), - false, - ); + expect(medium.matches(const Size(1023, 1024)), false); }); test('MixBreakpointsTokens small matches correctly', () { @@ -67,15 +46,9 @@ void main() { final small = breakpoints[BreakpointToken.small]!; - expect( - small.matches(const Size(600, 1024)), - true, - ); + expect(small.matches(const Size(600, 1024)), true); - expect( - small.matches(const Size(599, 1024)), - false, - ); + expect(small.matches(const Size(599, 1024)), false); }); test('MixBreakpointsTokens xsmall matches correctly', () { @@ -83,14 +56,8 @@ void main() { final xsmall = breakpoints[BreakpointToken.xsmall]!; - expect( - xsmall.matches(const Size(0, 1024)), - true, - ); + expect(xsmall.matches(const Size(0, 1024)), true); - expect( - xsmall.matches(const Size(-1, 1024)), - false, - ); + expect(xsmall.matches(const Size(-1, 1024)), false); }); } diff --git a/test/src/theme/tokens/radius_token_test.dart b/test/src/theme/tokens/radius_token_test.dart index da492b085..1684e7dd0 100644 --- a/test/src/theme/tokens/radius_token_test.dart +++ b/test/src/theme/tokens/radius_token_test.dart @@ -50,9 +50,13 @@ void main() { expect(mixData.tokens.radiiToken(redRadiusRef), const Radius.circular(1)); expect( - mixData.tokens.radiiToken(greenRadiusRef), const Radius.circular(2)); + mixData.tokens.radiiToken(greenRadiusRef), + const Radius.circular(2), + ); expect( - mixData.tokens.radiiToken(blueRadiusRef), const Radius.circular(3)); + mixData.tokens.radiiToken(blueRadiusRef), + const Radius.circular(3), + ); }); }); @@ -70,19 +74,13 @@ void main() { }); }); - group( - 'UtilityWithRadiusTokens', - () { - test( - 'tokens resolve', - () { - final radiiTokenUtil = UtilityWithRadiusTokens((value) => value); - - expect(radiiTokenUtil.small(), RadiusToken.small()); - expect(radiiTokenUtil.medium(), RadiusToken.medium()); - expect(radiiTokenUtil.large(), RadiusToken.large()); - }, - ); - }, - ); + group('UtilityWithRadiusTokens', () { + test('tokens resolve', () { + final radiiTokenUtil = UtilityWithRadiusTokens((value) => value); + + expect(radiiTokenUtil.small(), RadiusToken.small()); + expect(radiiTokenUtil.medium(), RadiusToken.medium()); + expect(radiiTokenUtil.large(), RadiusToken.large()); + }); + }); } diff --git a/test/src/theme/tokens/text_style_token_test.dart b/test/src/theme/tokens/text_style_token_test.dart index 78a181dbd..e6676dbaf 100644 --- a/test/src/theme/tokens/text_style_token_test.dart +++ b/test/src/theme/tokens/text_style_token_test.dart @@ -48,41 +48,41 @@ void main() { final mixData = MixData.create(context, const Style.empty()); - expect(mixData.tokens.textStyleToken(redtextStyleToken), - const TextStyle(color: Colors.red)); - expect(mixData.tokens.textStyleToken(greentextStyleToken), - const TextStyle(color: Colors.green)); - expect(mixData.tokens.textStyleToken(bluetextStyleToken), - const TextStyle(color: Colors.blue)); + expect( + mixData.tokens.textStyleToken(redtextStyleToken), + const TextStyle(color: Colors.red), + ); + expect( + mixData.tokens.textStyleToken(greentextStyleToken), + const TextStyle(color: Colors.green), + ); + expect( + mixData.tokens.textStyleToken(bluetextStyleToken), + const TextStyle(color: Colors.blue), + ); }); }); testWidgets('Combined Test', (tester) async { final themeData = MixThemeData( + colors: { + $md.colorScheme.error: Colors.blue, + $md.colorScheme.background: Colors.red, + }, + space: {$space.large: 100, $space.medium: 50}, textStyles: { $md.textTheme.bodyText1: const TextStyle(color: Colors.red, fontSize: 10), $md.textTheme.bodyText2: const TextStyle(color: Colors.blue, fontSize: 20), }, - colors: { - $md.colorScheme.error: Colors.blue, - $md.colorScheme.background: Colors.red, - }, - radii: { - $radii.medium: const Radius.elliptical(10, 50), - }, - space: { - $space.large: 100, - $space.medium: 50, - }, + radii: {$radii.medium: const Radius.elliptical(10, 50)}, ); const key = Key('box'); await tester.pumpWithMixTheme( Box( - key: key, style: Style( text.style.of($md.textTheme.bodyText1), text.style.of($md.textTheme.bodyText2), @@ -93,25 +93,18 @@ void main() { box.padding.horizontal.of($space.medium), box.padding.horizontal.of($space.large), ), - child: const StyledText( - 'Hello', - ), + key: key, + child: const StyledText('Hello'), ), theme: themeData, ); final textWidget = tester.widget( - find.descendant( - of: find.byKey(key), - matching: find.byType(Text), - ), + find.descendant(of: find.byKey(key), matching: find.byType(Text)), ); final containerWidget = tester.widget( - find.descendant( - of: find.byKey(key), - matching: find.byType(Container), - ), + find.descendant(of: find.byKey(key), matching: find.byType(Container)), ); expect( diff --git a/test/src/variants/variant_operation_test.dart b/test/src/variants/variant_operation_test.dart index 1987ad8cc..6b243354e 100644 --- a/test/src/variants/variant_operation_test.dart +++ b/test/src/variants/variant_operation_test.dart @@ -24,147 +24,131 @@ void main() { }); group('Operator `or`', () { - testWidgets('should set the same icon color for 2 different variants', - (WidgetTester tester) async { - final style = Style( - (_foo | _bar)( - icon.color.black(), - ), - ); - - await tester.pumpMaterialApp( - Row( - children: [ - _buildDefaultTestCase(style, [_foo]), - _buildDefaultTestCase(style, [_bar]), - _buildDefaultTestCase(style, [_foo, _bar]), - _buildDefaultTestCase(style, [_foo, _fooBar]), - _buildDefaultTestCase(style, [_bar, _fooBar]), - _buildTestCaseToVerifyIfNull(style, [_fooBar]), - ], - ), - ); - }); + testWidgets( + 'should set the same icon color for 2 different variants', + (WidgetTester tester) async { + final style = Style((_foo | _bar)(icon.color.black())); + + await tester.pumpMaterialApp( + Row( + children: [ + _buildDefaultTestCase(style, [_foo]), + _buildDefaultTestCase(style, [_bar]), + _buildDefaultTestCase(style, [_foo, _bar]), + _buildDefaultTestCase(style, [_foo, _fooBar]), + _buildDefaultTestCase(style, [_bar, _fooBar]), + _buildTestCaseToVerifyIfNull(style, [_fooBar]), + ], + ), + ); + }, + ); - testWidgets('should set the same icon color for 3 different variants', - (WidgetTester tester) async { - final style = Style( - (_foo | _bar | _fooBar)( - icon.color.black(), - ), - ); - - await tester.pumpMaterialApp( - Row( - children: [ - _buildDefaultTestCase(style, [_foo]), - _buildDefaultTestCase(style, [_bar]), - _buildDefaultTestCase(style, [_fooBar]), - _buildDefaultTestCase(style, [_foo, _bar]), - _buildDefaultTestCase(style, [_foo, _fooBar]), - _buildDefaultTestCase(style, [_bar, _fooBar]), - _buildDefaultTestCase(style, [_bar, _foo, _fooBar]), - ], - ), - ); - }); + testWidgets( + 'should set the same icon color for 3 different variants', + (WidgetTester tester) async { + final style = Style((_foo | _bar | _fooBar)(icon.color.black())); + + await tester.pumpMaterialApp( + Row( + children: [ + _buildDefaultTestCase(style, [_foo]), + _buildDefaultTestCase(style, [_bar]), + _buildDefaultTestCase(style, [_fooBar]), + _buildDefaultTestCase(style, [_foo, _bar]), + _buildDefaultTestCase(style, [_foo, _fooBar]), + _buildDefaultTestCase(style, [_bar, _fooBar]), + _buildDefaultTestCase(style, [_bar, _foo, _fooBar]), + ], + ), + ); + }, + ); }); group('Operator `and`', () { testWidgets( - 'should set the icon color when 2 different variants are needed', - (WidgetTester tester) async { - final style = Style( - (_foo & _bar)( - icon.color.black(), - ), - ); - - await tester.pumpMaterialApp( - Row( - children: [ - _buildDefaultTestCase(style, [_foo, _bar]), - _buildTestCaseToVerifyIfNull(style, [_fooBar]), - _buildTestCaseToVerifyIfNull(style, [_foo, _fooBar]), - _buildTestCaseToVerifyIfNull(style, [_bar, _fooBar]), - _buildDefaultTestCase(style, [_foo, _bar, _fooBar]), - ], - ), - ); - }); + 'should set the icon color when 2 different variants are needed', + (WidgetTester tester) async { + final style = Style((_foo & _bar)(icon.color.black())); + + await tester.pumpMaterialApp( + Row( + children: [ + _buildDefaultTestCase(style, [_foo, _bar]), + _buildTestCaseToVerifyIfNull(style, [_fooBar]), + _buildTestCaseToVerifyIfNull(style, [_foo, _fooBar]), + _buildTestCaseToVerifyIfNull(style, [_bar, _fooBar]), + _buildDefaultTestCase(style, [_foo, _bar, _fooBar]), + ], + ), + ); + }, + ); testWidgets( - 'should set the icon color when 3 different variants are needed', - (WidgetTester tester) async { - final style = Style( - (_foo & _bar & _fooBar)( - icon.color.black(), - ), - ); - - await tester.pumpMaterialApp( - Row( - children: [ - _buildDefaultTestCase(style, [_foo, _bar, _fooBar]), - _buildTestCaseToVerifyIfNull(style, [_bar]), - _buildTestCaseToVerifyIfNull(style, [_foo]), - _buildTestCaseToVerifyIfNull(style, [_fooBar]), - _buildTestCaseToVerifyIfNull(style, [_bar, _foo]), - _buildTestCaseToVerifyIfNull(style, [_foo, _fooBar]), - _buildTestCaseToVerifyIfNull(style, [_bar, _fooBar]), - ], - ), - ); - }); + 'should set the icon color when 3 different variants are needed', + (WidgetTester tester) async { + final style = Style((_foo & _bar & _fooBar)(icon.color.black())); + + await tester.pumpMaterialApp( + Row( + children: [ + _buildDefaultTestCase(style, [_foo, _bar, _fooBar]), + _buildTestCaseToVerifyIfNull(style, [_bar]), + _buildTestCaseToVerifyIfNull(style, [_foo]), + _buildTestCaseToVerifyIfNull(style, [_fooBar]), + _buildTestCaseToVerifyIfNull(style, [_bar, _foo]), + _buildTestCaseToVerifyIfNull(style, [_foo, _fooBar]), + _buildTestCaseToVerifyIfNull(style, [_bar, _fooBar]), + ], + ), + ); + }, + ); }); group('Operators `and` and `or` in the same expression', () { testWidgets( - 'should follow the order of operations and set the icon color when all conditions are met, case with | first', - (WidgetTester tester) async { - final style = Style( - ((_foo | _bar) & _fooBar)( - icon.color.black(), - ), - ); - - await tester.pumpMaterialApp( - Row( - children: [ - _buildDefaultTestCase(style, [_foo, _fooBar]), - _buildDefaultTestCase(style, [_bar, _fooBar]), - _buildDefaultTestCase(style, [_foo, _bar, _fooBar]), - _buildTestCaseToVerifyIfNull(style, [_foo]), - _buildTestCaseToVerifyIfNull(style, [_bar]), - _buildTestCaseToVerifyIfNull(style, [_fooBar]), - ], - ), - ); - }); + 'should follow the order of operations and set the icon color when all conditions are met, case with | first', + (WidgetTester tester) async { + final style = Style(((_foo | _bar) & _fooBar)(icon.color.black())); + + await tester.pumpMaterialApp( + Row( + children: [ + _buildDefaultTestCase(style, [_foo, _fooBar]), + _buildDefaultTestCase(style, [_bar, _fooBar]), + _buildDefaultTestCase(style, [_foo, _bar, _fooBar]), + _buildTestCaseToVerifyIfNull(style, [_foo]), + _buildTestCaseToVerifyIfNull(style, [_bar]), + _buildTestCaseToVerifyIfNull(style, [_fooBar]), + ], + ), + ); + }, + ); testWidgets( - 'should follow the order of operations and set the icon color when all conditions are met, case with & first', - (WidgetTester tester) async { - final style = Style( - (_foo & _bar | _fooBar)( - icon.color.black(), - ), - ); - - await tester.pumpMaterialApp( - Row( - children: [ - _buildDefaultTestCase(style, [_foo, _bar, _fooBar]), - _buildDefaultTestCase(style, [_foo, _bar]), - _buildDefaultTestCase(style, [_foo, _fooBar]), - _buildDefaultTestCase(style, [_bar, _fooBar]), - _buildDefaultTestCase(style, [_fooBar]), - _buildTestCaseToVerifyIfNull(style, [_foo]), - _buildTestCaseToVerifyIfNull(style, [_bar]), - ], - ), - ); - }); + 'should follow the order of operations and set the icon color when all conditions are met, case with & first', + (WidgetTester tester) async { + final style = Style((_foo & _bar | _fooBar)(icon.color.black())); + + await tester.pumpMaterialApp( + Row( + children: [ + _buildDefaultTestCase(style, [_foo, _bar, _fooBar]), + _buildDefaultTestCase(style, [_foo, _bar]), + _buildDefaultTestCase(style, [_foo, _fooBar]), + _buildDefaultTestCase(style, [_bar, _fooBar]), + _buildDefaultTestCase(style, [_fooBar]), + _buildTestCaseToVerifyIfNull(style, [_foo]), + _buildTestCaseToVerifyIfNull(style, [_bar]), + ], + ), + ); + }, + ); }); } @@ -175,6 +159,7 @@ Widget _buildDefaultTestCase(Style style, List variants) { final icon = IconSpec.of(mixData); expect(icon.color, Colors.black); + return const SizedBox(); }, ); @@ -187,6 +172,7 @@ Widget _buildTestCaseToVerifyIfNull(Style style, List variants) { final icon = IconSpec.of(mixData); expect(icon.color, null); + return const SizedBox(); }, ); diff --git a/test/src/variants/variant_test.dart b/test/src/variants/variant_test.dart index c7b03e1ce..4056cf84f 100644 --- a/test/src/variants/variant_test.dart +++ b/test/src/variants/variant_test.dart @@ -6,25 +6,24 @@ import '../../helpers/testing_utils.dart'; void main() { group('Variant', () { - testWidgets('should set attributes when variant matches, otherwise null', - (WidgetTester tester) async { - final style = Style( - icon.color.black(), - _foo( - box.height(10), - box.width(10), - ), - ); - - await tester.pumpMaterialApp( - Row( - children: [ - _buildDefaultTestCase(style, [_foo]), - _buildTestCaseToVerifyIfNull(style, [_bar]), - ], - ), - ); - }); + testWidgets( + 'should set attributes when variant matches, otherwise null', + (WidgetTester tester) async { + final style = Style( + icon.color.black(), + _foo(box.height(10), box.width(10)), + ); + + await tester.pumpMaterialApp( + Row( + children: [ + _buildDefaultTestCase(style, [_foo]), + _buildTestCaseToVerifyIfNull(style, [_bar]), + ], + ), + ); + }, + ); }); group('MultiVariant', () { diff --git a/test/src/widgets/box/box_test.dart b/test/src/widgets/box/box_test.dart index 4c521529f..20c26a86c 100644 --- a/test/src/widgets/box/box_test.dart +++ b/test/src/widgets/box/box_test.dart @@ -6,121 +6,110 @@ import '../../../helpers/testing_utils.dart'; void main() { group('Box', () { - testWidgets('by default should not pass its style through the widget tree', - (tester) async { - await tester.pumpWidget( - Box( - style: Style( - icon.color.black(), - ), - child: Box( - child: WidgetWithTestableBuild((context) { - final inheritedStyle = MixProvider.maybeOf(context); + testWidgets( + 'by default should not pass its style through the widget tree', + (tester) async { + await tester.pumpWidget( + Box( + style: Style(icon.color.black()), + child: Box( + child: WidgetWithTestableBuild((context) { + final inheritedStyle = MixProvider.maybeOf(context); - expect(inheritedStyle?.attributes.length, 0); - }), + expect(inheritedStyle?.attributes.length, 0); + }), + ), ), - ), - ); - }); + ); + }, + ); testWidgets( - 'when the property `inherit` is true should pass its style through the widget tree', - (tester) async { - await tester.pumpWidget( - Box( - style: Style( - icon.color.black(), - ), - child: Box( - inherit: true, - child: Builder(builder: (context) { - final inheritedStyle = MixProvider.maybeOf(context)!; - final iconSpec = IconSpec.of(inheritedStyle); - - expect(inheritedStyle.attributes.length, 1); - expect(iconSpec.color, Colors.black); - return const SizedBox(); - }), + 'when the property `inherit` is true should pass its style through the widget tree', + (tester) async { + await tester.pumpWidget( + Box( + style: Style(icon.color.black()), + child: Box( + inherit: true, + child: Builder(builder: (context) { + final inheritedStyle = MixProvider.maybeOf(context)!; + final iconSpec = IconSpec.of(inheritedStyle); + + expect(inheritedStyle.attributes.length, 1); + expect(iconSpec.color, Colors.black); + + return const SizedBox(); + }), + ), ), - ), - ); - }); + ); + }, + ); testWidgets( - 'when the property `inherit` is true and it has its own style, should merge the styles', - (tester) async { - await tester.pumpWidget( - Box( - style: Style( - icon.color.black(), - ), - child: Box( - inherit: true, - style: Style( - box.height(100), - box.width(100), + 'when the property `inherit` is true and it has its own style, should merge the styles', + (tester) async { + await tester.pumpWidget( + Box( + style: Style(icon.color.black()), + child: Box( + style: Style(box.height(100), box.width(100)), + inherit: true, + child: Builder(builder: (context) { + final inheritedStyle = MixProvider.maybeOf(context)!; + final iconSpec = IconSpec.of(inheritedStyle); + final boxSpec = BoxSpec.of(inheritedStyle); + + expect(inheritedStyle.attributes.length, 2); + expect(iconSpec.color, Colors.black); + expect(boxSpec.height, 100); + expect(boxSpec.width, 100); + + return const SizedBox(); + }), ), - child: Builder(builder: (context) { - final inheritedStyle = MixProvider.maybeOf(context)!; - final iconSpec = IconSpec.of(inheritedStyle); - final boxSpec = BoxSpec.of(inheritedStyle); - - expect(inheritedStyle.attributes.length, 2); - expect(iconSpec.color, Colors.black); - expect(boxSpec.height, 100); - expect(boxSpec.width, 100); - return const SizedBox(); - }), ), - ), - ); - }); + ); + }, + ); testWidgets( - 'when the property `inherit` is true and it has its own style with different attributes, should merge them', - (tester) async { - await tester.pumpWidget( - Box( - style: Style( - icon.color.black(), - ), - child: Box( - inherit: true, - style: Style( - box.height(100), - box.width(100), + 'when the property `inherit` is true and it has its own style with different attributes, should merge them', + (tester) async { + await tester.pumpWidget( + Box( + style: Style(icon.color.black()), + child: Box( + style: Style(box.height(100), box.width(100)), + inherit: true, + child: Builder(builder: (context) { + final inheritedStyle = MixProvider.maybeOf(context)!; + final iconSpec = IconSpec.of(inheritedStyle); + final boxSpec = BoxSpec.of(inheritedStyle); + + expect(inheritedStyle.attributes.length, 2); + expect(iconSpec.color, Colors.black); + expect(boxSpec.height, 100); + expect(boxSpec.width, 100); + + return const SizedBox(); + }), ), - child: Builder(builder: (context) { - final inheritedStyle = MixProvider.maybeOf(context)!; - final iconSpec = IconSpec.of(inheritedStyle); - final boxSpec = BoxSpec.of(inheritedStyle); - - expect(inheritedStyle.attributes.length, 2); - expect(iconSpec.color, Colors.black); - expect(boxSpec.height, 100); - expect(boxSpec.width, 100); - return const SizedBox(); - }), ), - ), - ); - }); + ); + }, + ); testWidgets( 'when the property `inherit` is true and it has its own style with similar attributes, should merge them', (tester) async { await tester.pumpWidget( Box( - style: Style( - box.height(100), - box.width(50), - ), + style: Style(box.height(100), box.width(50)), child: Box( + style: Style(box.width(100)), inherit: true, - style: Style( - box.width(100), - ), child: Builder(builder: (context) { final inheritedStyle = MixProvider.maybeOf(context)!; final boxSpec = BoxSpec.of(inheritedStyle); @@ -128,6 +117,7 @@ void main() { expect(inheritedStyle.attributes.length, 1); expect(boxSpec.height, 100); expect(boxSpec.width, 100); + return const SizedBox(); }), ), @@ -143,7 +133,6 @@ void main() { await tester.pumpWidget( Box( - key: key, style: Style( box.height(100), box.width(50), @@ -153,49 +142,57 @@ void main() { visibility(true), aspectRatio(1), ), + key: key, ), ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(RenderWidgetDecorators)), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(RenderWidgetDecorators), + ), + findsOneWidget, + ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(Transform), - ), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(Transform), + ), + findsOneWidget, + ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(Opacity), - ), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(Opacity), + ), + findsOneWidget, + ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(RotatedBox), - ), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(RotatedBox), + ), + findsOneWidget, + ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(Visibility), - ), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(Visibility), + ), + findsOneWidget, + ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(AspectRatio), - ), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(AspectRatio), + ), + findsOneWidget, + ); }, ); }); diff --git a/test/src/widgets/pressable/pressable_state.notifier_test.dart b/test/src/widgets/pressable/pressable_state.notifier_test.dart index 8ef2df679..ea6af56ee 100644 --- a/test/src/widgets/pressable/pressable_state.notifier_test.dart +++ b/test/src/widgets/pressable/pressable_state.notifier_test.dart @@ -7,9 +7,9 @@ import '../../../helpers/testing_utils.dart'; void main() { group('PressableNotifier', () { const gestureData = WidgetStateData( - state: WidgetState.pressed, - status: WidgetStatus.enabled, focus: true, + status: WidgetStatus.enabled, + state: WidgetState.pressed, hover: false, ); test('constructor', () { @@ -32,8 +32,8 @@ void main() { final otherNotifier = WidgetStateNotifier( data: const WidgetStateData( focus: false, - state: WidgetState.none, status: WidgetStatus.disabled, + state: WidgetState.none, hover: false, ), child: Container(), diff --git a/test/src/widgets/pressable/pressable_widget_test.dart b/test/src/widgets/pressable/pressable_widget_test.dart index edbe3ad62..68ee66431 100644 --- a/test/src/widgets/pressable/pressable_widget_test.dart +++ b/test/src/widgets/pressable/pressable_widget_test.dart @@ -15,18 +15,11 @@ void main() { final secondKey = UniqueKey(); await tester.pumpWidget(Column( children: [ - Pressable( - onPressed: () {}, - child: Container( - key: firstKey, - ), - ), + Pressable(onPressed: null, child: Container(key: firstKey)), Pressable( onPressed: null, disabled: true, - child: Container( - key: secondKey, - ), + child: Container(key: secondKey), ), ], )); @@ -45,102 +38,110 @@ void main() { expect(secondNotifier!.status, WidgetStatus.disabled); }); - testWidgets('must be clickable when isDisabled is setted to false', - (tester) async { - int counter = 0; + testWidgets( + 'must be clickable when isDisabled is setted to false', + (tester) async { + int counter = 0; - await tester.pumpWidget( - Pressable( - onPressed: () { - counter++; - }, - disabled: false, - child: Container(), - ), - ); + await tester.pumpWidget( + Pressable( + onPressed: () { + counter++; + }, + disabled: false, + child: Container(), + ), + ); - final pressableFinder = find.byType(Pressable); - expect(pressableFinder, findsOneWidget); + final pressableFinder = find.byType(Pressable); + expect(pressableFinder, findsOneWidget); - await tester.tap(pressableFinder); - await tester.pumpAndSettle(); + await tester.tap(pressableFinder); + await tester.pumpAndSettle(); - expect(counter, 1); - }); + expect(counter, 1); + }, + ); - testWidgets('must be unclickable when isDisabled is setted to true', - (tester) async { - int counter = 0; + testWidgets( + 'must be unclickable when isDisabled is setted to true', + (tester) async { + int counter = 0; - await tester.pumpWidget( - Pressable( - onPressed: () { - counter++; - }, - disabled: true, - child: Container(), - ), - ); + await tester.pumpWidget( + Pressable( + onPressed: () { + counter++; + }, + disabled: true, + child: Container(), + ), + ); - final pressableFinder = find.byType(Pressable); - expect(pressableFinder, findsOneWidget); + final pressableFinder = find.byType(Pressable); + expect(pressableFinder, findsOneWidget); - await tester.tap(pressableFinder); - await tester.pumpAndSettle(); + await tester.tap(pressableFinder); + await tester.pumpAndSettle(); - expect(counter, 0); - }); + expect(counter, 0); + }, + ); }); group('PressableBox', () { - testWidgets('must be clickable when isDisabled is setted to false', - (tester) async { - int counter = 0; - - await tester.pumpWidget( - PressableBox( - unpressDelay: Duration.zero, - animationDuration: Duration.zero, - onPressed: () { - counter++; - }, - disabled: false, - child: Container(), - ), - ); - - final pressableFinder = find.byType(PressableBox); - expect(pressableFinder, findsOneWidget); - - await tester.tap(pressableFinder); - await tester.pumpAndSettle(); - - expect(counter, 1); - }); + testWidgets( + 'must be clickable when isDisabled is setted to false', + (tester) async { + int counter = 0; + + await tester.pumpWidget( + PressableBox( + onPressed: () { + counter++; + }, + unpressDelay: Duration.zero, + animationDuration: Duration.zero, + disabled: false, + child: Container(), + ), + ); + + final pressableFinder = find.byType(PressableBox); + expect(pressableFinder, findsOneWidget); + + await tester.tap(pressableFinder); + await tester.pumpAndSettle(); + + expect(counter, 1); + }, + ); + + testWidgets( + 'must be unclickable when isDisabled is setted to true', + (tester) async { + int counter = 0; + + await tester.pumpWidget( + PressableBox( + onPressed: () { + counter++; + }, + unpressDelay: Duration.zero, + animationDuration: Duration.zero, + disabled: true, + child: Container(), + ), + ); - testWidgets('must be unclickable when isDisabled is setted to true', - (tester) async { - int counter = 0; - - await tester.pumpWidget( - PressableBox( - onPressed: () { - counter++; - }, - unpressDelay: Duration.zero, - animationDuration: Duration.zero, - disabled: true, - child: Container(), - ), - ); - - final pressableFinder = find.byType(PressableBox); - expect(pressableFinder, findsOneWidget); - - await tester.tap(pressableFinder); - await tester.pumpAndSettle(); - - expect(counter, 0); - }); + final pressableFinder = find.byType(PressableBox); + expect(pressableFinder, findsOneWidget); + + await tester.tap(pressableFinder); + await tester.pumpAndSettle(); + + expect(counter, 0); + }, + ); }); } diff --git a/test/src/widgets/pressable/widget_state_util_test.dart b/test/src/widgets/pressable/widget_state_util_test.dart index dedade0b6..1b38bb3a7 100644 --- a/test/src/widgets/pressable/widget_state_util_test.dart +++ b/test/src/widgets/pressable/widget_state_util_test.dart @@ -48,11 +48,7 @@ void main() { }); testWidgets('hover state', (tester) async { - await tester.pumpWithPressable( - Container(), - hover: true, - focus: true, - ); + await tester.pumpWithPressable(Container(), focus: true, hover: true); final context = tester.element(find.byType(Container)); @@ -97,10 +93,7 @@ void main() { final onEnabledAttr = onEnabled(attribute1, attribute2, attribute3); expect(onEnabledAttr.when(context), true); - expect( - onEnabledAttr.value, - Style(attribute1, attribute2, attribute3), - ); + expect(onEnabledAttr.value, Style(attribute1, attribute2, attribute3)); expect(onEnabledAttr.variant.name, 'on-enabled'); expect(onEnabledAttr.variant.when(context), true); }); diff --git a/test/src/widgets/styled_icon_test.dart b/test/src/widgets/styled_icon_test.dart index 8b4abcd35..307550c92 100644 --- a/test/src/widgets/styled_icon_test.dart +++ b/test/src/widgets/styled_icon_test.dart @@ -6,27 +6,24 @@ import '../../helpers/testing_utils.dart'; void main() { group('StyledIcon', () { - testWidgets('should receive a style from its ancestor widget', - (tester) async { - const color = Color(0xffff1744); - const size = 20.0; + testWidgets( + 'should receive a style from its ancestor widget', + (tester) async { + const color = Color(0xffff1744); + const size = 20.0; - await tester.pumpMaterialApp( - Box( - style: Style( - icon.color(color), - icon.size(size), - ), - child: const StyledIcon( - Icons.access_time_filled_outlined, + await tester.pumpMaterialApp( + Box( + style: Style(icon.color(color), icon.size(size)), + child: const StyledIcon(Icons.access_time_filled_outlined), ), - ), - ); + ); - final iconWidget = tester.widget(find.byType(Icon)); - expect(iconWidget.color, color); - expect(iconWidget.size, size); - }); + final iconWidget = tester.widget(find.byType(Icon)); + expect(iconWidget.color, color); + expect(iconWidget.size, size); + }, + ); testWidgets( 'should apply decorators when they are defined in the style', @@ -36,7 +33,6 @@ void main() { await tester.pumpMaterialApp( StyledIcon( Icons.access_time_filled_outlined, - key: key, style: Style( box.height(100), box.width(50), @@ -46,49 +42,57 @@ void main() { visibility(true), aspectRatio(1), ), + key: key, ), ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(RenderWidgetDecorators)), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(RenderWidgetDecorators), + ), + findsOneWidget, + ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(Transform), - ), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(Transform), + ), + findsOneWidget, + ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(Opacity), - ), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(Opacity), + ), + findsOneWidget, + ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(RotatedBox), - ), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(RotatedBox), + ), + findsOneWidget, + ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(Visibility), - ), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(Visibility), + ), + findsOneWidget, + ); expect( - find.descendant( - of: find.byKey(key), - matching: find.byType(AspectRatio), - ), - findsOneWidget); + find.descendant( + of: find.byKey(key), + matching: find.byType(AspectRatio), + ), + findsOneWidget, + ); }, ); }); diff --git a/tool/rename_files.dart b/tool/rename_files.dart index 71c00c4f3..35f784191 100755 --- a/tool/rename_files.dart +++ b/tool/rename_files.dart @@ -1,3 +1,4 @@ +import 'dart:developer'; import 'dart:io'; import 'package:path/path.dart' as p; @@ -30,5 +31,5 @@ void main() { } } - print('Import updates and file renaming completed.'); + log('Import updates and file renaming completed.'); } diff --git a/tool/update_exports.dart b/tool/update_exports.dart index 0c6425abd..2f00200ca 100755 --- a/tool/update_exports.dart +++ b/tool/update_exports.dart @@ -1,5 +1,4 @@ -#!/usr/bin/env dart - +import 'dart:developer'; import 'dart:io'; import 'package:path/path.dart' as p; @@ -9,7 +8,7 @@ void main() { final exportFilePath = p.join('lib', 'mix.dart'); if (!libDirectory.existsSync()) { - print('The lib directory was not found.'); + log('The lib directory was not found.'); return; } @@ -19,15 +18,30 @@ void main() { exportFile.deleteSync(); } - final outputString = {}; + final defaultExports = {'export \'src/deprecations.dart\';'}; + + final outputString = StringBuffer(); + + outputString.writeln('library mix;'); + outputString.writeln(''); + outputString + .writeln('// This file is generated by the update_exports.dart script.'); + outputString.writeln('// DO NOT MODIFY MANUALLY'); + outputString.writeln(''); + outputString.writeln('// Some default exports'); + defaultExports.forEach(outputString.writeln); + + outputString.writeln(''); + + outputString.writeln('// Automated file exports'); - outputString.add('library mix;'); - outputString.add(''); - outputString.add('export \'src/deprecations.dart\';'); - outputString.add(''); + final filesList = libDirectory.listSync(recursive: true); + + // Order the files alphabetically + filesList.sort((a, b) => a.path.compareTo(b.path)); // Traverse the /lib/ directory - for (final entity in libDirectory.listSync(recursive: true)) { + for (final entity in filesList) { // Get the relative path using the path package final relativePath = p.relative(entity.path, from: libDirectory.path); @@ -43,10 +57,16 @@ void main() { continue; } - outputString.add('export \'$relativePath\';'); + final filePath = 'export \'$relativePath\';'; + + if (defaultExports.contains(filePath)) { + continue; + } + + outputString.writeln('export \'$relativePath\';'); } - exportFile.writeAsStringSync(outputString.join('\n')); + exportFile.writeAsStringSync(outputString.toString()); - print('Exports file updated with ${outputString.length} exports.'); + log('Exports file updated with ${outputString.length} exports.'); } diff --git a/website/pages/docs/guides/decorators.mdx b/website/pages/docs/guides/decorators.mdx index b2af90c6e..8d3a2a199 100644 --- a/website/pages/docs/guides/decorators.mdx +++ b/website/pages/docs/guides/decorators.mdx @@ -42,7 +42,7 @@ class ScaleDecorator extends WidgetDecorator { get props => [scale]; @override - Widget build(mix, child) { + Widget build(MixData mix, Widget child) { return Transform.scale( key: key, scale: scale,