|
| 1 | +import { handler } from '../src/handler' |
| 2 | + |
| 3 | +vi.mock('../vender/index_bg.wasm', async () => { |
| 4 | + const fs = await import('node:fs/promises') |
| 5 | + const wasm = await fs.readFile(require.resolve('@resvg/resvg-wasm/index_bg.wasm')) |
| 6 | + return { |
| 7 | + default: wasm, |
| 8 | + } |
| 9 | +}) |
| 10 | + |
| 11 | +describe('handler()', () => { |
| 12 | + it('no title', async () => { |
| 13 | + const response = await handler({ |
| 14 | + url: 'http://localhost:3000', |
| 15 | + } as Request) |
| 16 | + const result = Buffer.from(await response.arrayBuffer()) |
| 17 | + expect(result).toMatchImageSnapshot() |
| 18 | + }) |
| 19 | + it('should align title and have container padding', async () => { |
| 20 | + const response = await handler({ |
| 21 | + url: 'http://localhost:3000?title=Hello this is a test of really really really really really really long title', |
| 22 | + } as Request) |
| 23 | + const result = Buffer.from(await response.arrayBuffer()) |
| 24 | + expect(result).toMatchImageSnapshot() |
| 25 | + }) |
| 26 | + it('should align title without whitespaces', async () => { |
| 27 | + const response = await handler({ |
| 28 | + url: 'http://localhost:3000?title=Home', |
| 29 | + } as Request) |
| 30 | + const result = Buffer.from(await response.arrayBuffer()) |
| 31 | + expect(result).toMatchImageSnapshot() |
| 32 | + }) |
| 33 | + |
| 34 | + describe('show individual languages', () => { |
| 35 | + for (const [lang, title] of Object.entries({ |
| 36 | + ar: 'الأسئلة الشائعة حول الفرعيةرسم بياني استوديو', |
| 37 | + hi: 'फोर्क्स का उपयोग करके त्वरित और आसान सबग्राफ डिबगिंग', |
| 38 | + ja: 'フォークを用いた迅速かつ容易なサブグラフのデバッグ', |
| 39 | + ko: '다중서명 지갑 사용하기', |
| 40 | + ru: 'Замените контракт и сохраните его историю с помощью Grafting', |
| 41 | + ua: 'Мережа The Graph в порівнянні з Самостійним хостингом', |
| 42 | + ur: 'ایک معاہدے کو تبدیل کریں اور اس کی تاریخ کو گرافٹنگ کے ساتھ رکھیں', |
| 43 | + zh: '使用分叉快速轻松地调试子图', |
| 44 | + })) { |
| 45 | + it(lang, async () => { |
| 46 | + const response = await handler({ |
| 47 | + url: `http://localhost:3000?title=${title}`, |
| 48 | + } as Request) |
| 49 | + const result = Buffer.from(await response.arrayBuffer()) |
| 50 | + expect(result).toMatchImageSnapshot() |
| 51 | + }) |
| 52 | + } |
| 53 | + }) |
| 54 | +}) |
0 commit comments