94 lines
2.7 KiB
Dart
94 lines
2.7 KiB
Dart
// Author: fruit.com.cn
|
|
// 职责:检查观看全集按钮的玻璃表面确实被绘制出来。
|
|
import 'dart:typed_data';
|
|
import 'dart:ui' as ui;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/core/data/models/drama.dart';
|
|
import 'package:fruitshorts/core/theme/app_colors.dart';
|
|
import 'package:fruitshorts/l10n/app_localizations.dart';
|
|
import 'package:fruitshorts/pages/player/widgets/home_feed_recommend_panel.dart';
|
|
|
|
const _boundaryKey = Key('watch-surface-boundary');
|
|
const _width = 280.0;
|
|
const _sampleInset = 16;
|
|
const _sampleY = 4;
|
|
const _rgbaChannels = 4;
|
|
const _surfaceTolerance = 0.01;
|
|
const _drama = Drama(
|
|
id: 'surface',
|
|
title: 'Surface',
|
|
synopsis: '',
|
|
posterUrl: '',
|
|
);
|
|
|
|
Future<void> _pumpButton(WidgetTester tester) => tester.pumpWidget(
|
|
MaterialApp(
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: Scaffold(
|
|
backgroundColor: Colors.black,
|
|
body: Center(
|
|
child: RepaintBoundary(
|
|
key: _boundaryKey,
|
|
child: SizedBox(
|
|
width: _width,
|
|
child: ColoredBox(
|
|
color: Colors.black,
|
|
child: HomeFeedWatchAllBar(drama: _drama, onTap: () {}),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
Color _sample(ByteData bytes, int width, int x) {
|
|
final offset = (_sampleY * width + x) * _rgbaChannels;
|
|
return Color.fromARGB(
|
|
bytes.getUint8(offset + 3),
|
|
bytes.getUint8(offset),
|
|
bytes.getUint8(offset + 1),
|
|
bytes.getUint8(offset + 2),
|
|
);
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('should_paint_reference_dark_surface_when_watching_all', (
|
|
tester,
|
|
) async {
|
|
await _pumpButton(tester);
|
|
final boundary = tester.renderObject<RenderRepaintBoundary>(
|
|
find.byKey(_boundaryKey),
|
|
);
|
|
await tester.runAsync(() async {
|
|
final image = await boundary.toImage();
|
|
final bytes = (await image.toByteData(
|
|
format: ui.ImageByteFormat.rawRgba,
|
|
))!;
|
|
final left = _sample(bytes, image.width, _sampleInset);
|
|
final middle = _sample(bytes, image.width, image.width ~/ 2);
|
|
final right = _sample(bytes, image.width, image.width - _sampleInset);
|
|
image.dispose();
|
|
for (final sample in [left, middle, right]) {
|
|
expect(sample.a, 1);
|
|
expect(
|
|
sample.r,
|
|
closeTo(AppColors.watchAllSurface.a, _surfaceTolerance),
|
|
);
|
|
expect(
|
|
sample.g,
|
|
closeTo(AppColors.watchAllSurface.a, _surfaceTolerance),
|
|
);
|
|
expect(
|
|
sample.b,
|
|
closeTo(AppColors.watchAllSurface.a, _surfaceTolerance),
|
|
);
|
|
}
|
|
});
|
|
});
|
|
}
|