74 lines
2.1 KiB
Dart
74 lines
2.1 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/core/data/models/drama.dart';
|
|
import 'package:fruitshorts/pages/player/widgets/episode_picker_cell.dart';
|
|
|
|
void main() {
|
|
testWidgets('should_show_lock_when_episode_needs_unlock', (tester) async {
|
|
await tester.pumpWidget(
|
|
_host(
|
|
const Episode(
|
|
id: '12',
|
|
number: 12,
|
|
title: 'Paid',
|
|
isFree: false,
|
|
locked: true,
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(find.byIcon(Icons.lock_outline), findsOneWidget);
|
|
expect(find.text('12'), findsOneWidget);
|
|
final cell = tester.getRect(find.byType(EpisodePickerCell));
|
|
final cover = tester.getRect(find.byKey(const ValueKey('episode-lock-cover-12')));
|
|
final number = tester.getRect(find.text('12'));
|
|
final lock = tester.getRect(find.byIcon(Icons.lock_outline));
|
|
expect(number.overlaps(lock), isFalse);
|
|
expect(number.top, greaterThanOrEqualTo(lock.bottom));
|
|
final wash = tester.widget<ColoredBox>(
|
|
find.byKey(const ValueKey('episode-lock-cover-12')),
|
|
);
|
|
expect(cover.width, greaterThanOrEqualTo(cell.width - 1));
|
|
expect(cover.height, greaterThanOrEqualTo(cell.height - 1));
|
|
expect(cover.contains(lock.center), isTrue);
|
|
expect(wash.color.a, greaterThan(0));
|
|
expect(wash.color.a, lessThan(1));
|
|
});
|
|
|
|
testWidgets('should_hide_lock_when_episode_is_free', (tester) async {
|
|
await tester.pumpWidget(
|
|
_host(
|
|
const Episode(
|
|
id: '1',
|
|
number: 1,
|
|
title: 'Free',
|
|
isFree: true,
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(find.byIcon(Icons.lock_outline), findsNothing);
|
|
expect(find.byKey(const ValueKey('episode-lock-cover-1')), findsNothing);
|
|
expect(find.text('1'), findsOneWidget);
|
|
});
|
|
}
|
|
|
|
Widget _host(Episode episode) {
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
body: SizedBox(
|
|
width: 52,
|
|
height: 50,
|
|
child: EpisodePickerCell(
|
|
episode: episode,
|
|
selected: false,
|
|
lockLabel: 'Locked',
|
|
onTap: () {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|