bc3b464349
微信小程序 host-bridge 与 shell 文件改为职责命名 移动壳 host-bridge 与 shell 文件改为职责命名 更新原生壳结构门禁、微信 smoke 和宿主壳文档
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
import { describe, expect, test } from 'vitest';
|
|
|
|
import shareGridBridge from './shareGrid.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,
|
|
});
|
|
});
|
|
});
|