style(app): 格式化并拆分长函数
This commit is contained in:
1 parent
2b2b7e9913
commit
7850dfc746
31 files changed
+388
-318
No files matched your search
@@ -1,4 +1,4 @@
|
||||
// Author: fruit.com.cn
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -8,7 +8,11 @@ import 'package:fruitshorts/pages/discover/discover_logic.dart';
|
||||
|
||||
import '../support/fake_watch_history.dart';
|
||||
|
||||
Drama _drama(String id, {List<int> numbers = const [1, 2, 3], String language = ''}) => Drama(
|
||||
Drama _drama(
|
||||
String id, {
|
||||
List<int> numbers = const [1, 2, 3],
|
||||
String language = '',
|
||||
}) => Drama(
|
||||
language: language,
|
||||
id: id,
|
||||
title: id,
|
||||
@@ -29,15 +33,18 @@ Drama _drama(String id, {List<int> numbers = const [1, 2, 3], String language =
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('should_resolve_resume_position_of_episode_one_when_constructed', () async {
|
||||
final history = FakeWatchHistory()..saved = const Duration(seconds: 4);
|
||||
final logic = DiscoverLogic(history: history, drama: _drama('signal'));
|
||||
test(
|
||||
'should_resolve_resume_position_of_episode_one_when_constructed',
|
||||
() async {
|
||||
final history = FakeWatchHistory()..saved = const Duration(seconds: 4);
|
||||
final logic = DiscoverLogic(history: history, drama: _drama('signal'));
|
||||
|
||||
expect(await logic.position, const Duration(seconds: 4));
|
||||
expect(history.reads, ['signal']);
|
||||
expect(logic.searchOpen, isFalse);
|
||||
logic.dispose();
|
||||
});
|
||||
expect(await logic.position, const Duration(seconds: 4));
|
||||
expect(history.reads, ['signal']);
|
||||
expect(logic.searchOpen, isFalse);
|
||||
logic.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
test('should_reread_resume_position_when_drama_is_swapped', () async {
|
||||
final history = FakeWatchHistory();
|
||||
@@ -51,22 +58,28 @@ void main() {
|
||||
logic.dispose();
|
||||
});
|
||||
|
||||
test('should_resume_from_last_watch_when_list_card_has_no_episodes', () async {
|
||||
final history = FakeWatchHistory()
|
||||
..saved = const Duration(seconds: 9)
|
||||
..lastEpisode = 'signal-2';
|
||||
final logic = DiscoverLogic(
|
||||
history: history,
|
||||
drama: _drama('signal', numbers: const []),
|
||||
);
|
||||
test(
|
||||
'should_resume_from_last_watch_when_list_card_has_no_episodes',
|
||||
() async {
|
||||
final history = FakeWatchHistory()
|
||||
..saved = const Duration(seconds: 9)
|
||||
..lastEpisode = 'signal-2';
|
||||
final logic = DiscoverLogic(
|
||||
history: history,
|
||||
drama: _drama('signal', numbers: const []),
|
||||
);
|
||||
|
||||
expect(await logic.position, const Duration(seconds: 9));
|
||||
expect(history.reads, ['signal']);
|
||||
logic.dispose();
|
||||
});
|
||||
expect(await logic.position, const Duration(seconds: 9));
|
||||
expect(history.reads, ['signal']);
|
||||
logic.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
test('should_filter_visible_dramas_when_language_is_selected', () {
|
||||
final logic = DiscoverLogic(history: FakeWatchHistory(), drama: _drama('s'));
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
);
|
||||
final dramas = [
|
||||
_drama('zh', language: 'zh-CN'),
|
||||
_drama('id', language: 'id'),
|
||||
@@ -84,7 +97,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('should_list_distinct_languages_when_feed_has_cards', () {
|
||||
final logic = DiscoverLogic(history: FakeWatchHistory(), drama: _drama('s'));
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
);
|
||||
final dramas = [
|
||||
_drama('zh', language: 'zh-CN'),
|
||||
_drama('id', language: 'id'),
|
||||
@@ -109,7 +125,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('should_show_search_when_flag_is_on_or_text_is_typed', () {
|
||||
final logic = DiscoverLogic(history: FakeWatchHistory(), drama: _drama('s'));
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
);
|
||||
|
||||
expect(logic.showSearch, isFalse);
|
||||
|
||||
@@ -126,7 +145,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('should_match_by_id_and_tolerate_missing_id_when_looking_up_drama', () {
|
||||
final logic = DiscoverLogic(history: FakeWatchHistory(), drama: _drama('s'));
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
);
|
||||
final catalog = [_drama('signal'), _drama('city')];
|
||||
|
||||
expect(logic.dramaFor('city', catalog)?.id, 'city');
|
||||
@@ -167,7 +189,12 @@ void main() {
|
||||
|
||||
// Staying active with a changed drama re-reads history.
|
||||
history.reads.clear();
|
||||
sync(_drama('vengeance'), active: true, wasActive: true, dramaChanged: true);
|
||||
sync(
|
||||
_drama('vengeance'),
|
||||
active: true,
|
||||
wasActive: true,
|
||||
dramaChanged: true,
|
||||
);
|
||||
expect(logic.drama.id, 'vengeance');
|
||||
expect(history.reads, ['vengeance']);
|
||||
|
||||
@@ -179,43 +206,50 @@ void main() {
|
||||
logic.dispose();
|
||||
});
|
||||
|
||||
testWidgets('should_open_and_focus_field_when_search_is_requested_and_page_is_active', (
|
||||
tester,
|
||||
) async {
|
||||
final logic = DiscoverLogic(history: FakeWatchHistory(), drama: _drama('s'));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: TextField(
|
||||
controller: logic.search,
|
||||
focusNode: logic.searchFocus,
|
||||
testWidgets(
|
||||
'should_open_and_focus_field_when_search_is_requested_and_page_is_active',
|
||||
(tester) async {
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: TextField(
|
||||
controller: logic.search,
|
||||
focusNode: logic.searchFocus,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
|
||||
logic.syncDrama(
|
||||
active: true,
|
||||
wasActive: true,
|
||||
nextDrama: logic.drama,
|
||||
dramaChanged: false,
|
||||
searchRequest: 1,
|
||||
previousSearchRequest: 0,
|
||||
isActive: () => true,
|
||||
);
|
||||
logic.syncDrama(
|
||||
active: true,
|
||||
wasActive: true,
|
||||
nextDrama: logic.drama,
|
||||
dramaChanged: false,
|
||||
searchRequest: 1,
|
||||
previousSearchRequest: 0,
|
||||
isActive: () => true,
|
||||
);
|
||||
|
||||
expect(logic.searchOpen, isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(logic.searchFocus.hasFocus, isTrue);
|
||||
expect(logic.searchOpen, isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(logic.searchFocus.hasFocus, isTrue);
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
logic.dispose();
|
||||
});
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
logic.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('should_keep_search_field_closed_when_page_is_hidden', (
|
||||
tester,
|
||||
) async {
|
||||
final logic = DiscoverLogic(history: FakeWatchHistory(), drama: _drama('s'));
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
@@ -250,7 +284,10 @@ void main() {
|
||||
testWidgets('should_return_choice_and_forward_it_when_act_runs_embedded', (
|
||||
tester,
|
||||
) async {
|
||||
final logic = DiscoverLogic(history: FakeWatchHistory(), drama: _drama('s'));
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
);
|
||||
final forwarded = <DiscoverPageAction>[];
|
||||
final popped = Completer<DiscoverPageAction?>();
|
||||
late BuildContext pageContext;
|
||||
@@ -297,7 +334,10 @@ void main() {
|
||||
testWidgets('should_show_artwork_notice_when_card_has_no_playable_media', (
|
||||
tester,
|
||||
) async {
|
||||
final logic = DiscoverLogic(history: FakeWatchHistory(), drama: _drama('s'));
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
);
|
||||
late BuildContext context;
|
||||
|
||||
await tester.pumpWidget(
|
||||
@@ -322,8 +362,13 @@ void main() {
|
||||
logic.dispose();
|
||||
});
|
||||
|
||||
testWidgets('should_forward_chosen_drama_when_card_is_embedded', (tester) async {
|
||||
final logic = DiscoverLogic(history: FakeWatchHistory(), drama: _drama('s'));
|
||||
testWidgets('should_forward_chosen_drama_when_card_is_embedded', (
|
||||
tester,
|
||||
) async {
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
);
|
||||
late BuildContext context;
|
||||
Drama? selected;
|
||||
|
||||
@@ -350,7 +395,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('should_do_nothing_when_notifying_after_dispose', () {
|
||||
final logic = DiscoverLogic(history: FakeWatchHistory(), drama: _drama('s'));
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('s'),
|
||||
);
|
||||
var notifications = 0;
|
||||
logic.addListener(() => notifications++);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Author: fruit.com.cn
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
@@ -21,23 +21,28 @@ Drama _drama(String id, {String language = 'id'}) => Drama(
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('should_query_backend_and_render_results_when_search_text_changes', () async {
|
||||
final repository = _FakeSearchRepository(results: [_drama('velvet')]);
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('signal'),
|
||||
searchRepository: repository,
|
||||
)..searchDebounce = Duration.zero;
|
||||
test(
|
||||
'should_query_backend_and_render_results_when_search_text_changes',
|
||||
() async {
|
||||
final repository = _FakeSearchRepository(results: [_drama('velvet')]);
|
||||
final logic = DiscoverLogic(
|
||||
history: FakeWatchHistory(),
|
||||
drama: _drama('signal'),
|
||||
searchRepository: repository,
|
||||
)..searchDebounce = Duration.zero;
|
||||
|
||||
logic.search.text = 'velvet';
|
||||
logic.onSearchChanged();
|
||||
await pumpEventQueue();
|
||||
logic.search.text = 'velvet';
|
||||
logic.onSearchChanged();
|
||||
await pumpEventQueue();
|
||||
|
||||
expect(repository.calls, [(keyword: 'velvet', pageIndex: 1, pageSize: 20)]);
|
||||
expect(logic.searchLoading, isFalse);
|
||||
expect(logic.visibleDramas(const []).single.id, 'velvet');
|
||||
logic.dispose();
|
||||
});
|
||||
expect(repository.calls, [
|
||||
(keyword: 'velvet', pageIndex: 1, pageSize: 20),
|
||||
]);
|
||||
expect(logic.searchLoading, isFalse);
|
||||
expect(logic.visibleDramas(const []).single.id, 'velvet');
|
||||
logic.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
test('should_keep_server_results_when_text_only_loses_whitespace', () async {
|
||||
final repository = _FakeSearchRepository(results: [_drama('velvet')]);
|
||||
|
||||
Reference in new issue
Block a user