feat(following): 收藏页改为紧凑布局并去掉重复续播横幅
This commit is contained in:
1 parent
fd2ba0bf43
commit
c5b94633f1
3 files changed
+147
-78
No files matched your search
@@ -0,0 +1,143 @@
|
||||
// Author: fruit.com.cn
|
||||
// 职责:验证追剧页移除顶部横幅/重复收藏标题后,卡片直达及历史续播能力。
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/app.dart';
|
||||
import 'package:fruitshorts/core/data/models/watch_progress.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart';
|
||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||
|
||||
import '../support/fake_catalog.dart';
|
||||
import '../support/fake_category.dart';
|
||||
import '../support/fake_interaction_repositories.dart';
|
||||
import '../support/widget_player.dart';
|
||||
|
||||
const _viewport = Size(390, 844);
|
||||
const _tolerance = 0.1;
|
||||
const _dramaId = 'the-signal-demo';
|
||||
const _banner = Key('following-continue-banner');
|
||||
const _page = Key('following-page');
|
||||
const _favoritesGrid = Key('following-favorites-grid');
|
||||
const _historyRecord = WatchProgress(
|
||||
dramaId: _dramaId,
|
||||
episodeId: 'the-signal-demo-3',
|
||||
dramaTitle: 'Recent story',
|
||||
episodeNumber: 3,
|
||||
totalEpisodes: 8,
|
||||
position: Duration(seconds: 25),
|
||||
duration: Duration(seconds: 100),
|
||||
);
|
||||
|
||||
Future<void> _pumpFollowing(
|
||||
WidgetTester tester, {
|
||||
bool hasFavorites = true,
|
||||
}) async {
|
||||
tester.view.physicalSize = _viewport;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final catalog = FakeCatalogRepository();
|
||||
final cards = hasFavorites
|
||||
? catalog.dramas.take(1).toList()
|
||||
: catalog.dramas.take(0).toList();
|
||||
await tester.pumpWidget(
|
||||
LumaDramaApp(
|
||||
playerFactory: createWidgetPlayer,
|
||||
catalogRepository: catalog,
|
||||
categoryRepository: FakeCategoryRepository(catalog: catalog),
|
||||
watchHistoryRepository: InMemoryWatchHistoryRepository(
|
||||
seed: [_historyRecord],
|
||||
),
|
||||
favoriteRepository: InMemoryFavoriteRepository(
|
||||
cards: cards,
|
||||
saved: cards.map((drama) => drama.id).toSet(),
|
||||
),
|
||||
playbackRepository: FakePlaybackRepository(),
|
||||
commentRepository: FakeCommentRepository(),
|
||||
interactionRepository: FakeInteractionRepository(),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('tab-follow')));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
});
|
||||
|
||||
testWidgets('should_hide_continue_banner_when_recent_history_exists', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpFollowing(tester);
|
||||
expect(find.byKey(_banner), findsNothing);
|
||||
expect(find.byKey(const Key('following-card-$_dramaId')), findsOneWidget);
|
||||
expect(find.byKey(const Key('following-add-card')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
for (final hasFavorites in [true, false]) {
|
||||
testWidgets(
|
||||
'should_omit_section_heading_and_count_when_favorites_are_$hasFavorites',
|
||||
(tester) async {
|
||||
await _pumpFollowing(tester, hasFavorites: hasFavorites);
|
||||
final l10n = AppLocalizations.of(tester.element(find.byKey(_page)))!;
|
||||
final grid = find.byKey(_favoritesGrid);
|
||||
expect(
|
||||
find.descendant(of: grid, matching: find.text(l10n.favoriteDramas)),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: grid,
|
||||
matching: find.text(l10n.totalDramasCount(hasFavorites ? 1 : 0)),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
if (hasFavorites) {
|
||||
final header = tester.getRect(
|
||||
find.byKey(const Key('following-header')),
|
||||
);
|
||||
final card = tester.getRect(
|
||||
find.byKey(const Key('following-card-$_dramaId')),
|
||||
);
|
||||
expect(card.top, closeTo(header.bottom, _tolerance));
|
||||
} else {
|
||||
expect(
|
||||
find.byKey(const Key('following-favorites-empty')),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should_keep_history_continue_entry_when_history_tab_opens', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpFollowing(tester);
|
||||
await tester.tap(find.byKey(const Key('following-tab-history')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.byKey(const Key('following-history-card-$_dramaId')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const Key('following-history-continue-$_dramaId')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.byKey(const Key('following-progress-$_dramaId')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byKey(_banner), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user