공개페이지
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_entry_screen.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
DioException dio404(String path) => DioException(
|
||||
requestOptions: RequestOptions(path: path),
|
||||
response: Response(requestOptions: RequestOptions(path: path), statusCode: 404),
|
||||
type: DioExceptionType.badResponse,
|
||||
);
|
||||
|
||||
class Stub404Service extends PublicEventService {
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
throw dio404('/api/public/' + publicHash);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('shows 404 message and go to entry button navigates back', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'nope', service: Stub404Service()),
|
||||
));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('이벤트를 찾을 수 없습니다'), findsOneWidget);
|
||||
expect(find.byKey(const Key('go_entry_button')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('go_entry_button')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(PublicEventEntryScreen), findsOneWidget);
|
||||
expect(find.text('공개 이벤트 입장'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_entry_screen.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
DioException dio401(String path) => DioException(
|
||||
requestOptions: RequestOptions(path: path),
|
||||
response: Response(requestOptions: RequestOptions(path: path), statusCode: 401),
|
||||
type: DioExceptionType.badResponse,
|
||||
);
|
||||
|
||||
class StubFetch401Service extends PublicEventService {
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
throw dio401('/api/public/' + publicHash);
|
||||
}
|
||||
}
|
||||
|
||||
class StubUpdate401Service extends PublicEventService {
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
return {
|
||||
'event': {'id': 'E1', 'title': '테스트 이벤트', 'gameCount': 3, 'status': 'active'},
|
||||
'participants': [
|
||||
{
|
||||
'participantId': 'p1',
|
||||
'name': 'Kim',
|
||||
'scores': [100, null, null],
|
||||
'handicap': 0,
|
||||
},
|
||||
],
|
||||
'teams': [],
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateScore(String publicHash, {required String participantId, required int gameNumber, required int score, int? handicap, dynamic teamNumber}) async {
|
||||
throw dio401('/api/public/' + publicHash + '/score');
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('401 on fetchEvent navigates to entry screen', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'abc', service: StubFetch401Service()),
|
||||
));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(PublicEventEntryScreen), findsOneWidget);
|
||||
expect(find.text('공개 이벤트 입장'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('401 on updateScore navigates to entry screen', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'abc', service: StubUpdate401Service()),
|
||||
));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('participant_tile_p1')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('participant_tile_p1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.enterText(find.byKey(const Key('score_input')), '150');
|
||||
await tester.tap(find.byKey(const Key('score_save_button')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(PublicEventEntryScreen), findsOneWidget);
|
||||
expect(find.text('공개 이벤트 입장'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_entry_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
class StubSuccessService extends PublicEventService {
|
||||
@override
|
||||
Future<Map<String, dynamic>> enter(String publicHash, {String? password}) async {
|
||||
// 즉시 성공(토큰 포함)
|
||||
return {'token': 'TKN', 'event': {'id': 'E1'}};
|
||||
}
|
||||
}
|
||||
|
||||
class StubNeedPasswordThenSuccessService extends PublicEventService {
|
||||
bool first = true;
|
||||
@override
|
||||
Future<Map<String, dynamic>> enter(String publicHash, {String? password}) async {
|
||||
if (first) {
|
||||
first = false;
|
||||
throw Exception('401 need password');
|
||||
}
|
||||
if (password == 'pw') {
|
||||
return {'token': 'TKN2', 'event': {'id': 'E2'}};
|
||||
}
|
||||
throw Exception('wrong password');
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('auto enter success navigates to PublicEventScreen', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventEntryScreen(publicHash: 'auto', service: StubSuccessService()),
|
||||
));
|
||||
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('공개 이벤트'), findsOneWidget);
|
||||
expect(find.text('공개 이벤트 입장'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('needs password then success on submit', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventEntryScreen(publicHash: 'needpw', service: StubNeedPasswordThenSuccessService()),
|
||||
));
|
||||
|
||||
// 초기 자동 진입 실패 → 비밀번호 UI 노출
|
||||
await tester.pump();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('public_password_field')), findsOneWidget);
|
||||
|
||||
// 비밀번호 입력 후 제출
|
||||
await tester.enterText(find.byKey(const Key('public_password_field')), 'pw');
|
||||
await tester.tap(find.byKey(const Key('public_enter_submit')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('공개 이벤트'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
class StubFinalService extends PublicEventService {
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
return {
|
||||
'event': {'id': 'E1', 'title': '최종 결과 테스트', 'gameCount': 3, 'status': 'completed'},
|
||||
'participants': [
|
||||
{
|
||||
'participantId': 'p1',
|
||||
'name': 'Kim',
|
||||
'scores': [140, 150, 0],
|
||||
'handicap': 0,
|
||||
},
|
||||
{
|
||||
'participantId': 'p2',
|
||||
'name': 'Lee',
|
||||
'scores': [200, 100, 0],
|
||||
'handicap': 0,
|
||||
},
|
||||
{
|
||||
'participantId': 'p3',
|
||||
'name': 'Park',
|
||||
'scores': [200, 100, 0],
|
||||
'handicap': 0,
|
||||
},
|
||||
],
|
||||
'teams': [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('완료 상태에서 최종 결과 섹션 렌더와 동순위 처리, 평균 1자리', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'H', service: StubFinalService()),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 최종 결과 섹션 존재 (스크롤 필요 시 스크롤)
|
||||
final scrollable = find.byType(Scrollable).first;
|
||||
await tester.scrollUntilVisible(find.byKey(const Key('section_final_results')), 300, scrollable: scrollable);
|
||||
expect(find.byKey(const Key('section_final_results')), findsOneWidget);
|
||||
|
||||
// 각 행 존재
|
||||
expect(find.byKey(const Key('result_row_p1')), findsOneWidget);
|
||||
expect(find.byKey(const Key('result_row_p2')), findsOneWidget);
|
||||
expect(find.byKey(const Key('result_row_p3')), findsOneWidget);
|
||||
|
||||
// 총점: p2/p3=300, p1=300 (동률), 동순위 1,1,3
|
||||
expect(find.byKey(const Key('result_rank_p2')), findsOneWidget);
|
||||
expect(find.byKey(const Key('result_rank_p3')), findsOneWidget);
|
||||
expect(find.byKey(const Key('result_rank_p1')), findsOneWidget);
|
||||
|
||||
final r2 = tester.widget<Text>(find.byKey(const Key('result_rank_p2'))).data;
|
||||
final r3 = tester.widget<Text>(find.byKey(const Key('result_rank_p3'))).data;
|
||||
final r1 = tester.widget<Text>(find.byKey(const Key('result_rank_p1'))).data;
|
||||
|
||||
expect(r2, '1');
|
||||
expect(r3, '1');
|
||||
expect(r1, '3');
|
||||
|
||||
// 평균 표기 1자리 확인: 0점도 입력으로 카운트됨 → p2: (200+100+0)/3 = 100.0
|
||||
expect(find.textContaining('평균 100.0'), findsWidgets);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
class StubInlineService extends PublicEventService {
|
||||
int fetchCount = 0;
|
||||
int updateCount = 0;
|
||||
final List<Map<String, dynamic>> calls = [];
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
fetchCount++;
|
||||
return {
|
||||
'event': {'id': 'E1', 'title': '인라인 저장 테스트', 'gameCount': 3, 'status': 'active'},
|
||||
'participants': [
|
||||
{
|
||||
'participantId': 'p1',
|
||||
'name': 'Kim',
|
||||
'scores': [null, null, null],
|
||||
'handicap': 0,
|
||||
},
|
||||
],
|
||||
'teams': [],
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateScore(String publicHash, {required String participantId, required int gameNumber, required int score, int? handicap, teamNumber}) async {
|
||||
updateCount++;
|
||||
calls.add({'pid': participantId, 'g': gameNumber, 's': score});
|
||||
// simulate small delay
|
||||
await Future<void>.delayed(const Duration(milliseconds: 1));
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('3자리 입력 즉시 저장, 디바운스 저장, 범위 밖 값은 저장 안함', (tester) async {
|
||||
final stub = StubInlineService();
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'H', service: stub),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// cell p1 game2 존재 확인
|
||||
final cellG2 = find.byKey(const Key('cell_p1_2'));
|
||||
expect(cellG2, findsOneWidget);
|
||||
|
||||
// 3자리 입력 즉시 저장
|
||||
await tester.enterText(cellG2, '150');
|
||||
// allow microtasks
|
||||
await tester.pump(const Duration(milliseconds: 10));
|
||||
expect(stub.updateCount, 1);
|
||||
expect(stub.calls.last['s'], 150);
|
||||
|
||||
// 1자리 입력 후 디바운스 200ms 후 저장
|
||||
await tester.enterText(cellG2, '2');
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(stub.updateCount, 2);
|
||||
expect(stub.calls.last['s'], 2);
|
||||
|
||||
// 범위 밖 값은 저장 안함 (350)
|
||||
await tester.enterText(cellG2, '350');
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
expect(stub.updateCount, 2);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
class StubJoinService extends PublicEventService {
|
||||
int fetchCount = 0;
|
||||
bool addGuestCalled = false;
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
fetchCount++;
|
||||
return {
|
||||
'event': {'id': 'E1', 'title': 'Join 테스트', 'gameCount': 3, 'status': 'ready'},
|
||||
'participants': [
|
||||
{
|
||||
'participantId': 'p1',
|
||||
'name': 'Kim',
|
||||
'scores': [null, null, null],
|
||||
'handicap': 0,
|
||||
},
|
||||
],
|
||||
'teams': [],
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addGuest(String publicHash, {required String name, String? phone, String? gender, num? average}) async {
|
||||
addGuestCalled = true;
|
||||
await Future<void>.delayed(const Duration(milliseconds: 10));
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('join button opens dialog, saves, and reloads (fetch called twice)', (tester) async {
|
||||
final stub = StubJoinService();
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'HASH', service: stub),
|
||||
));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(stub.fetchCount, 1);
|
||||
expect(find.byKey(const Key('join_button')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('join_button')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('참가 신청(게스트)'), findsOneWidget);
|
||||
|
||||
await tester.enterText(find.byKey(const Key('join_name_input')), 'New Guest');
|
||||
await tester.tap(find.byKey(const Key('join_save_button')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(stub.addGuestCalled, isTrue);
|
||||
// reload triggered
|
||||
expect(stub.fetchCount, 2);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/main.dart' as app;
|
||||
|
||||
void main() {
|
||||
testWidgets('navigates to PublicEventEntryScreen with /p/:hash', (tester) async {
|
||||
// MyApp은 내부에서 routes/onGenerateRoute를 정의하므로 직접 runApp
|
||||
await tester.pumpWidget(const app.MyApp());
|
||||
|
||||
// 초기 홈이 뜬 후, 라우트 푸시
|
||||
final nav = app.navigatorKey.currentState!;
|
||||
nav.pushNamed('/p/abc123');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('공개 이벤트 입장'), findsOneWidget);
|
||||
expect(find.textContaining('abc123'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
class StubColorService extends PublicEventService {
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
return {
|
||||
'event': {'id': 'E1', 'title': '색상/상태 테스트', 'gameCount': 3, 'status': 'active'},
|
||||
'participants': [
|
||||
{
|
||||
'participantId': 'p1',
|
||||
'name': 'Kim',
|
||||
'scores': [null, null, null],
|
||||
'handicap': 0,
|
||||
},
|
||||
],
|
||||
'teams': [],
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateScore(String publicHash, {required String participantId, required int gameNumber, required int score, int? handicap, teamNumber}) async {
|
||||
// no-op
|
||||
await Future<void>.delayed(const Duration(milliseconds: 1));
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('200 입력 시 색상 빨강으로 표시', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'H', service: StubColorService()),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 초기에는 회색 점
|
||||
final colorDot = find.byKey(const Key('color_p1_1'));
|
||||
expect(colorDot, findsOneWidget);
|
||||
|
||||
// 200 입력
|
||||
final cell = find.byKey(const Key('cell_p1_1'));
|
||||
await tester.enterText(cell, '200');
|
||||
await tester.pump(const Duration(milliseconds: 20));
|
||||
|
||||
// 색상 컨테이너를 가져와서 색상을 확인
|
||||
final container = tester.widget<Container>(colorDot);
|
||||
final deco = container.decoration as BoxDecoration;
|
||||
expect((deco.color as Color), equals(Colors.red));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
class StubDialogService extends PublicEventService {
|
||||
String? lastHash;
|
||||
String? lastParticipantId;
|
||||
int? lastGameNumber;
|
||||
int? lastScore;
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
return {
|
||||
'event': {'id': 'E1', 'title': '다이얼로그 테스트', 'gameCount': 3, 'status': 'active'},
|
||||
'participants': [
|
||||
{
|
||||
'participantId': 'p1',
|
||||
'name': 'Kim',
|
||||
'scores': [null, null, null],
|
||||
'handicap': 0,
|
||||
},
|
||||
],
|
||||
'teams': [],
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateScore(String publicHash, {required String participantId, required int gameNumber, required int score, int? handicap, dynamic teamNumber}) async {
|
||||
lastHash = publicHash;
|
||||
lastParticipantId = participantId;
|
||||
lastGameNumber = gameNumber;
|
||||
lastScore = score;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('game select and validation works in score dialog', (tester) async {
|
||||
final stub = StubDialogService();
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'hash-validate', service: stub),
|
||||
));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('participant_tile_p1')), findsOneWidget);
|
||||
|
||||
// Open dialog
|
||||
await tester.tap(find.byKey(const Key('participant_tile_p1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Select game 2
|
||||
await tester.tap(find.byKey(const Key('game_select')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('게임 2').last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Enter invalid value
|
||||
await tester.enterText(find.byKey(const Key('score_input')), '350');
|
||||
await tester.tap(find.byKey(const Key('score_save_button')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('0~300'), findsOneWidget);
|
||||
|
||||
// Enter valid value
|
||||
await tester.enterText(find.byKey(const Key('score_input')), '180');
|
||||
await tester.tap(find.byKey(const Key('score_save_button')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Saved and called with game 2
|
||||
expect(stub.lastHash, 'hash-validate');
|
||||
expect(stub.lastParticipantId, 'p1');
|
||||
expect(stub.lastGameNumber, 2);
|
||||
expect(stub.lastScore, 180);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
class StubScoreService extends PublicEventService {
|
||||
String? lastHash;
|
||||
String? lastParticipantId;
|
||||
int? lastGameNumber;
|
||||
int? lastScore;
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
return {
|
||||
'event': {'id': 'E1', 'title': '테스트 이벤트', 'gameCount': 3, 'status': 'active'},
|
||||
'participants': [
|
||||
{
|
||||
'participantId': 'p1',
|
||||
'name': 'Kim',
|
||||
'scores': [100, null, null],
|
||||
'handicap': 0,
|
||||
},
|
||||
],
|
||||
'teams': [],
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateScore(String publicHash, {required String participantId, required int gameNumber, required int score, int? handicap, dynamic teamNumber}) async {
|
||||
lastHash = publicHash;
|
||||
lastParticipantId = participantId;
|
||||
lastGameNumber = gameNumber;
|
||||
lastScore = score;
|
||||
await Future<void>.delayed(const Duration(milliseconds: 10));
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('tap participant -> edit game1 score -> calls updateScore and shows snackbar', (tester) async {
|
||||
final stub = StubScoreService();
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'hash123', service: stub),
|
||||
));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('participant_tile_p1')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('participant_tile_p1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 입력 후 저장
|
||||
await tester.enterText(find.byKey(const Key('score_input')), '199');
|
||||
await tester.tap(find.byKey(const Key('score_save_button')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 스낵바 문구 확인
|
||||
expect(find.text('점수가 저장되었습니다'), findsOneWidget);
|
||||
|
||||
// 서비스 호출 확인
|
||||
expect(stub.lastHash, 'hash123');
|
||||
expect(stub.lastParticipantId, 'p1');
|
||||
expect(stub.lastGameNumber, 1);
|
||||
expect(stub.lastScore, 199);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
class StubFetchService extends PublicEventService {
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
return {
|
||||
'event': {'id': 'E100', 'title': '오픈 리그'},
|
||||
'participants': [
|
||||
{'participantId': '1', 'name': 'Kim'},
|
||||
{'participantId': '2', 'name': 'Lee'},
|
||||
],
|
||||
'teams': [
|
||||
{'teamId': 'T1'},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('renders title and counts from fetchEvent', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'abc', service: StubFetchService()),
|
||||
));
|
||||
|
||||
// initial loading
|
||||
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('event_title')), findsOneWidget);
|
||||
expect(find.text('오픈 리그'), findsOneWidget);
|
||||
expect(find.byKey(const Key('participants_count')), findsOneWidget);
|
||||
final pc = tester.widget<Text>(find.byKey(const Key('participants_count')));
|
||||
expect(pc.data, '총 2명');
|
||||
expect(find.byKey(const Key('teams_count')), findsOneWidget);
|
||||
expect(find.text('총 1팀'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
class StubStateService extends PublicEventService {
|
||||
final String status;
|
||||
StubStateService(this.status);
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
return {
|
||||
'event': {'id': 'E1', 'title': '상태 테스트', 'gameCount': 3, 'status': status},
|
||||
'participants': [
|
||||
{
|
||||
'participantId': 'p1',
|
||||
'name': 'Kim',
|
||||
'scores': [null, null, null],
|
||||
'handicap': 0,
|
||||
},
|
||||
],
|
||||
'teams': [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('ready: shows join button, blocks score dialog', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'H', service: StubStateService('ready')),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('join_button')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('participant_tile_p1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// dialog should NOT appear, snackbar appears
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(find.textContaining('불가'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('active: shows join button, allows score dialog', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'H', service: StubStateService('active')),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('join_button')), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('participant_tile_p1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('completed: hides join button, blocks score dialog', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'H', service: StubStateService('completed')),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('join_button')), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('participant_tile_p1')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(find.textContaining('불가'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
class StubTeamsService extends PublicEventService {
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
return {
|
||||
'event': {'id': 'E1', 'title': '팀/미배정 테스트', 'gameCount': 3, 'status': 'active'},
|
||||
'participants': [
|
||||
{
|
||||
'participantId': 'p1',
|
||||
'name': 'Kim',
|
||||
'scores': [100, 100, 100],
|
||||
'handicap': 0,
|
||||
},
|
||||
{
|
||||
'participantId': 'p2',
|
||||
'name': 'Lee',
|
||||
'scores': [120, 110, 90],
|
||||
'handicap': 0,
|
||||
},
|
||||
],
|
||||
'teams': [
|
||||
{
|
||||
'teamId': 'T1',
|
||||
'teamNumber': 1,
|
||||
'handicap': 0,
|
||||
'members': [
|
||||
{
|
||||
'participantId': 'p1',
|
||||
'name': 'Kim',
|
||||
'scores': [100, 100, 100],
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('팀 순위 배지와 미배정 목록 렌더', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'H', service: StubTeamsService()),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 팀 섹션 (스크롤 필요 시 스크롤)
|
||||
final scrollable = find.byType(Scrollable).first;
|
||||
await tester.scrollUntilVisible(find.byKey(const Key('section_teams')), 300, scrollable: scrollable);
|
||||
expect(find.byKey(const Key('section_teams')), findsOneWidget);
|
||||
expect(find.byKey(const Key('team_rank_1')), findsOneWidget);
|
||||
|
||||
// 미배정: p2가 표시되어야 함 (필요 시 더 스크롤)
|
||||
await tester.scrollUntilVisible(find.byKey(const Key('section_unassigned')), 300, scrollable: scrollable);
|
||||
expect(find.byKey(const Key('section_unassigned')), findsOneWidget);
|
||||
expect(find.byKey(const Key('unassigned_count')), findsOneWidget);
|
||||
await tester.scrollUntilVisible(find.byKey(const Key('unassigned_p2')), 300, scrollable: scrollable);
|
||||
expect(find.byKey(const Key('unassigned_p2')), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lanebow/screens/public_event/public_event_screen.dart';
|
||||
import 'package:lanebow/services/public_event_service.dart';
|
||||
|
||||
class StubTotalsService extends PublicEventService {
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchEvent(String publicHash) async {
|
||||
return {
|
||||
'event': {'id': 'E1', 'title': '합계/평균 테스트', 'gameCount': 3},
|
||||
'participants': [
|
||||
{
|
||||
'participantId': 'p1',
|
||||
'name': 'Kim',
|
||||
'handicap': 10,
|
||||
'scores': [100, 120, 130], // per-game hc 없음 → 기본 hc=10 적용
|
||||
},
|
||||
{
|
||||
'participantId': 'p2',
|
||||
'name': 'Lee',
|
||||
'handicap': 0,
|
||||
'scores': [200, null, 50], // null은 미집계
|
||||
}
|
||||
],
|
||||
'teams': [
|
||||
{
|
||||
'teamId': 'T1',
|
||||
'teamNumber': 1,
|
||||
'handicap': 0,
|
||||
'members': [
|
||||
{
|
||||
'participantId': 'm1',
|
||||
'name': 'A',
|
||||
'scores': [100, 100, 100]
|
||||
},
|
||||
{
|
||||
'participantId': 'm2',
|
||||
'name': 'B',
|
||||
'scores': [50, null, 50]
|
||||
},
|
||||
]
|
||||
}
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('renders participant totals and team total/avg', (tester) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: PublicEventScreen(publicHash: 'hash-totals', service: StubTotalsService()),
|
||||
));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 참가자 합계 검증
|
||||
// Kim: (100+10) + (120+10) + (130+10) = 380 → 300 cap 없음 → 380
|
||||
expect(find.textContaining('총 380'), findsOneWidget);
|
||||
// Lee: (200+0) + (50+0) = 250
|
||||
expect(find.textContaining('총 250'), findsOneWidget);
|
||||
|
||||
// 팀 합계/평균 검증
|
||||
// team members total: A:300, B:100 → 합 400, 팀 hc 0 → 총 400, 인원2 → 평균 200.0
|
||||
expect(find.textContaining('총 400'), findsOneWidget);
|
||||
expect(find.textContaining('평균 200.0'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user