1
0
forked from baron/baron-sso

feat: i18n 개선 및 userfront 로그인/로케일 보완

This commit is contained in:
Lectom C Han
2026-02-12 21:25:26 +09:00
parent b6d3b69cda
commit dfa2fc2406
60 changed files with 5724 additions and 1734 deletions

View File

@@ -0,0 +1,66 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:userfront/core/i18n/locale_utils.dart';
void main() {
group('locale_utils', () {
test('normalizeLocaleCode handles supported locales', () {
expect(normalizeLocaleCode('ko'), 'ko');
expect(normalizeLocaleCode('ko-KR'), 'ko');
expect(normalizeLocaleCode('en'), 'en');
expect(normalizeLocaleCode('en-US'), 'en');
});
test('normalizeLocaleCode falls back to default', () {
expect(normalizeLocaleCode('ja'), defaultLocaleCode);
expect(normalizeLocaleCode(null), defaultLocaleCode);
expect(normalizeLocaleCode(''), defaultLocaleCode);
});
test('extractLocaleFromPath picks locale when present', () {
expect(extractLocaleFromPath(Uri.parse('/ko/signin')), 'ko');
expect(extractLocaleFromPath(Uri.parse('/en/profile')), 'en');
expect(extractLocaleFromPath(Uri.parse('/ko')), 'ko');
});
test('extractLocaleFromPath returns null when missing', () {
expect(extractLocaleFromPath(Uri.parse('/signin')), isNull);
expect(extractLocaleFromPath(Uri.parse('/zz/signin')), isNull);
});
test('stripLocalePath removes locale segment', () {
expect(stripLocalePath(Uri.parse('/ko/signin')), '/signin');
expect(stripLocalePath(Uri.parse('/en/profile')), '/profile');
expect(stripLocalePath(Uri.parse('/ko')), '/');
expect(stripLocalePath(Uri.parse('/en/')), '/');
});
test('stripLocalePath keeps path without locale', () {
expect(stripLocalePath(Uri.parse('/signin')), '/signin');
expect(stripLocalePath(Uri.parse('/auth/callback')), '/auth/callback');
});
test('buildLocalizedPath applies locale', () {
expect(buildLocalizedPath('ko', Uri.parse('/signin')), '/ko/signin');
expect(buildLocalizedPath('en', Uri.parse('/signin')), '/en/signin');
expect(buildLocalizedPath('ko', Uri.parse('/')), '/ko');
expect(buildLocalizedPath('en', Uri.parse('/')), '/en');
});
test('buildLocalizedPath preserves query parameters', () {
final uri = Uri.parse('/signin?redirect_uri=https://example.com');
expect(
buildLocalizedPath('ko', uri),
'/ko/signin?redirect_uri=https%3A%2F%2Fexample.com',
);
});
test('buildLocalizedPath replaces existing locale', () {
expect(buildLocalizedPath('en', Uri.parse('/ko/signin')), '/en/signin');
expect(buildLocalizedPath('ko', Uri.parse('/en/profile')), '/ko/profile');
});
test('buildLocalizedPath drops unknown 2-letter prefix', () {
expect(buildLocalizedPath('ko', Uri.parse('/zz/signin')), '/ko/signin');
});
});
}