import { Buffer } from 'node:buffer'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { describe, expect, it } from 'vitest'
const root = resolve(import.meta.dirname, '..')
function readPngMetadata(path: string) {
const data = readFileSync(resolve(root, path))
expect(data.subarray(0, 8)).toEqual(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))
return {
colorType: data[25],
height: data.readUInt32BE(20),
width: data.readUInt32BE(16),
}
}
describe('web app metadata', () => {
it('uses 食用手册 as the app name', () => {
const constants = readFileSync(resolve(root, 'apps/web/app/constants/index.ts'), 'utf8')
expect(constants).toContain('export const appName = \'食用手册\'')
})
it('ships the selected Cook icon across web surfaces', () => {
const appIcon = readFileSync(resolve(root, 'apps/web/public/brand/cook-app-icon.svg'), 'utf8')
const mark = readFileSync(resolve(root, 'apps/web/public/brand/cook-mark.svg'), 'utf8')
expect(appIcon).toContain('viewBox="0 0 1254 1254"')
expect(appIcon).toContain('')
expect(appIcon).toContain('')
expect(mark).not.toContain('M0 0h1254v1254H0z')
expect(mark).toContain('')
expect(readPngMetadata('apps/web/public/pwa-192x192.png')).toMatchObject({ width: 192, height: 192, colorType: 2 })
expect(readPngMetadata('apps/web/public/pwa-512x512.png')).toMatchObject({ width: 512, height: 512, colorType: 2 })
expect(readPngMetadata('apps/web/public/apple-touch-icon.png')).toMatchObject({ width: 180, height: 180, colorType: 2 })
})
})