|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { readFileSync } from "node:fs"; |
| 3 | +import { |
| 4 | + SHARED_ACTION_LABELS, |
| 5 | + getSharedShellActions |
| 6 | +} from "../../tools/shared/assetUsageIntegration.js"; |
| 7 | + |
| 8 | +const FIRST_CLASS_TOOL_INDEXES = Object.freeze([ |
| 9 | + { toolId: "asset-browser", indexPath: "../../tools/Asset Browser/index.html" }, |
| 10 | + { toolId: "sprite-editor", indexPath: "../../tools/Sprite Editor/index.html" }, |
| 11 | + { toolId: "vector-map-editor", indexPath: "../../tools/Vector Map Editor/index.html" }, |
| 12 | + { toolId: "vector-asset-studio", indexPath: "../../tools/Vector Asset Studio/index.html" }, |
| 13 | + { toolId: "tile-map-editor", indexPath: "../../tools/Tilemap Studio/index.html" }, |
| 14 | + { toolId: "parallax-editor", indexPath: "../../tools/Parallax Scene Studio/index.html" }, |
| 15 | + { toolId: "palette-browser", indexPath: "../../tools/Palette Browser/index.html" } |
| 16 | +]); |
| 17 | + |
| 18 | +export async function run() { |
| 19 | + const previousWindow = globalThis.window; |
| 20 | + globalThis.window = { |
| 21 | + location: { |
| 22 | + search: "" |
| 23 | + } |
| 24 | + }; |
| 25 | + |
| 26 | + try { |
| 27 | + FIRST_CLASS_TOOL_INDEXES.forEach(({ toolId }) => { |
| 28 | + const actions = getSharedShellActions(toolId, "tool"); |
| 29 | + assert.equal(actions.length, 4); |
| 30 | + assert.deepEqual( |
| 31 | + actions.map((action) => action.label), |
| 32 | + [ |
| 33 | + SHARED_ACTION_LABELS.browseAssets, |
| 34 | + SHARED_ACTION_LABELS.importAssets, |
| 35 | + SHARED_ACTION_LABELS.browsePalettes, |
| 36 | + SHARED_ACTION_LABELS.managePalettes |
| 37 | + ] |
| 38 | + ); |
| 39 | + assert.equal( |
| 40 | + actions[0].href, |
| 41 | + `../Asset Browser/index.html?view=browse&sourceToolId=${toolId}` |
| 42 | + ); |
| 43 | + assert.equal( |
| 44 | + actions[1].href, |
| 45 | + `../Asset Browser/index.html?view=import&sourceToolId=${toolId}` |
| 46 | + ); |
| 47 | + assert.equal( |
| 48 | + actions[2].href, |
| 49 | + `../Palette Browser/index.html?view=browse&sourceToolId=${toolId}` |
| 50 | + ); |
| 51 | + assert.equal( |
| 52 | + actions[3].href, |
| 53 | + `../Palette Browser/index.html?view=manage&sourceToolId=${toolId}` |
| 54 | + ); |
| 55 | + }); |
| 56 | + } finally { |
| 57 | + globalThis.window = previousWindow; |
| 58 | + } |
| 59 | + |
| 60 | + FIRST_CLASS_TOOL_INDEXES.forEach(({ toolId, indexPath }) => { |
| 61 | + const fileUrl = new URL(indexPath, import.meta.url); |
| 62 | + const html = readFileSync(fileUrl, "utf8"); |
| 63 | + assert.match(html, new RegExp(`data-tool-id="${toolId}"`)); |
| 64 | + assert.match(html, /<script type="module" src="\.\.\/shared\/platformShell\.js"><\/script>/); |
| 65 | + }); |
| 66 | +} |
0 commit comments