64 lines
1.9 KiB
JavaScript
64 lines
1.9 KiB
JavaScript
// @vitest-environment jsdom
|
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
import {
|
|
getSiteTitle,
|
|
getSiteIcp,
|
|
getPageTitle,
|
|
getGaMeasurementId,
|
|
getJinrishiciSdkUrl,
|
|
} from '../../src/config/site.js'
|
|
import { initAnalytics } from '../../src/utils/analytics.js'
|
|
|
|
describe('site config', () => {
|
|
beforeEach(() => {
|
|
delete window.__SITE_CONFIG__
|
|
})
|
|
|
|
afterEach(() => {
|
|
delete window.__SITE_CONFIG__
|
|
})
|
|
|
|
it('uses default title and icp', () => {
|
|
expect(getSiteTitle()).toBe('ToolBox')
|
|
expect(getSiteIcp()).toBe('')
|
|
})
|
|
|
|
it('builds page title with suffix', () => {
|
|
expect(getPageTitle('JSON')).toBe('ToolBox-JSON')
|
|
expect(getPageTitle(null)).toBe('ToolBox')
|
|
})
|
|
|
|
it('prefers runtime config over defaults', () => {
|
|
window.__SITE_CONFIG__ = { title: '自定义工具箱', icp: '京ICP备12345678号' }
|
|
expect(getSiteTitle()).toBe('自定义工具箱')
|
|
expect(getSiteIcp()).toBe('京ICP备12345678号')
|
|
expect(getPageTitle('对比')).toBe('自定义工具箱-对比')
|
|
})
|
|
|
|
it('allows empty icp to hide footer', () => {
|
|
window.__SITE_CONFIG__ = { title: 'ToolBox', icp: '' }
|
|
expect(getSiteIcp()).toBe('')
|
|
})
|
|
|
|
it('disables third-party integrations by default', () => {
|
|
expect(getGaMeasurementId()).toBe('')
|
|
expect(getJinrishiciSdkUrl()).toBe('')
|
|
})
|
|
|
|
it('loads analytics only when configured', () => {
|
|
window.__SITE_CONFIG__ = { gaId: 'G-TEST123' }
|
|
initAnalytics()
|
|
expect(document.querySelector('script[src*="googletagmanager.com"]')).not.toBeNull()
|
|
expect(typeof window.gtag).toBe('function')
|
|
})
|
|
|
|
it('respects runtime privacy overrides', () => {
|
|
window.__SITE_CONFIG__ = {
|
|
gaId: 'G-RUNTIME',
|
|
jinrishiciSdkUrl: 'https://example.com/sdk.js',
|
|
}
|
|
expect(getGaMeasurementId()).toBe('G-RUNTIME')
|
|
expect(getJinrishiciSdkUrl()).toBe('https://example.com/sdk.js')
|
|
})
|
|
})
|