import { describe, expect, test } from 'vitest'; import shareGridBridge from './index.shared.js'; const { buildShareGridTileFileName, buildShareGridTilePlan, normalizeShareGridQuery, } = shareGridBridge; describe('share-grid mini program bridge', () => { test('normalizes query values and keeps a fallback title', () => { expect( normalizeShareGridQuery({ imageUrl: ' https://web.test/cover.png ', publicWorkCode: ' PZ-0001 ', }), ).toEqual({ imageUrl: 'https://web.test/cover.png', title: '我的作品', publicWorkCode: 'PZ-0001', }); }); test('names tiles by title, public code and left-to-right order', () => { const params = { title: '星港:拼图', publicWorkCode: 'PZ-0001', }; expect(buildShareGridTileFileName(params, 0)).toBe( '星港拼图-PZ-0001-01.png', ); expect(buildShareGridTileFileName(params, 8)).toBe( '星港拼图-PZ-0001-09.png', ); }); test('builds a 3x3 crop plan in reading order', () => { const plan = buildShareGridTilePlan(900, 600); expect(plan).toHaveLength(9); expect(plan[0]).toMatchObject({ index: 0, row: 0, col: 0, sourceX: 0, sourceY: 0, sourceWidth: 300, sourceHeight: 200, }); expect(plan[4]).toMatchObject({ index: 4, row: 1, col: 1, sourceX: 300, sourceY: 200, }); expect(plan[8]).toMatchObject({ index: 8, row: 2, col: 2, sourceX: 600, sourceY: 400, }); }); });