import { describe, it, expect, beforeEach } from 'vitest'; import { getStateInfoClient } from '@/lib/getStateInfoClient'; import { getCanonicalUrlClient } from '@/lib/getCanonicalUrl'; function setLocation(loc) { Object.defineProperty(window, 'location', { value: loc, writable: true, configurable: true }); } describe('getStateInfoClient (window)', () => { it('subdomain شناخته‌شده → شهر و استان', () => { setLocation({ host: 'arak-nobat.ir', href: 'https://arak-nobat.ir/' }); const { matchedCity, matchedState, host } = getStateInfoClient(); expect(matchedCity?.name).toBe('اراک'); expect(matchedState?.name).toBe('مرکزی'); expect(host).toBe('arak-nobat.ir'); }); it('host ناشناخته → بدون تطبیق', () => { setLocation({ host: 'zzz.ir', href: 'https://zzz.ir/' }); expect(getStateInfoClient().matchedCity).toBeUndefined(); }); }); describe('getCanonicalUrlClient (window)', () => { beforeEach(() => { setLocation({ host: 'arak-nobat.ir', pathname: '/doctors' }); }); it('subdomain → canonical به دامنه‌ی اصلی', () => { expect(getCanonicalUrlClient()).toBe('https://nobat724.com/doctors'); }); it('دامنه‌ی اصلی → null', () => { setLocation({ host: 'nobat724.com', pathname: '/doctors' }); expect(getCanonicalUrlClient()).toBeNull(); }); it('www و حروف بزرگ نرمال می‌شوند (دامنه‌ی اصلی) → null', () => { setLocation({ host: 'WWW.Nobat724.com', pathname: '/x' }); expect(getCanonicalUrlClient()).toBeNull(); }); });