Files
holo_shiny/test/shiny_widget_test.dart
T
hans 9564096a5c
CI / quality (push) Failing after 5m56s
Optimize shaders
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
2026-04-21 17:40:21 +02:00

142 lines
3.9 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:holo_shiny/holo_shiny.dart';
const ValueKey<String> _cardTransformKey =
ValueKey<String>('holo_shiny.card.transform');
void main() {
test('default profile is crackedIce', () {
const Shiny shiny = Shiny(child: SizedBox.shrink());
const ShinyCard shinyCard = ShinyCard();
expect(shiny.profile, ShinyProfile.crackedIce);
expect(shinyCard.profile, ShinyProfile.crackedIce);
});
test('default opacity is 1.0', () {
const Shiny shiny = Shiny(child: SizedBox.shrink());
const ShinyCard shinyCard = ShinyCard();
expect(shiny.opacity, 1.0);
expect(shinyCard.opacity, 1.0);
});
test('custom profile can be set on both widgets', () {
const Shiny shiny = Shiny(
profile: ShinyProfile.superGoldVinyl,
child: SizedBox.shrink(),
);
const ShinyCard shinyCard = ShinyCard(
profile: ShinyProfile.silverMosaic,
);
expect(shiny.profile, ShinyProfile.superGoldVinyl);
expect(shinyCard.profile, ShinyProfile.silverMosaic);
});
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<Offset> stream =
StreamController<Offset>.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<Transform>(find.byKey(_cardTransformKey)).transform;
stream.add(const Offset(0.7, 0.2));
await tester.pump();
final Matrix4 after =
tester.widget<Transform>(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<Transform>(find.byKey(_cardTransformKey)).transform;
await tester.drag(shinyCard, const Offset(50, 20));
await tester.pump();
final Matrix4 after =
tester.widget<Transform>(find.byKey(_cardTransformKey)).transform;
expect(after.storage[8], isNot(before.storage[8]));
});
}