98 lines
4.1 KiB
Dart
98 lines
4.1 KiB
Dart
import 'package:fancake/features/campaign/campaign_share.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fancake/core/data/invite_code.dart';
|
|
|
|
/// 공유 문구 — 정책 원장 **B-78** 의 판정 기준을 코드로 고정한다.
|
|
///
|
|
/// *콘텐츠 유형별로 해시태그 구성이 달라짐 · 고정 3종 하드코딩 0건 · 최대 3개 초과 0건*
|
|
|
|
void main() {
|
|
group('해시태그 (B-78)', () {
|
|
test('브랜드·팬덤·주제 셋이 다 있으면 세 개다', () {
|
|
expect(
|
|
shareHashtags(fandomName: 'BTS', topic: '캠페인'),
|
|
['#FANUZU', '#BTS', '#캠페인'],
|
|
);
|
|
});
|
|
|
|
test('팬덤을 모르면 두 개로 줄어든다 — 고정 3종이 아니다', () {
|
|
expect(shareHashtags(topic: '캠페인'), ['#FANUZU', '#캠페인']);
|
|
expect(shareHashtags(fandomName: '', topic: '캠페인').length, 2);
|
|
});
|
|
|
|
test('주제가 바뀌면 구성이 따라 바뀐다', () {
|
|
expect(
|
|
shareHashtags(fandomName: 'NewJeans', topic: '퀘스트').last,
|
|
'#퀘스트',
|
|
);
|
|
});
|
|
|
|
test('셋을 넘겨도 세 개를 넘지 않는다', () {
|
|
expect(
|
|
shareHashtags(fandomName: 'BTS', topic: '캠페인', maxHashtags: 3).length,
|
|
lessThanOrEqualTo(3),
|
|
);
|
|
});
|
|
|
|
test('공백과 해시는 태그를 끊으므로 지운다', () {
|
|
expect(shareHashtags(fandomName: 'New Jeans')[1], '#NewJeans');
|
|
expect(shareHashtags(fandomName: '#BTS')[1], '#BTS');
|
|
});
|
|
});
|
|
|
|
group('캠페인 공유 문구', () {
|
|
test('웹 브릿지 주소가 없으면 링크를 넣지 않는다', () {
|
|
final text = campaignShareText(
|
|
title: '강남역 초대형 LED 광고',
|
|
summary: '도심 한가운데에서 함께 축하해요.',
|
|
fandomName: 'BTS',
|
|
);
|
|
expect(text, contains('강남역 초대형 LED 광고'));
|
|
expect(text, contains('도심 한가운데에서'));
|
|
expect(text, contains('BTS 행성'));
|
|
expect(text, contains('#FANUZU #BTS #캠페인'));
|
|
// 주소 설정(FANUZU_SHARE_BASE_URL)이 없으면 지어낸 URL 이 새지 않는지 본다.
|
|
expect(text, isNot(contains('http')));
|
|
expect(text, isNot(contains('fanuzu.co.kr')));
|
|
});
|
|
|
|
test('행성을 모르면 행성 줄과 팬덤 해시태그가 함께 빠진다', () {
|
|
final text = campaignShareText(title: '커피차 보내기', summary: '한 잔.');
|
|
expect(text, isNot(contains('행성')));
|
|
expect(text, contains('#FANUZU #캠페인'));
|
|
});
|
|
|
|
test('소개가 비면 그 줄을 빼고 붙인다', () {
|
|
final text = campaignShareText(title: '제목만', fandomName: 'IVE');
|
|
expect(text.split('\n').first, '제목만');
|
|
expect(text, contains('IVE 행성'));
|
|
});
|
|
});
|
|
|
|
group('공유 링크', () {
|
|
test('주소가 있으면 /c/<캠페인> 이 문구에 들어가고, 없으면 null', () {
|
|
expect(campaignShareLink('cmp1', base: ''), isNull);
|
|
final link = campaignShareLink('cmp 1', base: 'https://link.example/');
|
|
expect(link, 'https://link.example/c/cmp%201');
|
|
final text = campaignShareText(title: 't', fandomName: 'BTS', link: link);
|
|
expect(text, contains('https://link.example/c/cmp%201'));
|
|
expect(shareLink(['b', 'bts', '2026-09-28'], base: 'https://link.example'),
|
|
'https://link.example/b/bts/2026-09-28');
|
|
expect(shareLink(['c', ''], base: 'https://link.example'), isNull);
|
|
});
|
|
|
|
test('내 초대 코드가 있으면 ?ref= 를 붙이고, 없으면 붙이지 않는다', () {
|
|
addTearDown(InviteCode.reset);
|
|
InviteCode.reset();
|
|
expect(campaignShareLink('c1', base: 'https://l.example'), 'https://l.example/c/c1');
|
|
InviteCode.current = 'ABCDEFGH23';
|
|
expect(campaignShareLink('c1', base: 'https://l.example'),
|
|
'https://l.example/c/c1?ref=ABCDEFGH23');
|
|
expect(shareLink(['b', 'bts', '2026-09-28'], base: 'https://l.example'),
|
|
'https://l.example/b/bts/2026-09-28?ref=ABCDEFGH23');
|
|
// 주소 설정이 없으면 코드가 있어도 링크가 없다.
|
|
expect(campaignShareLink('c1', base: ''), isNull);
|
|
});
|
|
});
|
|
}
|