import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:holo_shiny/holo_shiny.dart'; const ValueKey _cardTransformKey = ValueKey('holo_shiny.card.transform'); void main() { test('default holograph style is crackedIce', () { const Shiny shiny = Shiny(child: SizedBox.shrink()); const ShinyCard shinyCard = ShinyCard(); expect(shiny.style, HolographStyle.crackedIce); expect(shinyCard.style, HolographStyle.crackedIce); }); test('default sparkle shape is none', () { const Shiny shiny = Shiny(child: SizedBox.shrink()); const ShinyCard shinyCard = ShinyCard(); expect(shiny.sparkleShape.kind, SparkleShapeKind.none); expect(shiny.sparkleShape.primary, 0.0); expect(shinyCard.sparkleShape.kind, SparkleShapeKind.none); expect(shinyCard.sparkleShape.primary, 0.0); }); test('custom sparkle factories produce expected specs', () { final SparkleShapeSpec star = SparkleShapeSpec.customStar(points: 7, innerRatio: 0.33); final SparkleShapeSpec polygon = SparkleShapeSpec.customPolygon( sides: 8, aspectRatio: 1.2, rotation: 0.4); final SparkleShapeSpec rectangle = SparkleShapeSpec.customRectangle( halfWidth: 0.20, halfHeight: 0.05, rotationJitter: 0.7); expect(star.kind, SparkleShapeKind.star); expect(star.primary, 7.0); expect(star.secondary, 0.33); expect(polygon.kind, SparkleShapeKind.polygon); expect(polygon.primary, 8.0); expect(polygon.secondary, 1.2); expect(polygon.tertiary, 0.4); expect(rectangle.kind, SparkleShapeKind.rectangle); expect(rectangle.primary, 0.20); expect(rectangle.secondary, 0.05); expect(rectangle.tertiary, 0.7); }); testWidgets('Shiny wraps any child without card transform', (WidgetTester tester) async { await tester.pumpWidget( const MaterialApp( home: Scaffold( body: Shiny( enableShader: false, child: ColoredBox( color: Colors.blue, child: SizedBox(width: 80, height: 40), ), ), ), ), ); expect(find.byType(ColoredBox), findsWidgets); expect(find.byKey(_cardTransformKey), findsNothing); }); testWidgets('ShinyCard renders clipping and foreground', (WidgetTester tester) async { await tester.pumpWidget( const MaterialApp( home: Scaffold( body: ShinyCard( enableShader: false, background: ColoredBox(color: Colors.black), foreground: Text('FOREGROUND'), ), ), ), ); expect(find.text('FOREGROUND'), findsOneWidget); expect(find.byType(ClipPath), findsOneWidget); expect(find.byKey(_cardTransformKey), findsOneWidget); }); testWidgets('ShinyCard responds to external tilt stream', (WidgetTester tester) async { final StreamController stream = StreamController.broadcast(); final ShinyController controller = ShinyController(tiltStream: stream.stream); await tester.pumpWidget( MaterialApp( home: Scaffold( body: Center( child: ShinyCard( enableShader: false, controller: controller, background: const ColoredBox(color: Colors.black), ), ), ), ), ); final Matrix4 before = tester.widget(find.byKey(_cardTransformKey)).transform; stream.add(const Offset(0.7, 0.2)); await tester.pump(); final Matrix4 after = tester.widget(find.byKey(_cardTransformKey)).transform; expect(after.storage[8], isNot(before.storage[8])); await controller.dispose(); await stream.close(); }); testWidgets('Dragging ShinyCard updates transform', (WidgetTester tester) async { await tester.pumpWidget( const MaterialApp( home: Scaffold( body: Center( child: ShinyCard( enableShader: false, background: ColoredBox(color: Colors.black), ), ), ), ), ); final Finder shinyCard = find.byType(ShinyCard); final Matrix4 before = tester.widget(find.byKey(_cardTransformKey)).transform; await tester.drag(shinyCard, const Offset(50, 20)); await tester.pump(); final Matrix4 after = tester.widget(find.byKey(_cardTransformKey)).transform; expect(after.storage[8], isNot(before.storage[8])); }); }