From 1425b33e97ca2f9060195f61af385ef17f90362c Mon Sep 17 00:00:00 2001 From: xenticore Date: Mon, 24 Mar 2025 16:13:38 -0400 Subject: [PATCH] test: add localization tests --- __tests__/localization.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 __tests__/localization.test.ts diff --git a/__tests__/localization.test.ts b/__tests__/localization.test.ts new file mode 100644 index 0000000..e6699cf --- /dev/null +++ b/__tests__/localization.test.ts @@ -0,0 +1,23 @@ +import { describe, it, expect, jest, beforeEach } from "bun:test"; +import { extractLocaleFromURL } from '../src/content/utils/localization' + +beforeEach(() => { + jest.clearAllMocks() +}) + +describe('localization', () => { + it('should assume `en` if no locale is specified', async () => { + // extractLocaleFromURL('https://wiki.teamfortress.com/wiki/Team_Fortress_2') should return 'en' + expect(extractLocaleFromURL('https://wiki.teamfortress.com/wiki/Team_Fortress_2')).toBe('en') + }) + + it('should extract locale shortcode from URL correctly', async () => { + // extractLocaleFromURL('https://wiki.teamfortress.com/wiki/Phlogistinator/de') should return 'de' + expect(extractLocaleFromURL('https://wiki.teamfortress.com/wiki/Phlogistinator/de')).toBe('de') + }) + + it('should extract locale shortcode with special characters from URL correctly', async () => { + // extractLocaleFromURL('https://wiki.teamfortress.com/wiki/%C3%9CberCharge/zh-hans') should return 'zh-hans' + expect(extractLocaleFromURL('https://wiki.teamfortress.com/wiki/%C3%9CberCharge/zh-hans')).toBe('zh-hans') + }) +}) \ No newline at end of file