forked from baron/baron-sso
테스트 로직 강화, hydra 연동 데이터 용량 제한 완화.
This commit is contained in:
109
userfront/test/dashboard_providers_test.dart
Normal file
109
userfront/test/dashboard_providers_test.dart
Normal file
@@ -0,0 +1,109 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:userfront/features/dashboard/domain/dashboard_providers.dart';
|
||||
import 'package:userfront/features/dashboard/domain/models.dart';
|
||||
|
||||
AuditLogEntry _log(String id) {
|
||||
return AuditLogEntry.fromJson({
|
||||
'event_id': id,
|
||||
'timestamp': '2026-02-06T00:00:00Z',
|
||||
'status': 'success',
|
||||
'session_id': 's-$id',
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _drainMicrotasks() async {
|
||||
for (var i = 0; i < 5; i++) {
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('AuthTimelineNotifier는 초기 페이지를 로드한다', () async {
|
||||
final cursors = <String?>[];
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
authTimelineFetcherProvider.overrideWithValue(({String? cursor}) async {
|
||||
cursors.add(cursor);
|
||||
return AuditPage(items: [_log('1')], nextCursor: 'next');
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
||||
container.read(authTimelineProvider.notifier);
|
||||
|
||||
await _drainMicrotasks();
|
||||
|
||||
final state = container.read(authTimelineProvider);
|
||||
expect(state.items.length, 1);
|
||||
expect(state.nextCursor, 'next');
|
||||
expect(cursors, [null]);
|
||||
container.dispose();
|
||||
});
|
||||
|
||||
test('AuthTimelineNotifier는 다음 커서를 사용해 추가 로드한다', () async {
|
||||
final cursors = <String?>[];
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
authTimelineFetcherProvider.overrideWithValue(({String? cursor}) async {
|
||||
cursors.add(cursor);
|
||||
if (cursor == null) {
|
||||
return AuditPage(items: [_log('1')], nextCursor: 'next');
|
||||
}
|
||||
return AuditPage(items: [_log('2')], nextCursor: '');
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
||||
final notifier = container.read(authTimelineProvider.notifier);
|
||||
await _drainMicrotasks();
|
||||
await notifier.loadMore();
|
||||
|
||||
final state = container.read(authTimelineProvider);
|
||||
expect(state.items.map((e) => e.eventId).toList(), ['1', '2']);
|
||||
expect(cursors, [null, 'next']);
|
||||
container.dispose();
|
||||
});
|
||||
|
||||
test('AuthTimelineNotifier는 커서가 없으면 추가 로드를 하지 않는다', () async {
|
||||
var callCount = 0;
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
authTimelineFetcherProvider.overrideWithValue(({String? cursor}) async {
|
||||
callCount += 1;
|
||||
return AuditPage(items: [_log('1')], nextCursor: '');
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
||||
final notifier = container.read(authTimelineProvider.notifier);
|
||||
await _drainMicrotasks();
|
||||
await notifier.loadMore();
|
||||
|
||||
expect(callCount, 1);
|
||||
expect(container.read(authTimelineProvider).items.length, 1);
|
||||
container.dispose();
|
||||
});
|
||||
|
||||
test('AuthTimelineNotifier는 실패 시 오류 메시지를 보관한다', () async {
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
authTimelineFetcherProvider.overrideWithValue(({String? cursor}) async {
|
||||
throw Exception('fail');
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
||||
container.read(authTimelineProvider.notifier);
|
||||
|
||||
await _drainMicrotasks();
|
||||
|
||||
final state = container.read(authTimelineProvider);
|
||||
expect(state.items.isEmpty, true);
|
||||
expect(state.error, '접속이력을 불러오지 못했습니다.');
|
||||
container.dispose();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user