42 行
1.6 KiB
TypeScript
42 行
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { columnsForCounts, countColumns, countsCSV, normaliseCountsParams } from '@/lib/counts'
|
|
import { createUII18n, translateUIMessage } from '@/lib/i18n'
|
|
|
|
|
|
describe ('counts exports', () => {
|
|
it ('resolves every output and CSV header key in both locales', () => {
|
|
for (const locale of ['ja', 'ain-Kana'])
|
|
{
|
|
const instance = createUII18n (locale)
|
|
for (const key of Object.values (countColumns))
|
|
{
|
|
const translated = translateUIMessage (key, 'counts', locale, { }, instance)
|
|
expect (translated.text).not.toBe (key)
|
|
expect (translated.text).not.toContain ('counts:')
|
|
}
|
|
const fallback = translateUIMessage ('run', 'counts', locale, { }, instance)
|
|
expect (fallback).toEqual ({ text: '集計実行', language: 'ja' })
|
|
}
|
|
})
|
|
|
|
it ('makes the monthly default explicit for the existing API', () => {
|
|
expect (normaliseCountsParams ('posts', new URLSearchParams ()).get ('axis'))
|
|
.toBe ('month')
|
|
})
|
|
|
|
it ('escapes quotes, newlines and spreadsheet formulas in UTF-8 CSV', () => {
|
|
expect (countsCSV ([['日本語', 'a"b', 'a\nb', '=1+1']]))
|
|
.toBe ('\uFEFF"日本語","a""b","a\nb","\'=1+1"')
|
|
})
|
|
|
|
it ('keeps resource-specific columns out of the other resource', () => {
|
|
expect (columnsForCounts ('posts')).toContain ('added_tags')
|
|
expect (columnsForCounts ('posts')).not.toContain ('aliases')
|
|
expect (columnsForCounts ('tags')).toContain ('aliases')
|
|
expect (columnsForCounts ('tags')).not.toContain ('url')
|
|
expect (columnsForCounts ('posts')).not.toContain ('event_type')
|
|
expect (columnsForCounts ('tags')).not.toContain ('event_type')
|
|
})
|
|
})
|