chore(client): 归档原型阶段未提交改动(binding/logic/view 分层与各页迭代)
为什么:客户端原型在 14d7bd3 之后又做了一轮(页面分层、发现页、分类滑动、播放器控件等),
一直留在工作区没入库。下一批账号链路要改其中的 app.dart / home_view / player_view / mine_view,
先归档这批既存改动,本批的实际 diff 才说得清边界。
只归档,不改行为:当前工作区 flutter analyze 0 问题、flutter test 148 全过。
This commit is contained in:
1 parent
14d7bd39c7
commit
77d5748dbb
33 files changed
+1264
-1064
No files matched your search
@@ -1,39 +1,131 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:nontonki/core/data/repositories/catalog_repository.dart';
|
||||
import 'package:nontonki/core/data/models/drama.dart';
|
||||
import 'package:nontonki/core/data/models/home_feed.dart';
|
||||
import 'package:nontonki/core/data/models/play_ticket.dart';
|
||||
import 'package:nontonki/core/data/repositories/catalog_repository.dart';
|
||||
import 'package:nontonki/core/data/services/catalog_controller.dart';
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'empty catalog is distinct from a failed load, and retry recovers',
|
||||
() async {
|
||||
final repo = ScriptedCatalogRepository();
|
||||
final controller = CatalogController(repo);
|
||||
await controller.load();
|
||||
expect(controller.dramas, isEmpty);
|
||||
expect(controller.error, isNull);
|
||||
test('空目录与加载失败可区分,重试后恢复', () async {
|
||||
final repository = ScriptedCatalogRepository();
|
||||
final controller = CatalogController(repository);
|
||||
|
||||
repo.fail = true;
|
||||
await controller.load();
|
||||
expect(controller.error, isNotNull);
|
||||
await controller.load();
|
||||
expect(controller.dramas, isEmpty);
|
||||
expect(controller.error, isNull);
|
||||
|
||||
repo.fail = false;
|
||||
repo.items = await DemoCatalogRepository().fetchDramas();
|
||||
await controller.load();
|
||||
expect(controller.error, isNull);
|
||||
expect(controller.dramas, hasLength(3));
|
||||
expect(controller.dramas.first.episodes.length, 3);
|
||||
},
|
||||
);
|
||||
repository.fail = true;
|
||||
await controller.load();
|
||||
expect(controller.error, isNotNull);
|
||||
|
||||
repository.fail = false;
|
||||
repository.feed = HomeFeed(
|
||||
sections: [
|
||||
FeedSection(code: 'hot', title: '热门推荐', dramas: [_card('1')]),
|
||||
],
|
||||
);
|
||||
await controller.load();
|
||||
expect(controller.error, isNull);
|
||||
expect(controller.dramas, hasLength(1));
|
||||
expect(controller.sections.single.title, '热门推荐');
|
||||
});
|
||||
|
||||
test('详情按需加载:同一部短剧只请求一次', () async {
|
||||
final repository = ScriptedCatalogRepository();
|
||||
final controller = CatalogController(repository);
|
||||
repository.feed = HomeFeed(
|
||||
sections: [
|
||||
FeedSection(code: 'hot', title: '热门推荐', dramas: [_card('1')]),
|
||||
],
|
||||
);
|
||||
await controller.load();
|
||||
|
||||
final card = controller.dramas.single;
|
||||
expect(card.episodes, isEmpty);
|
||||
|
||||
final detail = await controller.requireDetail(card);
|
||||
expect(detail.episodes, hasLength(2));
|
||||
expect(repository.detailCalls, 1);
|
||||
|
||||
// 第二次已经是详情,直接复用,不再请求
|
||||
await controller.requireDetail(detail);
|
||||
expect(repository.detailCalls, 1);
|
||||
expect(controller.dramas.single.episodes, hasLength(2));
|
||||
});
|
||||
|
||||
test('播放票据:可播放写入地址,锁定集保持无地址', () async {
|
||||
final repository = ScriptedCatalogRepository();
|
||||
final controller = CatalogController(repository);
|
||||
repository.tickets['10'] = const PlayTicket(
|
||||
episodeId: '10',
|
||||
accessible: true,
|
||||
accessType: PlayTicket.free,
|
||||
playUrl: '/files/episode/10.mp4',
|
||||
);
|
||||
|
||||
const free = Episode(id: '10', number: 1, title: '免费集', isFree: true);
|
||||
final resolved = await controller.resolvePlay(free);
|
||||
expect(resolved.videoUrl, '/files/episode/10.mp4');
|
||||
|
||||
const locked = Episode(
|
||||
id: '11',
|
||||
number: 2,
|
||||
title: '锁定集',
|
||||
isFree: false,
|
||||
locked: true,
|
||||
);
|
||||
final lockedResolved = await controller.resolvePlay(locked);
|
||||
expect(lockedResolved.videoUrl, isEmpty);
|
||||
});
|
||||
}
|
||||
|
||||
Drama _card(String id) => Drama(
|
||||
id: id,
|
||||
title: 'Drama $id',
|
||||
synopsis: '简介 $id',
|
||||
posterUrl: '/files/$id.jpg',
|
||||
);
|
||||
|
||||
Drama _detail(String id) => Drama(
|
||||
id: id,
|
||||
title: 'Drama $id',
|
||||
synopsis: '简介 $id',
|
||||
posterUrl: '/files/$id.jpg',
|
||||
detailLoaded: true,
|
||||
episodes: const [
|
||||
Episode(id: '1', number: 1, title: '第一集', isFree: true),
|
||||
Episode(id: '2', number: 2, title: '第二集', isFree: false),
|
||||
],
|
||||
);
|
||||
|
||||
class ScriptedCatalogRepository implements CatalogRepository {
|
||||
bool fail = false;
|
||||
List<Drama> items = const [];
|
||||
HomeFeed feed = const HomeFeed();
|
||||
int detailCalls = 0;
|
||||
final Map<String, PlayTicket> tickets = {};
|
||||
|
||||
@override
|
||||
Future<List<Drama>> fetchDramas() async {
|
||||
Future<HomeFeed> fetchHomeFeed() async {
|
||||
if (fail) throw StateError('offline');
|
||||
return items;
|
||||
return feed;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<HomeFeed> fetchDiscoverFeed() async => feed;
|
||||
|
||||
@override
|
||||
Future<Drama> fetchDrama(String dramaId) async {
|
||||
detailCalls++;
|
||||
return _detail(dramaId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PlayTicket> resolvePlay(String episodeId) async {
|
||||
return tickets[episodeId] ??
|
||||
PlayTicket(
|
||||
episodeId: episodeId,
|
||||
accessible: false,
|
||||
accessType: PlayTicket.noMedia,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:nontonki/core/data/repositories/catalog_repository.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('all mock entries reuse one bundled local demo video', () async {
|
||||
final dramas = await DemoCatalogRepository().fetchDramas();
|
||||
expect(dramas, hasLength(3));
|
||||
expect(dramas.every((drama) => drama.episodes.length == 3), isTrue);
|
||||
final paths = {
|
||||
for (final drama in dramas)
|
||||
for (final episode in drama.episodes) episode.assetPath,
|
||||
};
|
||||
expect(paths, {'assets/media/demo_clip.mp4'});
|
||||
expect(
|
||||
dramas.every(
|
||||
(drama) => drama.episodes.every((episode) => episode.isFree),
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
final bytes = await rootBundle.load(paths.single);
|
||||
expect(bytes.lengthInBytes, greaterThan(1000000));
|
||||
});
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:nontonki/pages/home/home_feed_sections.dart';
|
||||
import 'package:nontonki/core/data/repositories/catalog_repository.dart';
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'home categories filter demo dramas without changing their media',
|
||||
() async {
|
||||
final dramas = await DemoCatalogRepository().fetchDramas();
|
||||
final sections = HomeFeedSections(dramas);
|
||||
|
||||
expect(sections.indicesFor(HomeFeedCategory.recommended), [0, 1, 2]);
|
||||
expect(sections.indicesFor(HomeFeedCategory.animated), [0]);
|
||||
expect(sections.indicesFor(HomeFeedCategory.liveAction), [1, 2]);
|
||||
expect(sections.indicesFor(HomeFeedCategory.following), isEmpty);
|
||||
expect(
|
||||
sections.dramaAt(HomeFeedCategory.liveAction, 0).title,
|
||||
'City Lights & Velvet Nights',
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ void main() {
|
||||
id: 'ep-$i',
|
||||
number: i + 1,
|
||||
title: 'Episode $i',
|
||||
assetPath: 'test-$i.mp4',
|
||||
videoUrl: 'https://example.test/$i.mp4',
|
||||
isFree: i < 4,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,26 +1,76 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:nontonki/core/data/repositories/catalog_repository.dart';
|
||||
import 'package:nontonki/core/data/models/drama.dart';
|
||||
import 'package:nontonki/core/data/services/playback_queue.dart';
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'home feed advances between dramas, series player between episodes',
|
||||
() async {
|
||||
final dramas = await DemoCatalogRepository().fetchDramas();
|
||||
final home = PlaybackQueue.home(dramas);
|
||||
expect(home.length, 3);
|
||||
expect(home.entryAt(0).drama.id, dramas[0].id);
|
||||
expect(home.entryAt(1).drama.id, dramas[1].id);
|
||||
expect(home.entryAt(1).episode.number, 1);
|
||||
expect(home.nextIndex(0), 1);
|
||||
expect(home.nextIndex(2), isNull);
|
||||
test('home feed advances between dramas, series player between episodes', () {
|
||||
final dramas = [_drama('a', 3), _drama('b', 2), _drama('c', 4)];
|
||||
|
||||
final series = PlaybackQueue.series(dramas[0]);
|
||||
expect(series.length, 3);
|
||||
expect(series.entryAt(0).drama.id, series.entryAt(1).drama.id);
|
||||
expect(series.entryAt(1).episode.number, 2);
|
||||
expect(series.nextIndex(0), 1);
|
||||
expect(series.nextIndex(2), isNull);
|
||||
},
|
||||
);
|
||||
final home = PlaybackQueue.home(dramas);
|
||||
expect(home.length, 3);
|
||||
expect(home.entryAt(0).drama.id, 'a');
|
||||
expect(home.entryAt(1).drama.id, 'b');
|
||||
expect(home.entryAt(1).episode.number, 1);
|
||||
expect(home.nextIndex(0), 1);
|
||||
expect(home.nextIndex(2), isNull);
|
||||
|
||||
final series = PlaybackQueue.series(dramas[0]);
|
||||
expect(series.length, 3);
|
||||
expect(series.entryAt(0).drama.id, series.entryAt(1).drama.id);
|
||||
expect(series.entryAt(1).episode.number, 2);
|
||||
expect(series.nextIndex(0), 1);
|
||||
expect(series.nextIndex(2), isNull);
|
||||
});
|
||||
|
||||
test('dramas without episodes are left out of the home queue', () {
|
||||
final home = PlaybackQueue.home([
|
||||
_drama('a', 2),
|
||||
Drama(
|
||||
id: 'empty',
|
||||
title: '没有剧集',
|
||||
synopsis: '',
|
||||
posterUrl: '/files/empty.jpg',
|
||||
),
|
||||
]);
|
||||
expect(home.length, 1);
|
||||
expect(home.entryAt(0).drama.id, 'a');
|
||||
});
|
||||
|
||||
test('a list card with a preview episode plays on the home feed', () {
|
||||
final home = PlaybackQueue.home([
|
||||
Drama.fromCardJson(const {
|
||||
'id': 5,
|
||||
'title': '闪婚后',
|
||||
'cover': '/files/cover.jpg',
|
||||
'totalEpisodes': 77,
|
||||
'preview': {
|
||||
'id': 9,
|
||||
'number': 1,
|
||||
'title': '第 1 集',
|
||||
'isFree': true,
|
||||
'playUrl': '/files/episode/9.mp4',
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(home.length, 1);
|
||||
expect(home.entryAt(0).episode.videoUrl, '/files/episode/9.mp4');
|
||||
});
|
||||
}
|
||||
|
||||
Drama _drama(String id, int episodeCount) => Drama(
|
||||
id: id,
|
||||
title: 'Drama $id',
|
||||
synopsis: '简介 $id',
|
||||
posterUrl: '/files/$id.jpg',
|
||||
episodes: [
|
||||
for (var index = 1; index <= episodeCount; index++)
|
||||
Episode(
|
||||
id: '$id-$index',
|
||||
number: index,
|
||||
title: '第 $index 集',
|
||||
isFree: true,
|
||||
videoUrl: 'https://example.test/$id-$index.mp4',
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -12,7 +12,7 @@ void main() {
|
||||
id: 'ep-${i + 1}',
|
||||
number: i + 1,
|
||||
title: 'Episode ${i + 1}',
|
||||
assetPath: 'assets/media/episode_0${i + 1}.mp4',
|
||||
videoUrl: 'https://example.test/episode_0${i + 1}.mp4',
|
||||
isFree: i < 2,
|
||||
),
|
||||
);
|
||||
@@ -99,6 +99,47 @@ void main() {
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test('pausing then swiping to the next episode resumes playback', () async {
|
||||
final factory = FakeFactory();
|
||||
final session = PlaybackSession(
|
||||
episodes: episodes,
|
||||
factory: factory.create,
|
||||
canPlay: (episode) => episode.isFree,
|
||||
);
|
||||
await session.select(0);
|
||||
session.setUserWantsPlay(false);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(session.userWantsPlay, isFalse);
|
||||
|
||||
await session.select(1);
|
||||
|
||||
expect(session.userWantsPlay, isTrue);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
final playing = session.active;
|
||||
expect(playing, isA<FakePlayer>());
|
||||
expect((playing! as FakePlayer).playCalls, greaterThan(0));
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test('re-selecting the same episode keeps the user pause', () async {
|
||||
final factory = FakeFactory();
|
||||
final session = PlaybackSession(
|
||||
episodes: episodes,
|
||||
factory: factory.create,
|
||||
canPlay: (episode) => episode.isFree,
|
||||
);
|
||||
await session.select(0);
|
||||
session.setUserWantsPlay(false);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
// 页面重新可见等场景会重复选中同一集,这时不能把暂停改成播放。
|
||||
await session.select(0);
|
||||
|
||||
expect(session.userWantsPlay, isFalse);
|
||||
expect(session.canAutoAdvance, isFalse);
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test('automatic advance respects visibility and playback intent', () async {
|
||||
final factory = FakeFactory();
|
||||
final session = PlaybackSession(
|
||||
|
||||
@@ -78,21 +78,20 @@ void main() {
|
||||
body: SeekProgressBar(
|
||||
valueListenable: video,
|
||||
semanticsLabel: 'Seek video',
|
||||
compactIdle: true,
|
||||
onSeek: (_) async {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('00:03'), findsNothing);
|
||||
expect(find.textContaining('00:12'), findsNothing);
|
||||
final gesture = await tester.startGesture(
|
||||
tester.getCenter(find.byType(Slider)),
|
||||
);
|
||||
await gesture.moveBy(const Offset(40, 0));
|
||||
await tester.pump();
|
||||
expect(find.text('00:12'), findsOneWidget);
|
||||
expect(find.textContaining('/ 00:12'), findsOneWidget);
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('00:12'), findsNothing);
|
||||
expect(find.textContaining('00:12'), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:nontonki/core/data/models/drama.dart';
|
||||
import 'package:nontonki/core/data/repositories/watch_history_repository.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';
|
||||
@@ -51,4 +52,79 @@ void main() {
|
||||
expect(await history.lastEpisodeId('profile-a', 'drama-a'), 'episode-2');
|
||||
expect(await history.lastEpisodeId('profile-a', 'drama-b'), isNull);
|
||||
});
|
||||
|
||||
test('resume prefers the first loaded episode', () async {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
final history = SharedPreferencesWatchHistoryRepository();
|
||||
await history.save(
|
||||
'profile-a',
|
||||
'drama-a',
|
||||
'episode-1',
|
||||
const Duration(seconds: 3),
|
||||
);
|
||||
await history.save(
|
||||
'profile-a',
|
||||
'drama-a',
|
||||
'episode-2',
|
||||
const Duration(seconds: 5),
|
||||
);
|
||||
|
||||
final drama = Drama(
|
||||
id: 'drama-a',
|
||||
title: 'title',
|
||||
synopsis: 'synopsis',
|
||||
posterUrl: '',
|
||||
episodes: const [
|
||||
Episode(id: 'episode-1', number: 1, title: 'E1', isFree: true),
|
||||
Episode(id: 'episode-2', number: 2, title: 'E2', isFree: true),
|
||||
],
|
||||
);
|
||||
|
||||
expect(
|
||||
await history.resumePositionFor('profile-a', drama),
|
||||
const Duration(seconds: 3),
|
||||
);
|
||||
});
|
||||
|
||||
test('resume falls back to the last watched episode for a list card', () async {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
final history = SharedPreferencesWatchHistoryRepository();
|
||||
await history.save(
|
||||
'profile-a',
|
||||
'drama-a',
|
||||
'episode-2',
|
||||
const Duration(seconds: 5),
|
||||
);
|
||||
|
||||
const card = Drama(
|
||||
id: 'drama-a',
|
||||
title: 'title',
|
||||
synopsis: 'synopsis',
|
||||
posterUrl: '',
|
||||
totalEpisodes: 12,
|
||||
);
|
||||
|
||||
expect(
|
||||
await history.resumePositionFor('profile-a', card),
|
||||
const Duration(seconds: 5),
|
||||
);
|
||||
});
|
||||
|
||||
test('a list card with no history has no resume position', () async {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.empty();
|
||||
final history = SharedPreferencesWatchHistoryRepository();
|
||||
|
||||
const card = Drama(
|
||||
id: 'drama-b',
|
||||
title: 'title',
|
||||
synopsis: 'synopsis',
|
||||
posterUrl: '',
|
||||
totalEpisodes: 12,
|
||||
);
|
||||
|
||||
expect(await history.resumePositionFor('profile-a', card), isNull);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user