Files
ReelShort/test/playback/watch_history_test.dart
T
Vicky 0e5d550b50 test(client): 用例名统一为 should_<期望>_when_<条件>(155/155)
为什么:红线第 8 条门禁立即生效,要求 Flutter 测试命名合规;此前 155 条用例名是英文自然语言
或中文描述,合规数 0/155,属存量欠账,按"先补齐再上新功能"在本批处理。

- 25 个测试文件、155 条用例改名,按「文件 + 旧名」精确定位,每条断言命中恰好 1 次才替换
- 只改名字字面量:改动行 155 删 + 155 增,无一行不含字符串字面量(断言与用例体零改动)
- 门禁:dart analyze lib test = No issues found;flutter test = 155 全过
2026-10-16 09:41:14 +08:00

131 lines
3.7 KiB
Dart

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';
void main() {
test('should_clamp_invalid_and_completed_values_when_resolving_resume_position', () {
const duration = Duration(seconds: 8);
expect(
clampResumePosition(const Duration(seconds: -1), duration),
Duration.zero,
);
expect(
clampResumePosition(const Duration(seconds: 3), duration),
const Duration(seconds: 3),
);
expect(
clampResumePosition(const Duration(seconds: 9), duration),
Duration.zero,
);
expect(
clampResumePosition(const Duration(milliseconds: 7700), duration),
Duration.zero,
);
});
test('should_scope_history_by_profile_drama_and_episode_when_saving', () 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),
);
expect(
await history.positionFor('profile-a', 'drama-a', 'episode-1'),
const Duration(seconds: 3),
);
expect(
await history.positionFor('profile-b', 'drama-a', 'episode-1'),
isNull,
);
expect(await history.lastEpisodeId('profile-a', 'drama-a'), 'episode-2');
expect(await history.lastEpisodeId('profile-a', 'drama-b'), isNull);
});
test('should_prefer_first_loaded_episode_when_resuming', () 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('should_fall_back_to_last_watched_episode_when_resuming_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('should_have_no_resume_position_when_list_card_has_no_history', () 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);
});
}