53 lines
1.6 KiB
Dart
53 lines
1.6 KiB
Dart
import 'package:fancake/features/home/home_repository_firestore.dart'
|
|
show HotArchiveRule, hotArchiveOrder;
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
/// HOT ARCHIVE — Figma `2097:16415` 「목표 달성 임박 > 실시간 기여 급증 > 신규 등록, 최대 5개」.
|
|
void main() {
|
|
final t0 = DateTime(2026, 10, 1);
|
|
({String id, double percent, int recentPop, DateTime createdAt}) c(
|
|
String id,
|
|
double percent,
|
|
int recent,
|
|
int day,
|
|
) => (
|
|
id: id,
|
|
percent: percent,
|
|
recentPop: recent,
|
|
createdAt: t0.add(Duration(days: day)),
|
|
);
|
|
|
|
test('임박 → 급증 → 신규 순이고 5건까지만', () {
|
|
final order = hotArchiveOrder([
|
|
c('old', 10, 0, 0),
|
|
c('new', 10, 0, 5),
|
|
c('surge-small', 20, 100, 1),
|
|
c('surge-big', 30, 900, 0),
|
|
c('imminent-90', 90, 0, 0),
|
|
c('imminent-99', 99, 0, 0),
|
|
c('rich-but-slow', 70, 0, 6),
|
|
], const HotArchiveRule());
|
|
expect(order, [
|
|
'imminent-99',
|
|
'imminent-90',
|
|
'surge-big',
|
|
'surge-small',
|
|
'rich-but-slow',
|
|
]);
|
|
});
|
|
|
|
test('기준값은 운영값(config/policy.hotArchive)을 따르고 없으면 임시값', () {
|
|
expect(HotArchiveRule.from(null).imminentPercent, 80);
|
|
expect(HotArchiveRule.from(null).surgeWindow, const Duration(minutes: 60));
|
|
final rule = HotArchiveRule.from({
|
|
'hotArchive': {'imminentPercent': 95, 'surgeWindowMinutes': 30},
|
|
});
|
|
expect(rule.imminentPercent, 95);
|
|
expect(rule.surgeWindow, const Duration(minutes: 30));
|
|
expect(
|
|
hotArchiveOrder([c('a', 90, 0, 0), c('b', 10, 5, 0)], rule),
|
|
['b', 'a'],
|
|
);
|
|
});
|
|
}
|