gentle-pi 4.7.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -44
- package/assets/agents/gentle-ai-explore.md +3 -3
- package/assets/agents/gentle-ai-verify.md +20 -6
- package/assets/agents/gentle-ai-worker.md +6 -6
- package/assets/agents/jd-judge-a.md +1 -3
- package/assets/agents/jd-judge-b.md +1 -3
- package/assets/agents/review-readability.md +1 -5
- package/assets/agents/review-reliability.md +1 -5
- package/assets/agents/review-resilience.md +1 -5
- package/assets/agents/review-risk.md +1 -5
- package/assets/design-canvas/canvas-api.js +45 -0
- package/assets/design-canvas/canvas-boards.js +456 -0
- package/assets/design-canvas/canvas-boot.js +217 -0
- package/assets/design-canvas/canvas-checks.js +491 -0
- package/assets/design-canvas/canvas-comments.js +315 -0
- package/assets/design-canvas/canvas-compare.js +159 -0
- package/assets/design-canvas/canvas-events.js +75 -0
- package/assets/design-canvas/canvas-export.js +393 -0
- package/assets/design-canvas/canvas-focus.js +203 -0
- package/assets/design-canvas/canvas-handoffs.js +150 -0
- package/assets/design-canvas/canvas-i18n-es.js +392 -0
- package/assets/design-canvas/canvas-i18n.js +108 -0
- package/assets/design-canvas/canvas-layout.js +526 -0
- package/assets/design-canvas/canvas-menu.js +213 -0
- package/assets/design-canvas/canvas-messages.js +86 -0
- package/assets/design-canvas/canvas-minimap.js +163 -0
- package/assets/design-canvas/canvas-parts.js +401 -0
- package/assets/design-canvas/canvas-popover.js +234 -0
- package/assets/design-canvas/canvas-rail.js +348 -0
- package/assets/design-canvas/canvas-sizes.js +524 -0
- package/assets/design-canvas/canvas-store.js +164 -0
- package/assets/design-canvas/canvas-tokens.js +674 -0
- package/assets/design-canvas/canvas-ui.js +24 -0
- package/assets/design-canvas/canvas-view.js +184 -0
- package/assets/design-canvas/canvas.css +746 -15
- package/assets/design-canvas/canvas.js +2 -1506
- package/assets/design-canvas/index.html +117 -36
- package/assets/design-canvas/inspector.js +546 -16
- package/assets/install-wizard/wizard.js +5 -1
- package/assets/migrations/agent-body-history.json +24 -0
- package/assets/orchestrator-delegation-reference.md +8 -14
- package/assets/orchestrator-delegation.md +4 -4
- package/assets/orchestrator-full-delegation-card.md +4 -5
- package/assets/orchestrator-full-delegation.md +8 -8
- package/assets/orchestrator-memory.md +2 -2
- package/assets/orchestrator-prompts.md +1 -1
- package/assets/orchestrator-quota-recovery.md +5 -0
- package/assets/orchestrator-skills.md +13 -12
- package/assets/orchestrator-tracking.md +10 -14
- package/assets/orchestrator-verification.md +10 -8
- package/assets/orchestrator-writer.md +4 -4
- package/assets/orchestrator.md +18 -22
- package/bin/gentle-shell.mjs +128 -9
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/manifest.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/orchestration/pi.md +1 -0
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/routing/pi.md +6 -6
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-roles.baseline.json +1 -1
- package/docs/assets/brand/sponsor-banner.svg +60 -0
- package/docs/bundled-install.md +14 -6
- package/docs/delegated-verification.md +18 -2
- package/docs/desktop-rpc.md +1253 -0
- package/docs/gentle-agents-activity.md +26 -0
- package/docs/gentle-shell.md +39 -16
- package/docs/install-wizard.md +30 -21
- package/docs/odd-preparation-continuity.md +24 -0
- package/docs/permission-modes.md +9 -1
- package/docs/prompt-budget.md +12 -0
- package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
- package/docs/readme-reference.md +76 -24
- package/docs/review-coordinator.md +29 -9
- package/docs/review-delivery-preflight.md +22 -0
- package/docs/work-continuity.md +11 -1
- package/extensions/ask-user-question.ts +2 -2
- package/extensions/child-context.ts +21 -7
- package/extensions/gentle-agents.ts +234 -33
- package/extensions/gentle-ai.ts +576 -135
- package/extensions/gentle-design.ts +69 -3
- package/extensions/gentle-desktop-rpc.ts +143 -0
- package/extensions/gentle-guide.ts +3 -0
- package/extensions/gentle-shell.ts +105 -52
- package/extensions/gentle-todo.ts +48 -25
- package/extensions/skill-registry.ts +248 -223
- package/lib/agent-assets.ts +30 -6
- package/lib/agent-tool-overlay.ts +117 -0
- package/lib/agents-config.ts +47 -6
- package/lib/agents-message-delivery.ts +17 -0
- package/lib/agents-messaging.ts +8 -2
- package/lib/agents-protocol.ts +15 -0
- package/lib/agents-report-cap.ts +115 -0
- package/lib/agents-runner.ts +91 -6
- package/lib/agents-session-transport.ts +17 -1
- package/lib/background-jobs-tools.ts +9 -4
- package/lib/bounded-writer-admission.ts +184 -31
- package/lib/child-context-files.ts +21 -6
- package/lib/codemode-renderer.ts +1 -0
- package/lib/delivery-conflict-markers.ts +349 -0
- package/lib/design-canvas-assets.ts +36 -0
- package/lib/design-canvas-server.ts +241 -23
- package/lib/design-comments.ts +94 -4
- package/lib/design-handoffs.ts +2 -1
- package/lib/design-layout.ts +125 -0
- package/lib/design-parts.ts +281 -0
- package/lib/design-system-tokens.ts +111 -0
- package/lib/desktop-agents-service.ts +294 -0
- package/lib/desktop-design-service.ts +233 -0
- package/lib/desktop-jobs-service.ts +263 -0
- package/lib/desktop-rpc-agents.ts +294 -0
- package/lib/desktop-rpc-config.ts +731 -0
- package/lib/desktop-rpc-design.ts +138 -0
- package/lib/desktop-rpc-jobs.ts +181 -0
- package/lib/desktop-rpc-permissions.ts +177 -0
- package/lib/desktop-rpc-profiles.ts +196 -0
- package/lib/desktop-rpc-usage.ts +229 -0
- package/lib/desktop-rpc.ts +225 -0
- package/lib/desktop-usage-service.ts +310 -0
- package/lib/destructive-command-guard.ts +188 -13
- package/lib/gentle-ai-renderer.ts +13 -1
- package/lib/gentle-design.ts +201 -14
- package/lib/gentle-shell-bundled.ts +100 -9
- package/lib/hidden-tools.ts +35 -0
- package/lib/inprocess-reviewer.ts +96 -12
- package/lib/model-fallback-policy.ts +9 -0
- package/lib/model-routing-authority.ts +9 -0
- package/lib/nan-provider.ts +42 -28
- package/lib/native-review-cli.ts +79 -4
- package/lib/orchestrator-discovery.ts +39 -2
- package/lib/reply-language-anchor.ts +27 -2
- package/lib/request-context-placement.ts +53 -0
- package/lib/review-candidate-view.ts +11 -1
- package/lib/review-continuation-registry.ts +17 -0
- package/lib/review-coordinator.ts +252 -8
- package/lib/review-delivery-preflight.ts +85 -0
- package/lib/review-host-relay.ts +5 -1
- package/lib/review-integration-v2.ts +56 -3
- package/lib/reviewer-stream.ts +87 -0
- package/lib/shell-prompt.ts +16 -3
- package/lib/shell-usage.ts +10 -0
- package/lib/vim-editor-adapter.ts +9 -2
- package/lib/writer-batch-admission.ts +55 -0
- package/lib/yolo-session-policy.ts +6 -1
- package/package.json +2 -2
- package/prompts/skill-creation.md +1 -10
- package/runtime/design-canvas-assets.mjs +37 -0
- package/runtime/gentle-shell-bundled.mjs +100 -9
- package/runtime/native-review-cli.mjs +79 -4
- package/runtime/review-integration-v2.mjs +56 -3
- package/scripts/bootstrap.cmd +2 -2
- package/scripts/bootstrap.sh +41 -4
- package/scripts/build-full-delegation-card.mjs +4 -0
- package/scripts/build-runtime-modules.mjs +1 -0
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/gentle-ai-proxy.mjs +1 -1
- package/scripts/installer-downloads.mjs +34 -8
- package/scripts/installer-preflight.mjs +28 -17
- package/scripts/installer-probes.mjs +25 -5
- package/scripts/installer-server.mjs +38 -9
- package/scripts/installer-windows.mjs +2 -2
- package/scripts/pi-update.mjs +166 -27
- package/scripts/prepare-verifier.mjs +107 -0
- package/scripts/update-agent-body-history.mjs +55 -8
- package/scripts/verify-package-files.mjs +40 -19
- package/skills/branch-pr/SKILL.md +16 -16
- package/skills/comment-writer/SKILL.md +1 -1
- package/skills/design/SKILL.md +6 -6
- package/skills/gentle-ai/SKILL.md +5 -5
- package/skills/judgment-day/SKILL.md +2 -2
- package/skills/judgment-day/references/prompts-and-formats.md +1 -1
- package/skills/rdd-defect-workflow/SKILL.md +6 -6
- package/skills/skill-improver/SKILL.md +2 -2
- package/skills/skill-registry/SKILL.md +11 -13
- package/skills/tui-design/SKILL.md +1 -1
- package/skills/work-unit-commits/SKILL.md +5 -5
- package/tests/agent-prompt-diet-contract.test.ts +101 -0
- package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
- package/tests/agent-tool-overlay.test.ts +89 -0
- package/tests/agents-config.test.ts +10 -1
- package/tests/agents-message-delivery.test.ts +36 -0
- package/tests/agents-queries.test.ts +144 -4
- package/tests/agents-report-cap.test.ts +126 -0
- package/tests/agents-runner.test.ts +37 -1
- package/tests/agents-session-transport.test.ts +34 -0
- package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
- package/tests/append-system-prompt-route.test.ts +10 -2
- package/tests/approved-text-leftovers-contract.test.ts +136 -0
- package/tests/artifact-language.test.ts +1 -1
- package/tests/ask-user-question.test.ts +2 -1
- package/tests/audit-leftovers-contract.test.ts +51 -0
- package/tests/bounded-stop-contract.test.ts +9 -1
- package/tests/branch-pr-skill.test.ts +10 -1
- package/tests/bundled-install.test.ts +1 -1
- package/tests/child-context-files.test.ts +64 -8
- package/tests/child-skills-catalog.test.ts +56 -0
- package/tests/codemode-rendering.test.ts +4 -1
- package/tests/delegate-for-reason-contract.test.ts +30 -8
- package/tests/delivery-conflict-markers.test.ts +348 -0
- package/tests/design-canvas-all-sizes.test.ts +631 -0
- package/tests/design-canvas-allowlist.test.ts +32 -0
- package/tests/design-canvas-assets.test.ts +11 -878
- package/tests/design-canvas-boards.test.ts +77 -0
- package/tests/design-canvas-checks.test.ts +655 -0
- package/tests/design-canvas-compare.test.ts +79 -0
- package/tests/design-canvas-events.test.ts +59 -0
- package/tests/design-canvas-export.test.ts +1168 -0
- package/tests/design-canvas-focus.test.ts +113 -0
- package/tests/design-canvas-handoffs.test.ts +59 -0
- package/tests/design-canvas-i18n-review.test.ts +513 -0
- package/tests/design-canvas-i18n-views.test.ts +259 -0
- package/tests/design-canvas-i18n.test.ts +526 -0
- package/tests/design-canvas-inspector.test.ts +937 -0
- package/tests/design-canvas-layout.test.ts +1222 -0
- package/tests/design-canvas-minimap.test.ts +413 -0
- package/tests/design-canvas-modules.test.ts +90 -0
- package/tests/design-canvas-parts.test.ts +721 -0
- package/tests/design-canvas-rail.test.ts +799 -0
- package/tests/design-canvas-server.test.ts +855 -17
- package/tests/design-canvas-sizes.test.ts +548 -0
- package/tests/design-canvas-store.test.ts +180 -0
- package/tests/design-canvas-tokens.test.ts +965 -0
- package/tests/design-canvas-view.test.ts +299 -0
- package/tests/design-comments.test.ts +201 -1
- package/tests/design-handoffs.test.ts +20 -0
- package/tests/design-layout.test.ts +100 -0
- package/tests/design-parts.test.ts +260 -0
- package/tests/design-system-tokens.test.ts +215 -0
- package/tests/desktop-rpc-agents.test.ts +893 -0
- package/tests/desktop-rpc-config.test.ts +1452 -0
- package/tests/desktop-rpc-design.test.ts +662 -0
- package/tests/desktop-rpc-jobs.test.ts +796 -0
- package/tests/desktop-rpc-permissions.test.ts +311 -0
- package/tests/desktop-rpc-profiles.test.ts +140 -0
- package/tests/desktop-rpc-safety.test.ts +119 -0
- package/tests/desktop-rpc-usage.test.ts +697 -0
- package/tests/desktop-rpc.test.ts +252 -0
- package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
- package/tests/devbinary/review-session-consent.devtest.ts +84 -0
- package/tests/engram-safety.test.ts +111 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +20 -29
- package/tests/fixtures/refusal-identity.probe.mjs +139 -0
- package/tests/full-delegation-closure.test.ts +29 -0
- package/tests/gentle-agents.test.ts +329 -4
- package/tests/gentle-ai-binary.test.ts +1 -1
- package/tests/gentle-ai-child-guards.test.ts +1 -0
- package/tests/gentle-ai-installer.test.ts +52 -51
- package/tests/gentle-ai-renderer.test.ts +36 -2
- package/tests/gentle-ai.test.ts +121 -6
- package/tests/gentle-design.test.ts +365 -1
- package/tests/gentle-shell-bundled.test.ts +91 -5
- package/tests/gentle-shell-launcher.test.ts +1 -1
- package/tests/gentle-shell.test.ts +118 -87
- package/tests/gentle-todo.test.ts +32 -9
- package/tests/hidden-tools.test.ts +188 -0
- package/tests/independent-recovery-delivery.test.ts +19 -5
- package/tests/inprocess-reviewer.test.ts +73 -0
- package/tests/install-wizard.test.ts +27 -1
- package/tests/installer-downloads.test.ts +30 -1
- package/tests/installer-posix-bootstrap.test.ts +114 -13
- package/tests/installer-preflight.test.ts +49 -1
- package/tests/installer-probes.test.ts +146 -0
- package/tests/installer-server.test.ts +203 -4
- package/tests/installer-windows-bootstrap.test.ts +19 -1
- package/tests/judgment-day-severity-admission.test.ts +46 -0
- package/tests/lazy-module-contradictions-contract.test.ts +158 -0
- package/tests/maintainer/desktop-rpc.maintest.ts +632 -0
- package/tests/maintainer/pi-update-source.maintest.ts +48 -18
- package/tests/model-fallback-policy.test.ts +26 -7
- package/tests/nan-provider-runtime.test.ts +17 -3
- package/tests/nan-provider.test.ts +111 -56
- package/tests/native-review-capability-contract.test.ts +11 -1
- package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
- package/tests/native-review-parity.test.ts +24 -5
- package/tests/native-review-refusal-identity.test.ts +25 -0
- package/tests/no-self-pause-contract.test.ts +11 -3
- package/tests/odd-integration.test.ts +11 -3
- package/tests/odd-routing-contract.test.ts +80 -28
- package/tests/orchestrator-budget.test.ts +30 -5
- package/tests/orchestrator-consultation-sdk.test.ts +32 -6
- package/tests/orchestrator-delegation-mode.test.ts +2 -1
- package/tests/orchestrator-discovery.test.ts +28 -0
- package/tests/orchestrator-prompt-budget.test.ts +11 -2
- package/tests/orchestrator-prompt-diet-contract.test.ts +221 -0
- package/tests/orchestrator-rdd-ownership.test.ts +2 -1
- package/tests/orchestrator-work-search.test.ts +4 -2
- package/tests/package-files.test.ts +25 -1
- package/tests/package-manifest.test.ts +11 -10
- package/tests/parallel-reason-contract.test.ts +6 -3
- package/tests/permission-allowlist.test.ts +200 -30
- package/tests/persona-neutral-voseo.test.ts +4 -4
- package/tests/persona-reply-language.test.ts +1 -1
- package/tests/persona-single-channel.test.ts +13 -5
- package/tests/pi-update-launcher.test.ts +17 -7
- package/tests/pi-update-source.test.ts +113 -6
- package/tests/pi-update.test.ts +294 -19
- package/tests/pnpm-workspace-policy.test.ts +47 -0
- package/tests/primary-context-files.test.ts +233 -0
- package/tests/primary-context-three-files.test.ts +174 -0
- package/tests/provider-defect-handoff.test.ts +9 -2
- package/tests/rdd-aware-verification-contract.test.ts +1 -1
- package/tests/rdd-status-line.test.ts +94 -1
- package/tests/reply-language-anchor-placement.test.ts +184 -0
- package/tests/reply-language-anchor.test.ts +17 -1
- package/tests/request-context-append-only.test.ts +218 -0
- package/tests/request-context-placement.test.ts +148 -0
- package/tests/review-agent-end-preflight.test.ts +79 -1
- package/tests/review-candidate-view.test.ts +65 -0
- package/tests/review-continuation-registry.test.ts +31 -0
- package/tests/review-contract-prompt.test.ts +1 -1
- package/tests/review-controller.test.ts +2 -1
- package/tests/review-coordinator-correction-gate.test.ts +105 -0
- package/tests/review-coordinator-findings.test.ts +206 -0
- package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
- package/tests/review-coordinator.test.ts +271 -4
- package/tests/review-delivery-preflight.test.ts +462 -0
- package/tests/review-due-compaction.test.ts +31 -0
- package/tests/review-due-public-boundary.test.ts +26 -0
- package/tests/review-integration-nonblocking-findings.test.ts +108 -0
- package/tests/review-json-arguments.test.ts +41 -2
- package/tests/review-ledger-contract.test.ts +19 -40
- package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
- package/tests/review-one-call-findings.test.ts +131 -0
- package/tests/review-one-call-followups.test.ts +308 -0
- package/tests/review-one-call-reviewer-requests.test.ts +207 -0
- package/tests/review-one-call.test.ts +452 -0
- package/tests/review-relay-transport-agent.test.ts +28 -1
- package/tests/review-reviewer-evidence.test.ts +41 -1
- package/tests/review-risk-assessment.test.ts +52 -5
- package/tests/review-run-statement-guidance-independent.test.ts +54 -0
- package/tests/review-session-standing-permission-controller.test.ts +32 -2
- package/tests/review-tool-prose-budget.test.ts +1 -0
- package/tests/reviewer-stream.test.ts +149 -0
- package/tests/session-profile-extension.test.ts +2 -2
- package/tests/shell-prompt.test.ts +17 -0
- package/tests/shell-usage.test.ts +59 -10
- package/tests/skill-contradictions-contract.test.ts +122 -0
- package/tests/skill-registry-watcher.test.ts +216 -2
- package/tests/skill-registry.test.ts +929 -306
- package/tests/support/design-canvas-dom.ts +369 -0
- package/tests/support/review-coordinator-runtime.ts +212 -17
- package/tests/task-size-routing-contract.test.ts +42 -11
- package/tests/test-strength-contract.test.ts +2 -1
- package/tests/todo-request-append-only.test.ts +214 -0
- package/tests/tool-batching-contract.test.ts +3 -1
- package/tests/update-agent-body-history.test.ts +138 -0
- package/tests/verification-tiers-contract.test.ts +229 -0
- package/tests/verifier-preparation.test.ts +229 -0
- package/tests/verify-agent-contract.test.ts +20 -2
- package/tests/verify-first-launch-contract.test.ts +87 -11
- package/tests/vim-editor-adapter.test.ts +2 -2
- package/tests/work-continuity-contract.test.ts +54 -11
- package/tests/writer-admission-messages.test.ts +232 -0
- package/tests/writer-batch-admission.test.ts +66 -0
- package/tests/writer-edit-surface-scope.test.ts +52 -20
- package/tests/writer-feature-document-admission.test.ts +184 -0
- package/tests/yolo-mode.test.ts +39 -0
- package/skills/_shared/review-ledger-contract.md +0 -106
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/lens.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/lens.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/targeted-validator.json +0 -0
|
@@ -0,0 +1,1222 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { DESIGN_CANVAS_ASSETS } from "../lib/design-canvas-assets.ts";
|
|
6
|
+
import { click, flush, handoffDoc, loadCanvas, read, setHandoffs, withClass, type FakeElement } from "./support/design-canvas-dom.ts";
|
|
7
|
+
|
|
8
|
+
// Where the artboards sit (canvas-layout.js): design/<slug>/layout.json through the
|
|
9
|
+
// api/designs/<slug>/layout routes, Row / Column / Grid (Free once moved by hand),
|
|
10
|
+
// moving an artboard by dragging any part of it in Move mode, the selected artboard,
|
|
11
|
+
// Space + drag to pan, and focus mode centering a moved artboard.
|
|
12
|
+
|
|
13
|
+
const LAYOUT_URL = "/t/api/designs/alpha/layout";
|
|
14
|
+
const NO_LAYOUT = { [LAYOUT_URL]: { layout: null } };
|
|
15
|
+
const SYSTEM_REPLY = { "/t/api/system": { exists: true, file: "system.html", width: 800, height: 600 } };
|
|
16
|
+
const ARRANGE_IDS = ["gd-arrange-row", "gd-arrange-column", "gd-arrange-grid"];
|
|
17
|
+
const NAVIGATING = "Navigating";
|
|
18
|
+
|
|
19
|
+
async function loadLayout(replies: Record<string, unknown> = {}, config: Record<string, unknown> = {}) {
|
|
20
|
+
const canvas = await loadCanvas(300, replies, config);
|
|
21
|
+
// The fake DOM starts every element visible; index.html starts these hidden.
|
|
22
|
+
canvas.document.getElementById("gd-popover").hidden = true;
|
|
23
|
+
canvas.document.getElementById("gd-menu").hidden = true;
|
|
24
|
+
return canvas;
|
|
25
|
+
}
|
|
26
|
+
type Canvas = Awaited<ReturnType<typeof loadLayout>>;
|
|
27
|
+
|
|
28
|
+
/** Where a world child sits, as the canvas wrote it: [left, top]. */
|
|
29
|
+
const placed = (wrapper: FakeElement) => [wrapper.style.left, wrapper.style.top];
|
|
30
|
+
const worldBox = (canvas: Canvas) => [canvas.world.style.width, canvas.world.style.height];
|
|
31
|
+
const pressedArrangements = (canvas: Canvas) => ARRANGE_IDS.map((id) => canvas.document.getElementById(id).getAttribute("aria-pressed"));
|
|
32
|
+
const layoutPosts = (canvas: Canvas) => canvas.posts.filter((post) => post.url === LAYOUT_URL);
|
|
33
|
+
/** The title in an artboard's label header. */
|
|
34
|
+
const boardTitle = (wrapper: FakeElement) => withClass(wrapper, "gd-artboard-title")[0];
|
|
35
|
+
const implementButton = (wrapper: FakeElement) => withClass(wrapper, "gd-implement-start")[0];
|
|
36
|
+
const translation = (canvas: Canvas) => /translate\((-?[\d.]+)px, (-?[\d.]+)px\)/.exec(canvas.world.style.transform)!.slice(1).map(Number);
|
|
37
|
+
/** Indexes of the selected world children; never the fake elements, which node:assert would walk whole on a failure. */
|
|
38
|
+
const selectedBoards = (canvas: Canvas) => canvas.world.children.flatMap((wrapper, index) => (wrapper.classes.has("gd-selected") ? [index] : []));
|
|
39
|
+
|
|
40
|
+
/** A press on `target`, moves through `path`, and a release (or a cancel) at the last point. */
|
|
41
|
+
async function dragFrom(target: FakeElement, from: [number, number], path: Array<[number, number]>, end = "pointerup") {
|
|
42
|
+
target.dispatch("pointerdown", { button: 0, pointerId: 3, clientX: from[0], clientY: from[1] });
|
|
43
|
+
for (const [x, y] of path) target.dispatch("pointermove", { pointerId: 3, clientX: x, clientY: y });
|
|
44
|
+
const [x, y] = path.length > 0 ? path[path.length - 1] : from;
|
|
45
|
+
target.dispatch(end, { button: 0, pointerId: 3, clientX: x, clientY: y });
|
|
46
|
+
for (let i = 0; i < 5; i++) await flush();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A key event on `target` (its listeners, then its ancestors'), then on the document's listeners, like the browser. */
|
|
50
|
+
function keyAt(canvas: Canvas, type: "keydown" | "keyup", key: string, target: FakeElement = canvas.document.body, init: Record<string, unknown> = {}) {
|
|
51
|
+
const event = target.dispatch(type, { key, shiftKey: false, ctrlKey: false, metaKey: false, altKey: false, ...init });
|
|
52
|
+
for (const listener of canvas.document.listeners.get(type) ?? []) listener(event);
|
|
53
|
+
return event;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ---- where the boards sit (S3)
|
|
57
|
+
|
|
58
|
+
test("without layout.json the artboards sit in a row, 80 px apart and top-aligned, the system board first", async () => {
|
|
59
|
+
const canvas = await loadLayout(SYSTEM_REPLY);
|
|
60
|
+
assert.ok(canvas.fetched.includes(LAYOUT_URL), "the canvas asks for the saved layout");
|
|
61
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["880px", "0px"], ["1360px", "0px"]]);
|
|
62
|
+
assert.deepEqual(worldBox(canvas), ["1760px", "600px"], "the world is as big as the boards' bounds");
|
|
63
|
+
assert.deepEqual(pressedArrangements(canvas), ["true", "false", "false"], "Row is the arrangement");
|
|
64
|
+
assert.deepEqual(canvas.posts, [], "opening a design saves nothing");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("a saved layout is restored; an artboard it does not know goes after the others and one the design lost drops out of the next save", async () => {
|
|
68
|
+
const saved = { arrangement: "free", positions: { "01-a.html": { x: 0, y: 500 }, "02-b.html": { x: 600, y: 0 }, "gone.html": { x: 5000, y: 5000 } } };
|
|
69
|
+
const manifest = { slug: "alpha", title: "Alpha", brief: "", artboards: [
|
|
70
|
+
{ file: "01-a.html", title: "First", tradeoff: "", width: 400, height: 300 },
|
|
71
|
+
{ file: "02-b.html", title: "Second", tradeoff: "", width: 400, height: 300 },
|
|
72
|
+
{ file: "03-c.html", title: "Third", tradeoff: "", width: 400, height: 300 },
|
|
73
|
+
] };
|
|
74
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout: saved }, "/t/api/designs/alpha": manifest });
|
|
75
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "500px"], ["600px", "0px"], ["1080px", "0px"]]);
|
|
76
|
+
assert.deepEqual(worldBox(canvas), ["1480px", "800px"]);
|
|
77
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "false", "false"], "a hand-made layout is none of the arrangements");
|
|
78
|
+
assert.deepEqual(canvas.posts, [], "restoring saves nothing");
|
|
79
|
+
await dragFrom(boardTitle(canvas.world.children[2]), [800, 100], [[800, 140]]);
|
|
80
|
+
assert.deepEqual(layoutPosts(canvas), [{ url: LAYOUT_URL, body: { arrangement: "free", positions: { "01-a.html": { x: 0, y: 500 }, "02-b.html": { x: 600, y: 0 }, "03-c.html": { x: 1080, y: 40 } } } }]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("a design whose layout cannot be read opens in the row", async () => {
|
|
84
|
+
for (const reply of [{ __http: 500 }, { __throw: "offline" }, { layout: { arrangement: "diagonal", positions: {} } }, { layout: { arrangement: "free", positions: { "01-a.html": { x: "far", y: 0 } } } }, { layout: "row" }]) {
|
|
85
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: reply });
|
|
86
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], JSON.stringify(reply));
|
|
87
|
+
assert.deepEqual(pressedArrangements(canvas), ["true", "false", "false"]);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("a layout.json change from another page moves the artboards without reloading any; the page's own save changes nothing", async () => {
|
|
92
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
93
|
+
const frames = canvas.frames();
|
|
94
|
+
const sources = frames.map((frame) => frame.src);
|
|
95
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
96
|
+
const own = layoutPosts(canvas)[0].body;
|
|
97
|
+
canvas.replies[LAYOUT_URL] = { layout: own };
|
|
98
|
+
await canvas.serverEvent("change", { slug: "alpha", file: "layout.json" });
|
|
99
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "0px"]]);
|
|
100
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "column", positions: {} } };
|
|
101
|
+
await canvas.serverEvent("change", { slug: "alpha", file: "layout.json" });
|
|
102
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "a column, as the other page chose");
|
|
103
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"]);
|
|
104
|
+
assert.ok(canvas.frames().every((frame, index) => frame === frames[index] && frame.src === sources[index]), "no artboard reloads");
|
|
105
|
+
assert.equal(layoutPosts(canvas).length, 1, "and nothing is saved back");
|
|
106
|
+
await canvas.serverEvent("change", { slug: "beta", file: "layout.json" });
|
|
107
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "another design's layout is not this one's");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("a layout that cannot be saved says so in the status line, and the artboard stays where it was put", async () => {
|
|
111
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { __http: 400, error: "invalid-layout", reason: "positions may hold at most 100 boards" } });
|
|
112
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
113
|
+
assert.equal(layoutPosts(canvas).length, 1);
|
|
114
|
+
const status = canvas.document.getElementById("gd-status");
|
|
115
|
+
assert.equal(status.textContent, "The layout of alpha could not be saved: positions may hold at most 100 boards");
|
|
116
|
+
assert.ok(status.classes.has("gd-error"));
|
|
117
|
+
assert.deepEqual(placed(canvas.world.children[1]), ["520px", "0px"]);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// ---- saves and reads of layout.json in flight
|
|
121
|
+
|
|
122
|
+
/** A reply the test gives later: a request for it stays in flight until `resolve`. */
|
|
123
|
+
function deferred() {
|
|
124
|
+
let resolve!: (reply: unknown) => void;
|
|
125
|
+
const promise = new Promise<unknown>((done) => { resolve = done; });
|
|
126
|
+
return { promise, resolve };
|
|
127
|
+
}
|
|
128
|
+
const settle = async () => { for (let i = 0; i < 5; i++) await flush(); };
|
|
129
|
+
const LAYOUT_CHANGE = { slug: "alpha", file: "layout.json" };
|
|
130
|
+
|
|
131
|
+
test("layout saves go out one at a time in gesture order: a move made while the previous save is on its way is sent after it", async () => {
|
|
132
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
133
|
+
const firstSave = deferred();
|
|
134
|
+
canvas.replies[LAYOUT_URL] = firstSave.promise;
|
|
135
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
136
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
137
|
+
await dragFrom(boardTitle(canvas.world.children[0]), [100, 100], [[100, 140]]);
|
|
138
|
+
const first = { arrangement: "free", positions: { "01-a.html": { x: 0, y: 0 }, "02-b.html": { x: 520, y: 0 } } };
|
|
139
|
+
const second = { arrangement: "free", positions: { "01-a.html": { x: 0, y: 40 }, "02-b.html": { x: 520, y: 0 } } };
|
|
140
|
+
assert.deepEqual(layoutPosts(canvas).map((post) => post.body), [first], "the second save waits for the first one's reply");
|
|
141
|
+
firstSave.resolve({ ok: true });
|
|
142
|
+
await settle();
|
|
143
|
+
assert.deepEqual(layoutPosts(canvas).map((post) => post.body), [first, second], "then goes out, so the server writes the newer layout last");
|
|
144
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "40px"], ["520px", "0px"]]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("a layout.json change from another page while a save is on its way is read once the save is done", async () => {
|
|
148
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
149
|
+
const save = deferred();
|
|
150
|
+
canvas.replies[LAYOUT_URL] = save.promise;
|
|
151
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
152
|
+
// The page's save landed, then another page chose Column; its change comes before this page's reply.
|
|
153
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "column", positions: {} } };
|
|
154
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
155
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "0px"]], "the page's own move stays while its save is on its way");
|
|
156
|
+
save.resolve({ ok: true });
|
|
157
|
+
await settle();
|
|
158
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "then the other page's column shows");
|
|
159
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"]);
|
|
160
|
+
assert.equal(layoutPosts(canvas).length, 1, "and nothing is saved back");
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("an older layout read that answers last never replaces a newer one", async () => {
|
|
164
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
165
|
+
const older = deferred();
|
|
166
|
+
canvas.replies[LAYOUT_URL] = older.promise;
|
|
167
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
168
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "column", positions: {} } };
|
|
169
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
170
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "the newer read shows");
|
|
171
|
+
older.resolve({ layout: { arrangement: "row", positions: {} } });
|
|
172
|
+
await settle();
|
|
173
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "the older read that answered last is dropped");
|
|
174
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("a layout read on its way when the page saves never undoes the page's newer move", async () => {
|
|
178
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
179
|
+
const read = deferred();
|
|
180
|
+
canvas.replies[LAYOUT_URL] = read.promise;
|
|
181
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
182
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
183
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
184
|
+
assert.equal(layoutPosts(canvas).length, 1, "the move is saved");
|
|
185
|
+
read.resolve({ layout: { arrangement: "column", positions: {} } });
|
|
186
|
+
await settle();
|
|
187
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "0px"]], "the read from before the save is dropped");
|
|
188
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "false", "false"]);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("a layout.json change that comes during a press on an artboard shows once the press ends without a move", async () => {
|
|
192
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
193
|
+
const title = boardTitle(canvas.world.children[1]);
|
|
194
|
+
// A still press: the change waits for the release, then shows.
|
|
195
|
+
title.dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 500, clientY: 100 });
|
|
196
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "column", positions: {} } };
|
|
197
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
198
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], "nothing moves under the press");
|
|
199
|
+
title.dispatch("pointerup", { button: 0, pointerId: 3, clientX: 500, clientY: 100 });
|
|
200
|
+
await settle();
|
|
201
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "the other page's column shows after the release");
|
|
202
|
+
// A cancelled move: the artboard goes back, then the change shows.
|
|
203
|
+
title.dispatch("pointerdown", { button: 0, pointerId: 4, clientX: 100, clientY: 400 });
|
|
204
|
+
title.dispatch("pointermove", { pointerId: 4, clientX: 160, clientY: 400 });
|
|
205
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "row", positions: {} } };
|
|
206
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
207
|
+
assert.deepEqual(placed(canvas.world.children[1]), ["60px", "380px"], "the moved artboard stays under the pointer");
|
|
208
|
+
title.dispatch("pointercancel", { button: 0, pointerId: 4, clientX: 160, clientY: 400 });
|
|
209
|
+
await settle();
|
|
210
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], "the row shows after the cancel");
|
|
211
|
+
assert.deepEqual(pressedArrangements(canvas), ["true", "false", "false"]);
|
|
212
|
+
assert.deepEqual(canvas.posts, [], "and nothing is saved");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("a layout.json change from another page that comes while an artboard is dragged shows once the drag is cancelled", async () => {
|
|
216
|
+
// Page A sits in a row; page B chooses Column while A drags an artboard; A's drag is then cancelled.
|
|
217
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
218
|
+
const title = boardTitle(canvas.world.children[1]);
|
|
219
|
+
title.dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 500, clientY: 100 });
|
|
220
|
+
title.dispatch("pointermove", { pointerId: 3, clientX: 560, clientY: 100 });
|
|
221
|
+
assert.deepEqual(placed(canvas.world.children[1]), ["540px", "0px"], "the artboard follows the drag");
|
|
222
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "column", positions: {} } };
|
|
223
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
224
|
+
assert.deepEqual(placed(canvas.world.children[1]), ["540px", "0px"], "nothing moves under the drag");
|
|
225
|
+
title.dispatch("pointercancel", { button: 0, pointerId: 3, clientX: 560, clientY: 100 });
|
|
226
|
+
await settle();
|
|
227
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "B's column shows after the cancel");
|
|
228
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"]);
|
|
229
|
+
assert.deepEqual(canvas.posts, [], "and the cancelled drag saves nothing");
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("an arrangement whose save failed stays until another page changes layout.json: the page's own earlier save, notified late, never replaces it", async () => {
|
|
233
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
234
|
+
const status = canvas.document.getElementById("gd-status");
|
|
235
|
+
const arrange = async (id: string) => {
|
|
236
|
+
canvas.document.getElementById(id).dispatch("click");
|
|
237
|
+
await settle();
|
|
238
|
+
};
|
|
239
|
+
// Grid is saved; Column's save is rejected.
|
|
240
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
241
|
+
await arrange("gd-arrange-grid");
|
|
242
|
+
const grid = layoutPosts(canvas)[0].body;
|
|
243
|
+
canvas.replies[LAYOUT_URL] = { __http: 400, error: "invalid-layout", reason: "disk full" };
|
|
244
|
+
await arrange("gd-arrange-column");
|
|
245
|
+
assert.equal(layoutPosts(canvas).length, 2);
|
|
246
|
+
assert.equal(status.textContent, "The layout of alpha could not be saved: disk full");
|
|
247
|
+
// The file event of the Grid save comes late: layout.json still holds the page's own Grid.
|
|
248
|
+
canvas.replies[LAYOUT_URL] = { layout: grid };
|
|
249
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
250
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "the unsaved column stays");
|
|
251
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"]);
|
|
252
|
+
assert.equal(status.textContent, "The layout of alpha could not be saved: disk full", "and the error still names it");
|
|
253
|
+
assert.ok(status.classes.has("gd-error"));
|
|
254
|
+
// A design.json reload reads the same Grid: still no news.
|
|
255
|
+
await canvas.serverEvent("change", { slug: "alpha", file: "design.json" });
|
|
256
|
+
await settle();
|
|
257
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "a reload keeps the unsaved column too");
|
|
258
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"]);
|
|
259
|
+
// Another page writes Row: the file now holds something this page never saved, so it shows.
|
|
260
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "row", positions: {} } };
|
|
261
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
262
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], "the other page's row wins");
|
|
263
|
+
assert.deepEqual(pressedArrangements(canvas), ["true", "false", "false"]);
|
|
264
|
+
assert.equal(layoutPosts(canvas).length, 2, "and nothing is saved back");
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test("a design.json reload whose layout read answers after the page's newer save is done never undoes the page's move", async () => {
|
|
268
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
269
|
+
const read = deferred();
|
|
270
|
+
canvas.replies[LAYOUT_URL] = read.promise;
|
|
271
|
+
await canvas.serverEvent("change", { slug: "alpha", file: "design.json" });
|
|
272
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
273
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
274
|
+
assert.equal(layoutPosts(canvas).length, 1, "the move is saved, and its save is done");
|
|
275
|
+
read.resolve({ layout: null });
|
|
276
|
+
await settle();
|
|
277
|
+
await settle();
|
|
278
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "0px"]], "the reload's older read is dropped");
|
|
279
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "false", "false"]);
|
|
280
|
+
assert.equal(layoutPosts(canvas).length, 1);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test("a design.json reload whose layout read answers while the page's save is still on its way keeps the page's move", async () => {
|
|
284
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
285
|
+
const save = deferred();
|
|
286
|
+
canvas.replies[LAYOUT_URL] = save.promise;
|
|
287
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
288
|
+
canvas.replies[LAYOUT_URL] = { layout: null };
|
|
289
|
+
await canvas.serverEvent("change", { slug: "alpha", file: "design.json" });
|
|
290
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "0px"]], "the file read before the save landed is older than the move");
|
|
291
|
+
save.resolve({ ok: true });
|
|
292
|
+
await settle();
|
|
293
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "0px"]]);
|
|
294
|
+
assert.equal(layoutPosts(canvas).length, 1);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test("a layout read that fails keeps the layout shown: a design.json reload after a failed save keeps the unsaved column and saves nothing", async () => {
|
|
298
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout: { arrangement: "grid", positions: {} } } });
|
|
299
|
+
canvas.replies[LAYOUT_URL] = { __http: 400, error: "invalid-layout", reason: "disk full" };
|
|
300
|
+
canvas.document.getElementById("gd-arrange-column").dispatch("click");
|
|
301
|
+
await settle();
|
|
302
|
+
assert.equal(layoutPosts(canvas).length, 1, "Column's save is rejected");
|
|
303
|
+
for (const reply of [{ __http: 500 }, { __throw: "offline" }]) {
|
|
304
|
+
canvas.replies[LAYOUT_URL] = reply;
|
|
305
|
+
await canvas.serverEvent("change", { slug: "alpha", file: "design.json" });
|
|
306
|
+
await settle();
|
|
307
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], `the unsaved column stays (${JSON.stringify(reply)})`);
|
|
308
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"]);
|
|
309
|
+
}
|
|
310
|
+
assert.equal(layoutPosts(canvas).length, 1, "and nothing is saved");
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test("a layout.json change whose read fails keeps the layout shown instead of falling back to the row", async () => {
|
|
314
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout: { arrangement: "column", positions: {} } } });
|
|
315
|
+
for (const reply of [{ __http: 500 }, { __throw: "offline" }]) {
|
|
316
|
+
canvas.replies[LAYOUT_URL] = reply;
|
|
317
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
318
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], JSON.stringify(reply));
|
|
319
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"]);
|
|
320
|
+
}
|
|
321
|
+
// The next read that answers still shows another page's change.
|
|
322
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "row", positions: {} } };
|
|
323
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
324
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]]);
|
|
325
|
+
assert.deepEqual(canvas.posts, [], "nothing is saved");
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test("a design.json reload of an unchanged layout with negative positions leaves the view where it is", async () => {
|
|
329
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout: { arrangement: "free", positions: { "01-a.html": { x: -200, y: -100 }, "02-b.html": { x: 480, y: 0 } } } } });
|
|
330
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["680px", "100px"]]);
|
|
331
|
+
const view = translation(canvas);
|
|
332
|
+
for (let reload = 1; reload <= 2; reload++) {
|
|
333
|
+
await canvas.serverEvent("change", { slug: "alpha", file: "design.json" });
|
|
334
|
+
await settle();
|
|
335
|
+
assert.deepEqual(translation(canvas), view, `reload ${reload} keeps the view`);
|
|
336
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["680px", "100px"]]);
|
|
337
|
+
}
|
|
338
|
+
assert.deepEqual(canvas.posts, []);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test("a layout.json change of the next design that comes before its design.json never moves or saves the boards still shown", async () => {
|
|
342
|
+
const BETA_LAYOUT = "/t/api/designs/beta/layout";
|
|
343
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
344
|
+
const betaManifest = deferred();
|
|
345
|
+
const beta = canvas.replies["/t/api/designs/beta"];
|
|
346
|
+
canvas.replies["/t/api/designs/beta"] = betaManifest.promise;
|
|
347
|
+
canvas.replies[BETA_LAYOUT] = { layout: { arrangement: "column", positions: {} } };
|
|
348
|
+
const select = canvas.document.getElementById("gd-design");
|
|
349
|
+
select.value = "beta";
|
|
350
|
+
select.dispatch("change");
|
|
351
|
+
await canvas.serverEvent("change", { slug: "beta", file: "layout.json" });
|
|
352
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], "alpha's boards keep alpha's row");
|
|
353
|
+
assert.deepEqual(pressedArrangements(canvas), ["true", "false", "false"]);
|
|
354
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
355
|
+
assert.deepEqual(canvas.posts.filter((post) => post.url === BETA_LAYOUT), [], "alpha's boards are never written to beta's layout.json");
|
|
356
|
+
betaManifest.resolve(beta);
|
|
357
|
+
await settle();
|
|
358
|
+
assert.equal(canvas.world.children.length, 1, "beta's board shows");
|
|
359
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"], "in beta's column");
|
|
360
|
+
assert.deepEqual(canvas.posts.filter((post) => post.url === BETA_LAYOUT), []);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test("a save that lands after the page left the design and came back shows once its layout.json change comes", async () => {
|
|
364
|
+
const grid = { arrangement: "grid", positions: {} };
|
|
365
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout: grid } });
|
|
366
|
+
const select = canvas.document.getElementById("gd-design");
|
|
367
|
+
const open = async (slug: string) => {
|
|
368
|
+
select.value = slug;
|
|
369
|
+
select.dispatch("change");
|
|
370
|
+
await settle();
|
|
371
|
+
};
|
|
372
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], "alpha opens in its grid");
|
|
373
|
+
// Column's save stays on its way while the page goes to beta and back; alpha's layout.json still holds the grid.
|
|
374
|
+
const save = deferred();
|
|
375
|
+
canvas.replies[LAYOUT_URL] = save.promise;
|
|
376
|
+
canvas.document.getElementById("gd-arrange-column").dispatch("click");
|
|
377
|
+
await settle();
|
|
378
|
+
assert.deepEqual(layoutPosts(canvas).map((post) => (post.body as { arrangement: string }).arrangement), ["column"]);
|
|
379
|
+
const column = layoutPosts(canvas)[0].body;
|
|
380
|
+
canvas.replies[LAYOUT_URL] = { layout: grid };
|
|
381
|
+
await open("beta");
|
|
382
|
+
assert.equal(canvas.world.children.length, 1, "beta's board shows");
|
|
383
|
+
await open("alpha");
|
|
384
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], "back in alpha, the file's grid shows");
|
|
385
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "false", "true"]);
|
|
386
|
+
// The server takes the column, then its layout.json change comes.
|
|
387
|
+
save.resolve({ ok: true });
|
|
388
|
+
await settle();
|
|
389
|
+
canvas.replies[LAYOUT_URL] = { layout: column };
|
|
390
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
391
|
+
await settle();
|
|
392
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "the column the server took shows");
|
|
393
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"]);
|
|
394
|
+
assert.equal(layoutPosts(canvas).length, 1, "and nothing is saved back");
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test("a second pointer pressed during a move never takes the move over: the moved artboard is saved on its own release", async () => {
|
|
398
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
399
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
400
|
+
const wrapper = canvas.world.children[1];
|
|
401
|
+
const title = boardTitle(wrapper);
|
|
402
|
+
title.dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 500, clientY: 100 });
|
|
403
|
+
title.dispatch("pointermove", { pointerId: 3, clientX: 560, clientY: 100 });
|
|
404
|
+
canvas.viewport.dispatch("pointerdown", { button: 0, pointerId: 4, clientX: 900, clientY: 600 });
|
|
405
|
+
canvas.viewport.dispatch("pointerup", { button: 0, pointerId: 4, clientX: 900, clientY: 600 });
|
|
406
|
+
title.dispatch("pointerup", { button: 0, pointerId: 3, clientX: 560, clientY: 100 });
|
|
407
|
+
await settle();
|
|
408
|
+
assert.deepEqual(layoutPosts(canvas).map((post) => post.body), [{ arrangement: "free", positions: { "01-a.html": { x: 0, y: 0 }, "02-b.html": { x: 540, y: 0 } } }]);
|
|
409
|
+
assert.equal(wrapper.classes.has("gd-lifted"), false, "the artboard is put down");
|
|
410
|
+
assert.deepEqual(selectedBoards(canvas), [1], "the second press changes no selection");
|
|
411
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "column", positions: {} } };
|
|
412
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
413
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "a later layout.json change shows");
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test("a save that succeeds after a failed one clears the save error, never another status", async () => {
|
|
417
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
418
|
+
const status = canvas.document.getElementById("gd-status");
|
|
419
|
+
canvas.replies[LAYOUT_URL] = { __http: 400, error: "invalid-layout", reason: "disk full" };
|
|
420
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
421
|
+
assert.equal(status.textContent, "The layout of alpha could not be saved: disk full");
|
|
422
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
423
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [540, 100], [[560, 100]]);
|
|
424
|
+
assert.equal(layoutPosts(canvas).length, 2);
|
|
425
|
+
assert.equal(status.textContent, "", "the retry's success clears the error");
|
|
426
|
+
assert.equal(status.classes.has("gd-error"), false);
|
|
427
|
+
// Another status shown after the failure stays.
|
|
428
|
+
canvas.replies[LAYOUT_URL] = { __http: 400, error: "invalid-layout", reason: "disk full" };
|
|
429
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [560, 100], [[580, 100]]);
|
|
430
|
+
await canvas.serverEvent("error", {});
|
|
431
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
432
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [580, 100], [[600, 100]]);
|
|
433
|
+
assert.equal(layoutPosts(canvas).length, 4);
|
|
434
|
+
assert.equal(status.textContent, "Live reload disconnected, retrying…");
|
|
435
|
+
assert.ok(status.classes.has("gd-error"));
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// ---- moving an artboard (S1, S9) in Move mode
|
|
439
|
+
|
|
440
|
+
test("dragging an artboard's title moves it in world px at any zoom and saves it once, on release, as a free layout", async () => {
|
|
441
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
442
|
+
const [first, second] = canvas.world.children;
|
|
443
|
+
canvas.document.getElementById("gd-zoom-out").dispatch("click");
|
|
444
|
+
assert.equal(canvas.zoomLevel.textContent, "80%");
|
|
445
|
+
const view = canvas.world.style.transform;
|
|
446
|
+
// Within the 4 px click slop nothing moves; then 80 x 40 screen px at 80% are 100 x 50 world px.
|
|
447
|
+
boardTitle(second).dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 500, clientY: 300 });
|
|
448
|
+
assert.ok(canvas.viewport.classes.has("gd-moving"), "the grabbing cursor of a move");
|
|
449
|
+
boardTitle(second).dispatch("pointermove", { pointerId: 3, clientX: 503, clientY: 302 });
|
|
450
|
+
assert.deepEqual(placed(second), ["480px", "0px"], "a still press does not move");
|
|
451
|
+
boardTitle(second).dispatch("pointermove", { pointerId: 3, clientX: 580, clientY: 340 });
|
|
452
|
+
assert.deepEqual(placed(second), ["580px", "50px"]);
|
|
453
|
+
assert.ok(second.classes.has("gd-lifted"), "the moved artboard is lifted above the others");
|
|
454
|
+
assert.equal(layoutPosts(canvas).length, 0, "nothing is saved while it moves");
|
|
455
|
+
boardTitle(second).dispatch("pointerup", { button: 0, pointerId: 3, clientX: 580, clientY: 340 });
|
|
456
|
+
for (let i = 0; i < 5; i++) await flush();
|
|
457
|
+
assert.ok(!canvas.viewport.classes.has("gd-moving"));
|
|
458
|
+
assert.ok(!second.classes.has("gd-lifted"));
|
|
459
|
+
assert.equal(canvas.world.style.transform, view, "moving an artboard never pans");
|
|
460
|
+
assert.equal(canvas.navMode.textContent, NAVIGATING, "nor opens it");
|
|
461
|
+
assert.deepEqual(canvas.posts, [{ url: LAYOUT_URL, body: { arrangement: "free", positions: { "01-a.html": { x: 0, y: 0 }, "02-b.html": { x: 580, y: 50 } } } }]);
|
|
462
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "false", "false"], "a hand-made layout is none of the arrangements");
|
|
463
|
+
assert.deepEqual(worldBox(canvas), ["980px", "350px"]);
|
|
464
|
+
assert.deepEqual(placed(first), ["0px", "0px"], "the other artboard stays");
|
|
465
|
+
|
|
466
|
+
// Left of everything: the boards keep their place on screen and the world's top left stays the bounds' top left.
|
|
467
|
+
const [x, y] = translation(canvas);
|
|
468
|
+
await dragFrom(boardTitle(first), [100, 100], [[-100, 100]]);
|
|
469
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["830px", "50px"]]);
|
|
470
|
+
assert.equal(canvas.world.style.transform, `translate(${x - 200}px, ${y}px) scale(0.8)`);
|
|
471
|
+
assert.deepEqual(layoutPosts(canvas).at(-1)!.body, { arrangement: "free", positions: { "01-a.html": { x: 0, y: 0 }, "02-b.html": { x: 830, y: 50 } } });
|
|
472
|
+
assert.equal(layoutPosts(canvas).length, 2, "one save per move");
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
test("a still click on a title moves nothing, and a cancelled move puts the artboard back unsaved", async () => {
|
|
476
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
477
|
+
const second = canvas.world.children[1];
|
|
478
|
+
click(boardTitle(second), 500, 300);
|
|
479
|
+
await dragFrom(boardTitle(second), [500, 300], [[600, 400]], "pointercancel");
|
|
480
|
+
assert.deepEqual(placed(second), ["480px", "0px"]);
|
|
481
|
+
assert.ok(!second.classes.has("gd-lifted"), "and lays it down");
|
|
482
|
+
assert.deepEqual(canvas.posts, []);
|
|
483
|
+
assert.equal(canvas.navMode.textContent, NAVIGATING);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
const moveTargets: Array<[string, (canvas: Canvas) => FakeElement]> = [
|
|
487
|
+
["artboard gap", (canvas) => canvas.boards[0].wrapper],
|
|
488
|
+
["frame box", (canvas) => canvas.boards[0].frame.parentElement!],
|
|
489
|
+
["artboard title", (canvas) => boardTitle(canvas.boards[0].wrapper)],
|
|
490
|
+
["actions gap", (canvas) => withClass(canvas.boards[0].wrapper, "gd-board-actions")[0]],
|
|
491
|
+
["shield", (canvas) => canvas.boards[0].shield!],
|
|
492
|
+
];
|
|
493
|
+
|
|
494
|
+
for (const [name, targetOf] of moveTargets) {
|
|
495
|
+
test(`a drag on the ${name} moves the artboard in Move mode, without panning or selecting text`, async () => {
|
|
496
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
497
|
+
const [board, other] = canvas.boards;
|
|
498
|
+
const view = canvas.world.style.transform;
|
|
499
|
+
const down = targetOf(canvas).dispatch("pointerdown", { button: 0, pointerId: 7, clientX: 10, clientY: 10 });
|
|
500
|
+
canvas.viewport.dispatch("pointermove", { pointerId: 7, clientX: 45, clientY: 30 });
|
|
501
|
+
assert.equal(down.defaultPrevented, true, "the press suppresses the pointer default");
|
|
502
|
+
assert.deepEqual(canvas.viewport.capturedPointers, [7]);
|
|
503
|
+
assert.equal(canvas.viewport.classes.has("gd-moving"), true);
|
|
504
|
+
assert.equal(canvas.viewport.classes.has("gd-panning"), false);
|
|
505
|
+
canvas.viewport.dispatch("pointerup", { button: 0, pointerId: 7, clientX: 45, clientY: 30 });
|
|
506
|
+
assert.deepEqual(placed(board.wrapper), ["35px", "20px"], "the artboard followed the pointer");
|
|
507
|
+
assert.deepEqual(placed(other.wrapper), ["480px", "0px"]);
|
|
508
|
+
assert.equal(canvas.world.style.transform, view, "the canvas did not pan");
|
|
509
|
+
assert.equal(canvas.viewport.classes.has("gd-moving"), false);
|
|
510
|
+
assert.equal(canvas.navMode.textContent, NAVIGATING, "a drag does not focus a shield");
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
test("in Move mode the empty canvas still pans, a still click on the body still opens it, header buttons keep their default, and focus mode moves nothing", async () => {
|
|
515
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
516
|
+
const [first, second] = canvas.boards;
|
|
517
|
+
const before = canvas.world.style.transform;
|
|
518
|
+
await dragFrom(second.shield!, [550, 150], [[590, 170]]);
|
|
519
|
+
assert.equal(canvas.world.style.transform, before, "the body moves its artboard instead of panning");
|
|
520
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "20px"]]);
|
|
521
|
+
assert.equal(layoutPosts(canvas).length, 1);
|
|
522
|
+
await dragFrom(canvas.world, [700, 600], [[650, 560]]);
|
|
523
|
+
assert.notEqual(canvas.world.style.transform, before, "the empty canvas pans");
|
|
524
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "20px"]], "and no artboard moved");
|
|
525
|
+
const implement = implementButton(second.wrapper);
|
|
526
|
+
const press = implement.dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 700, clientY: 120 });
|
|
527
|
+
assert.equal(press.defaultPrevented, false, "a header button keeps its press");
|
|
528
|
+
implement.dispatch("pointermove", { pointerId: 3, clientX: 800, clientY: 200 });
|
|
529
|
+
implement.dispatch("pointerup", { button: 0, pointerId: 3, clientX: 800, clientY: 200 });
|
|
530
|
+
assert.deepEqual(placed(second.wrapper), ["520px", "20px"], "a press on a header button does not move the artboard");
|
|
531
|
+
click(second.shield!, 600, 200);
|
|
532
|
+
assert.match(canvas.navMode.textContent, /^Using: Second/, "a still click on the body opens it");
|
|
533
|
+
assert.equal(canvas.document.getElementById("gd-arrange-grid").disabled, true, "no arrangement while an artboard is in use");
|
|
534
|
+
await dragFrom(boardTitle(second.wrapper), [500, 60], [[600, 160]]);
|
|
535
|
+
await dragFrom(first.shield!, [100, 160], [[200, 260]]);
|
|
536
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "20px"]], "focus mode moves nothing");
|
|
537
|
+
assert.equal(layoutPosts(canvas).length, 1);
|
|
538
|
+
canvas.document.getElementById("gd-back").dispatch("click");
|
|
539
|
+
assert.equal(canvas.document.getElementById("gd-arrange-grid").disabled, false);
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
test("Comment mode keeps main's pick routing: a press on an artboard pans instead of moving it, and a still click picks an element", async () => {
|
|
543
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
544
|
+
const [first] = canvas.boards;
|
|
545
|
+
canvas.document.getElementById("gd-comment").dispatch("click");
|
|
546
|
+
const [x, y] = translation(canvas);
|
|
547
|
+
await dragFrom(first.shield!, [150, 150], [[190, 170]]);
|
|
548
|
+
await dragFrom(boardTitle(first.wrapper), [150, 20], [[160, 20]]);
|
|
549
|
+
assert.deepEqual(translation(canvas), [x + 50, y + 20], "the frame and the title pan");
|
|
550
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], "and no artboard moves");
|
|
551
|
+
assert.deepEqual(selectedBoards(canvas), [], "nor is selected");
|
|
552
|
+
assert.deepEqual(canvas.posts, []);
|
|
553
|
+
first.frame.rect = { left: 100, top: 100, width: 200, height: 150 };
|
|
554
|
+
click(first.shield!, 150, 130);
|
|
555
|
+
assert.equal(canvas.navMode.textContent, NAVIGATING, "comment mode picks instead of focusing");
|
|
556
|
+
assert.deepEqual(first.frame.contentWindow!.posted.at(-1), { type: "gd:pick-at", x: 100, y: 60 });
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
// ---- Space + drag pans (S9)
|
|
560
|
+
|
|
561
|
+
test("holding Space pans from anywhere, over an artboard too, with a grab cursor, and never scrolls the page", async () => {
|
|
562
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
563
|
+
const [, second] = canvas.boards;
|
|
564
|
+
const [x, y] = translation(canvas);
|
|
565
|
+
assert.equal(keyAt(canvas, "keydown", " ").defaultPrevented, true, "Space does not scroll the page");
|
|
566
|
+
assert.ok(canvas.viewport.classes.has("gd-space-pan"), "a grab cursor while it is held");
|
|
567
|
+
assert.equal(keyAt(canvas, "keydown", " ", undefined, { repeat: true }).defaultPrevented, true, "nor does its auto-repeat");
|
|
568
|
+
await dragFrom(second.shield!, [500, 300], [[540, 320]]);
|
|
569
|
+
await dragFrom(boardTitle(second.wrapper), [500, 60], [[520, 60]]);
|
|
570
|
+
assert.deepEqual(translation(canvas), [x + 60, y + 20], "the frame and the title pan");
|
|
571
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], "and no artboard moves");
|
|
572
|
+
click(second.shield!, 500, 300);
|
|
573
|
+
assert.equal(canvas.navMode.textContent, NAVIGATING, "a still press with Space opens nothing");
|
|
574
|
+
assert.deepEqual(selectedBoards(canvas), [], "nor selects");
|
|
575
|
+
assert.deepEqual(canvas.posts, []);
|
|
576
|
+
keyAt(canvas, "keyup", " ");
|
|
577
|
+
assert.ok(!canvas.viewport.classes.has("gd-space-pan"));
|
|
578
|
+
await dragFrom(second.shield!, [500, 300], [[540, 320]]);
|
|
579
|
+
assert.deepEqual(placed(second.wrapper), ["520px", "20px"], "without Space a drag moves the artboard again");
|
|
580
|
+
assert.deepEqual(translation(canvas), [x + 60, y + 20]);
|
|
581
|
+
// A window that loses focus never sees the release: Space lets go.
|
|
582
|
+
keyAt(canvas, "keydown", " ");
|
|
583
|
+
canvas.windowEvent("blur");
|
|
584
|
+
assert.ok(!canvas.viewport.classes.has("gd-space-pan"));
|
|
585
|
+
await dragFrom(second.shield!, [500, 300], [[510, 300]]);
|
|
586
|
+
assert.deepEqual(placed(second.wrapper), ["530px", "20px"]);
|
|
587
|
+
|
|
588
|
+
const css = read("canvas.css");
|
|
589
|
+
assert.match(css, /\.gd-viewport\.gd-space-pan, \.gd-viewport\.gd-space-pan \* \{ cursor: grab; \}/);
|
|
590
|
+
assert.match(css, /\.gd-viewport\.gd-space-pan\.gd-panning, \.gd-viewport\.gd-space-pan\.gd-panning \* \{ cursor: grabbing; \}/);
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
test("Space stays with fields, buttons, the comment box, a menu, the shortcuts list and an artboard in use; on a shield it still opens it", async () => {
|
|
594
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
595
|
+
const [first] = canvas.boards;
|
|
596
|
+
const editable = canvas.document.createElement("div");
|
|
597
|
+
editable.setAttribute("contenteditable", "true");
|
|
598
|
+
for (const target of [...["input", "textarea", "select", "button", "a"].map((tag) => canvas.document.createElement(tag)), editable]) {
|
|
599
|
+
assert.equal(keyAt(canvas, "keydown", " ", target).defaultPrevented, false, `${target.localName}: Space keeps its default`);
|
|
600
|
+
assert.ok(!canvas.viewport.classes.has("gd-space-pan"), target.localName);
|
|
601
|
+
}
|
|
602
|
+
const popover = canvas.document.getElementById("gd-popover");
|
|
603
|
+
popover.hidden = false;
|
|
604
|
+
assert.equal(keyAt(canvas, "keydown", " ").defaultPrevented, false, "the comment box keeps it");
|
|
605
|
+
popover.hidden = true;
|
|
606
|
+
canvas.document.getElementById("gd-rail-settings").dispatch("click");
|
|
607
|
+
assert.equal(keyAt(canvas, "keydown", " ").defaultPrevented, false, "an open menu keeps it");
|
|
608
|
+
canvas.document.getElementById("gd-rail-settings").dispatch("click");
|
|
609
|
+
canvas.document.getElementById("gd-shortcuts").setAttribute("open", "");
|
|
610
|
+
assert.equal(keyAt(canvas, "keydown", " ").defaultPrevented, false, "the shortcuts list keeps it");
|
|
611
|
+
canvas.document.getElementById("gd-shortcuts").removeAttribute("open");
|
|
612
|
+
assert.ok(!canvas.viewport.classes.has("gd-space-pan"));
|
|
613
|
+
|
|
614
|
+
// From the keyboard an artboard's shield is a button: Space opens it, as before.
|
|
615
|
+
assert.equal(keyAt(canvas, "keydown", " ", first.shield!).defaultPrevented, true);
|
|
616
|
+
assert.match(canvas.navMode.textContent, /^Using: First/);
|
|
617
|
+
assert.ok(!canvas.viewport.classes.has("gd-space-pan"), "and starts no pan");
|
|
618
|
+
// Inside an artboard Space belongs to it and to the Back button.
|
|
619
|
+
assert.equal(keyAt(canvas, "keydown", " ").defaultPrevented, false, "focus mode keeps it");
|
|
620
|
+
assert.ok(!canvas.viewport.classes.has("gd-space-pan"));
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
// ---- the selected artboard (S10)
|
|
624
|
+
|
|
625
|
+
test("pressing an artboard outlines all of it as selected until a press elsewhere or Esc, one at a time; opening it clears it", async () => {
|
|
626
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
627
|
+
const [first, second] = canvas.boards;
|
|
628
|
+
assert.deepEqual(selectedBoards(canvas), []);
|
|
629
|
+
second.shield!.dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 500, clientY: 300 });
|
|
630
|
+
assert.deepEqual(selectedBoards(canvas), [1], "on the press, before it moves");
|
|
631
|
+
second.shield!.dispatch("pointermove", { pointerId: 3, clientX: 540, clientY: 320 });
|
|
632
|
+
second.shield!.dispatch("pointerup", { button: 0, pointerId: 3, clientX: 540, clientY: 320 });
|
|
633
|
+
for (let i = 0; i < 5; i++) await flush();
|
|
634
|
+
assert.deepEqual(selectedBoards(canvas), [1], "and after the drop");
|
|
635
|
+
await dragFrom(boardTitle(first.wrapper), [100, 20], []);
|
|
636
|
+
assert.deepEqual(selectedBoards(canvas), [0], "another artboard's title takes it: one at a time");
|
|
637
|
+
await dragFrom(canvas.world, [700, 600], [[650, 560]]);
|
|
638
|
+
assert.deepEqual(selectedBoards(canvas), [], "a press on the background clears it");
|
|
639
|
+
await dragFrom(second.shield!, [500, 300], [[510, 300]]);
|
|
640
|
+
implementButton(second.wrapper).dispatch("pointerdown", { button: 0, pointerId: 4, clientX: 700, clientY: 20 });
|
|
641
|
+
assert.deepEqual(selectedBoards(canvas), [1], "a header button keeps it");
|
|
642
|
+
const shiftEsc = keyAt(canvas, "keydown", "Escape", undefined, { shiftKey: true });
|
|
643
|
+
assert.equal(shiftEsc.defaultPrevented, false);
|
|
644
|
+
assert.deepEqual(selectedBoards(canvas), [1], "Shift+Esc is not for the selection");
|
|
645
|
+
const esc = keyAt(canvas, "keydown", "Escape");
|
|
646
|
+
assert.equal(esc.defaultPrevented, true);
|
|
647
|
+
assert.deepEqual(selectedBoards(canvas), [], "Esc clears it");
|
|
648
|
+
// With an artboard selected in Comment mode, Esc clears the selection first, then leaves Comment mode.
|
|
649
|
+
await dragFrom(second.shield!, [500, 300], [[510, 300]]);
|
|
650
|
+
canvas.document.getElementById("gd-comment").dispatch("click");
|
|
651
|
+
keyAt(canvas, "keydown", "Escape");
|
|
652
|
+
assert.deepEqual(selectedBoards(canvas), []);
|
|
653
|
+
assert.equal(canvas.document.getElementById("gd-comment").getAttribute("aria-pressed"), "true");
|
|
654
|
+
keyAt(canvas, "keydown", "Escape");
|
|
655
|
+
assert.equal(canvas.document.getElementById("gd-comment").getAttribute("aria-pressed"), "false");
|
|
656
|
+
await dragFrom(second.shield!, [500, 300], [[510, 300]]);
|
|
657
|
+
click(first.shield!, 150, 150);
|
|
658
|
+
assert.match(canvas.navMode.textContent, /^Using: First/);
|
|
659
|
+
assert.deepEqual(selectedBoards(canvas), [], "a still click opens it, selected only for the press");
|
|
660
|
+
canvas.document.getElementById("gd-back").dispatch("click");
|
|
661
|
+
assert.deepEqual(selectedBoards(canvas), []);
|
|
662
|
+
|
|
663
|
+
const css = read("canvas.css");
|
|
664
|
+
const start = css.indexOf("\n.gd-world .gd-selected {");
|
|
665
|
+
assert.ok(start >= 0, "the selected artboard is styled");
|
|
666
|
+
const rule = css.slice(start, css.indexOf("}", start) + 1);
|
|
667
|
+
assert.match(rule, /outline:[^;]*var\(--gd-accent\)/, "an accent outline around the whole artboard");
|
|
668
|
+
assert.ok(!/#[0-9a-fA-F]{3,8}\b|rgba?\(|transition|animation/.test(rule), "tokens only, and no motion");
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
// ---- Row, Column and Grid (S2)
|
|
672
|
+
|
|
673
|
+
const MIXED_REPLY = {
|
|
674
|
+
...SYSTEM_REPLY,
|
|
675
|
+
...NO_LAYOUT,
|
|
676
|
+
"/t/api/designs/alpha": {
|
|
677
|
+
slug: "alpha",
|
|
678
|
+
title: "Alpha",
|
|
679
|
+
brief: "",
|
|
680
|
+
artboards: [
|
|
681
|
+
{ file: "01-a.html", title: "A", tradeoff: "", width: 400, height: 300 },
|
|
682
|
+
{ file: "02-b.html", title: "B", tradeoff: "", width: 200, height: 500 },
|
|
683
|
+
{ file: "03-c.html", title: "C", tradeoff: "", width: 300, height: 100 },
|
|
684
|
+
{ file: "04-d.html", title: "D", tradeoff: "", width: 100, height: 200 },
|
|
685
|
+
],
|
|
686
|
+
},
|
|
687
|
+
};
|
|
688
|
+
const MIXED_KEYS = ["system", "01-a.html", "02-b.html", "03-c.html", "04-d.html"];
|
|
689
|
+
const positionsOf = (rows: number[][]) => Object.fromEntries(rows.map(([x, y], index) => [MIXED_KEYS[index], { x, y }]));
|
|
690
|
+
|
|
691
|
+
test("Row, Column and Grid arrange every artboard with 80 px between them, save the arrangement and fit the view", async () => {
|
|
692
|
+
const canvas = await loadLayout(MIXED_REPLY);
|
|
693
|
+
Object.defineProperty(canvas.world, "offsetWidth", { get: () => Number.parseFloat(canvas.world.style.width) });
|
|
694
|
+
Object.defineProperty(canvas.world, "offsetHeight", { get: () => Number.parseFloat(canvas.world.style.height) });
|
|
695
|
+
const arrange = async (id: string) => {
|
|
696
|
+
canvas.document.getElementById(id).dispatch("click");
|
|
697
|
+
for (let i = 0; i < 5; i++) await flush();
|
|
698
|
+
};
|
|
699
|
+
// Grid: 5 boards in 3 columns as wide as their widest, rows as tall as their tallest.
|
|
700
|
+
await arrange("gd-arrange-grid");
|
|
701
|
+
const grid = [[0, 0], [880, 0], [1360, 0], [0, 680], [880, 680]];
|
|
702
|
+
assert.deepEqual(canvas.world.children.map(placed), grid.map(([x, y]) => [`${x}px`, `${y}px`]));
|
|
703
|
+
assert.deepEqual(worldBox(canvas), ["1560px", "880px"]);
|
|
704
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "false", "true"]);
|
|
705
|
+
assert.deepEqual(layoutPosts(canvas).at(-1)!.body, { arrangement: "grid", positions: positionsOf(grid) });
|
|
706
|
+
// Column: one above the other, left-aligned.
|
|
707
|
+
await arrange("gd-arrange-column");
|
|
708
|
+
const column = [[0, 0], [0, 680], [0, 1060], [0, 1640], [0, 1820]];
|
|
709
|
+
assert.deepEqual(canvas.world.children.map(placed), column.map(([x, y]) => [`${x}px`, `${y}px`]));
|
|
710
|
+
assert.deepEqual(worldBox(canvas), ["800px", "2020px"]);
|
|
711
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"]);
|
|
712
|
+
assert.deepEqual(layoutPosts(canvas).at(-1)!.body, { arrangement: "column", positions: positionsOf(column) });
|
|
713
|
+
// Fit shows the whole column: 604 / 2020 of the 700 px viewport, 48 px from the top.
|
|
714
|
+
assert.equal(canvas.zoomLevel.textContent, "30%");
|
|
715
|
+
assert.match(canvas.world.style.transform, /^translate\([\d.]+px, 48px\) scale\(0\.29900990099/);
|
|
716
|
+
// Row: side by side, top-aligned.
|
|
717
|
+
await arrange("gd-arrange-row");
|
|
718
|
+
const row = [[0, 0], [880, 0], [1360, 0], [1640, 0], [2020, 0]];
|
|
719
|
+
assert.deepEqual(canvas.world.children.map(placed), row.map(([x, y]) => [`${x}px`, `${y}px`]));
|
|
720
|
+
assert.deepEqual(layoutPosts(canvas).at(-1)!.body, { arrangement: "row", positions: positionsOf(row) });
|
|
721
|
+
assert.equal(layoutPosts(canvas).length, 3, "one save per choice");
|
|
722
|
+
// After an arrangement each artboard can still be moved by hand: the layout becomes free and the others stay.
|
|
723
|
+
await arrange("gd-arrange-column");
|
|
724
|
+
await dragFrom(boardTitle(canvas.world.children[2]), [300, 300], [[330, 300]]);
|
|
725
|
+
assert.deepEqual(layoutPosts(canvas).at(-1)!.body, { arrangement: "free", positions: positionsOf([[0, 0], [0, 680], [100, 1060], [0, 1640], [0, 1820]]) });
|
|
726
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "false", "false"]);
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
test("a handoff that grows the artboard labels after they were placed lays the arrangement out again; a free layout keeps its positions", async () => {
|
|
730
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout: { arrangement: "column", positions: {} } } });
|
|
731
|
+
// Like the browser: the handoff row in an artboard's header (.gd-has-handoff) pushes its frame box 30 px down.
|
|
732
|
+
for (const board of canvas.boards) Object.defineProperty(board.frame.parentElement!, "offsetTop", { get: () => (board.wrapper.classes.has("gd-has-handoff") ? 50 : 20) });
|
|
733
|
+
await setHandoffs(canvas, handoffDoc("01-a.html", { "01-a.html": {} }));
|
|
734
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "430px"]], "80 px below the grown first artboard");
|
|
735
|
+
assert.deepEqual(worldBox(canvas), ["400px", "780px"]);
|
|
736
|
+
assert.deepEqual(canvas.posts, [], "laid out again, not saved");
|
|
737
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
738
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 500], [[540, 500]]);
|
|
739
|
+
await setHandoffs(canvas, handoffDoc(null, {}));
|
|
740
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["40px", "430px"]], "a free layout stays where it was put");
|
|
741
|
+
assert.deepEqual(worldBox(canvas), ["440px", "750px"], "and the world follows the smaller labels");
|
|
742
|
+
assert.equal(layoutPosts(canvas).length, 1);
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
test("a handoff that grows the labels while an artboard is in use keeps that artboard where it was on screen", async () => {
|
|
746
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout: { arrangement: "column", positions: {} } } });
|
|
747
|
+
// Like the browser: an artboard sits at its position and the handoff row pushes its frame box 30 px down.
|
|
748
|
+
for (const board of canvas.boards) {
|
|
749
|
+
Object.defineProperty(board.frame.parentElement!, "offsetTop", { get: () => (board.wrapper.classes.has("gd-has-handoff") ? 50 : 20) });
|
|
750
|
+
Object.defineProperty(board.wrapper, "offsetTop", { get: () => Number.parseFloat(board.wrapper.style.top) });
|
|
751
|
+
}
|
|
752
|
+
const [, second] = canvas.boards;
|
|
753
|
+
const frameTop = () => translation(canvas)[1] + Number.parseFloat(second.wrapper.style.top) + second.frame.parentElement!.offsetTop;
|
|
754
|
+
click(second.shield!, 200, 200);
|
|
755
|
+
assert.match(canvas.navMode.textContent, /^Using: Second/);
|
|
756
|
+
const onScreen = frameTop();
|
|
757
|
+
await setHandoffs(canvas, handoffDoc("01-a.html", { "01-a.html": {} }));
|
|
758
|
+
assert.deepEqual(placed(second.wrapper), ["0px", "430px"], "the column is laid out again below the grown first artboard");
|
|
759
|
+
assert.equal(frameTop(), onScreen, "the artboard in use stays put on screen");
|
|
760
|
+
assert.deepEqual(canvas.posts, []);
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
test("the arrangement buttons are off without a design, in focus mode and in Compare", async () => {
|
|
764
|
+
const empty = await loadLayout({ "/t/api/designs": { designs: [] }, ...SYSTEM_REPLY }, { slug: null });
|
|
765
|
+
assert.ok(ARRANGE_IDS.every((id) => empty.document.getElementById(id).disabled), "the system-only view has nothing to arrange");
|
|
766
|
+
const canvas = await loadLayout({ ...NO_LAYOUT, "/t/api/designs/alpha/handoffs": { version: 1, chosen: "01-a.html", handoffs: { "01-a.html": { status: "implemented", queued: false, sentAt: "2026-10-26T10:00:00.000Z", startedAt: null, implementedAt: null, previewUrl: "http://localhost:5173/login" } } } });
|
|
767
|
+
assert.ok(ARRANGE_IDS.every((id) => !canvas.document.getElementById(id).disabled));
|
|
768
|
+
withClass(canvas.world.children[0], "gd-compare-start")[0].dispatch("click");
|
|
769
|
+
assert.ok(ARRANGE_IDS.every((id) => canvas.document.getElementById(id).disabled), "Compare covers the canvas");
|
|
770
|
+
canvas.document.getElementById("gd-compare-back").dispatch("click");
|
|
771
|
+
assert.ok(ARRANGE_IDS.every((id) => !canvas.document.getElementById(id).disabled));
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
// ---- focus mode and the view (S3: store mutators only)
|
|
775
|
+
|
|
776
|
+
test("focus mode centers a moved artboard from where it sits", async () => {
|
|
777
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout: { arrangement: "free", positions: { "01-a.html": { x: 0, y: 0 }, "02-b.html": { x: 600, y: 900 } } } } });
|
|
778
|
+
const [, second] = canvas.boards;
|
|
779
|
+
assert.deepEqual(placed(second.wrapper), ["600px", "900px"]);
|
|
780
|
+
// The browser lays an absolutely placed artboard out at its position; its frame box sits under the label, inside it.
|
|
781
|
+
second.wrapper.offsetLeft = 600;
|
|
782
|
+
second.wrapper.offsetTop = 900;
|
|
783
|
+
second.frame.parentElement!.offsetTop = 20;
|
|
784
|
+
click(second.shield!, 200, 200);
|
|
785
|
+
// Desktop fills the 1000 px viewport less its 8 px margins, so x is the left margin: 8 - 600; y centers its 300 px below
|
|
786
|
+
// the 8 px margin and the label: 200 - 920.
|
|
787
|
+
assert.equal(canvas.world.style.transform, "translate(-592px, -720px) scale(1)");
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
test("a layout change while an artboard is in use shifts the view to restore, so Back to canvas shows the boards where they were", async () => {
|
|
791
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
792
|
+
const [first] = canvas.boards;
|
|
793
|
+
assert.equal(canvas.world.style.transform, "translate(48px, 48px) scale(1)");
|
|
794
|
+
click(first.shield!, 200, 200);
|
|
795
|
+
assert.match(canvas.navMode.textContent, /^Using: First/);
|
|
796
|
+
// Another page put the first artboard 200 px left of and 100 px above the second: the bounds' top left moves.
|
|
797
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "free", positions: { "01-a.html": { x: -200, y: -100 }, "02-b.html": { x: 480, y: 0 } } } };
|
|
798
|
+
await canvas.serverEvent("change", { slug: "alpha", file: "layout.json" });
|
|
799
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["680px", "100px"]]);
|
|
800
|
+
assert.match(canvas.navMode.textContent, /^Using: First/, "focus mode stays");
|
|
801
|
+
canvas.document.getElementById("gd-back").dispatch("click");
|
|
802
|
+
assert.equal(canvas.world.style.transform, "translate(-152px, -52px) scale(1)", "the saved view moved with the world");
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
test("no canvas module changes the view in place: zoom and pan go through the store's mutators", () => {
|
|
806
|
+
for (const name of Object.keys(DESIGN_CANVAS_ASSETS).filter((file) => file.startsWith("canvas-") && file.endsWith(".js"))) {
|
|
807
|
+
const source = read(name);
|
|
808
|
+
assert.ok(!/\b(?:state|view|savedView)\.(?:x|y|zoom|fitted)\s*(?:[-+*/]?=)(?!=)/.test(source), `${name} assigns no view field`);
|
|
809
|
+
assert.ok(!/Object\.assign\(\s*state\b/.test(source), `${name} does not assign into state`);
|
|
810
|
+
}
|
|
811
|
+
const layout = read("canvas-layout.js");
|
|
812
|
+
assert.match(layout, /store\.setView\(/, "the layout shifts the view through setView");
|
|
813
|
+
assert.match(layout, /store\.setFocus\(\{ savedView/, "and the view to restore through setFocus");
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
// ---- markup, styles and docs
|
|
817
|
+
|
|
818
|
+
test("the arrangement control sits in the top bar after the zoom, named in English, styled with tokens; boards are placed absolutely", () => {
|
|
819
|
+
const html = read("index.html");
|
|
820
|
+
const bar = html.slice(html.indexOf('<header class="gd-bar"'), html.indexOf("</header>"));
|
|
821
|
+
const group = /<div class="gd-group gd-arrange" role="group" aria-label="Arrange the artboards" data-i18n-aria-label="arrange">([^]*?)<\/div>/.exec(bar);
|
|
822
|
+
assert.ok(group, "a labelled group in the top bar");
|
|
823
|
+
for (const [kind, name] of [["row", "Row"], ["column", "Column"], ["grid", "Grid"]]) {
|
|
824
|
+
assert.match(group![1], new RegExp(`<button type="button" id="gd-arrange-${kind}" aria-pressed="${kind === "row"}" aria-label="${name}" title="Arrange in a ${kind}" data-i18n-aria-label="${kind}" data-i18n-title="arrange${name}" disabled><svg class="gd-i" aria-hidden="true"><use href="#i-${kind}"/></svg></button>`));
|
|
825
|
+
assert.match(html, new RegExp(`<symbol id="i-${kind}" viewBox="0 0 24 24">`));
|
|
826
|
+
}
|
|
827
|
+
assert.ok(bar.indexOf('aria-label="Zoom"') < bar.indexOf("gd-arrange") && bar.indexOf("gd-arrange") < bar.indexOf('id="gd-nav-mode"'), "after the zoom, before the mode label");
|
|
828
|
+
const css = read("canvas.css");
|
|
829
|
+
const pressed = /\.gd-arrange button\[aria-pressed="true"\]\s*{([^}]*)}/.exec(css);
|
|
830
|
+
assert.ok(pressed && /var\(--gd-/.test(pressed[1]) && !/#[0-9a-fA-F]{3,8}\b|rgba?\(/.test(pressed[1]), "the chosen arrangement shows, in tokens");
|
|
831
|
+
assert.match(css, /\.gd-world \.gd-artboard\s*{[^}]*position:\s*absolute/, "artboards sit where the layout puts them");
|
|
832
|
+
const world = /\n\.gd-world\s*{([^}]*)}/.exec(css)![1];
|
|
833
|
+
assert.ok(!/display:\s*flex|gap:/.test(world), "the world is no longer a flex row");
|
|
834
|
+
assert.match(css, /\.gd-viewport\.gd-moving, \.gd-viewport\.gd-moving \* \{ cursor: grabbing; \}/);
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
test("the shortcuts list names Space + drag and Esc clears the selection, and the docs describe the layout", () => {
|
|
838
|
+
const html = read("index.html");
|
|
839
|
+
const dialog = html.slice(html.indexOf('<dialog id="gd-shortcuts"'), html.indexOf("</dialog>"));
|
|
840
|
+
assert.match(dialog, /<dt><kbd data-i18n="space">Space<\/kbd> \+ <span data-i18n="drag">drag<\/span><\/dt><dd data-i18n="panAnywhere">Pan from anywhere, even over an artboard<\/dd>/);
|
|
841
|
+
assert.ok(dialog.indexOf("↓") < dialog.indexOf(">Space</kbd>") && dialog.indexOf(">Space</kbd>") < dialog.indexOf("<dt><kbd>Esc</kbd></dt>"), "after the arrow keys");
|
|
842
|
+
assert.match(dialog, /<dt><kbd>Esc<\/kbd><\/dt><dd data-i18n="escape">[^<]*selected artboard[^<]*<\/dd>/);
|
|
843
|
+
const docs = readFileSync(fileURLToPath(new URL("../docs/gentle-shell.md", import.meta.url)), "utf8");
|
|
844
|
+
const section = docs.slice(docs.indexOf("### Gentle Design"));
|
|
845
|
+
const start = section.indexOf("- **Layout**");
|
|
846
|
+
assert.ok(start >= 0, "a Layout entry");
|
|
847
|
+
const layout = section.slice(start, section.indexOf("\n", start));
|
|
848
|
+
for (const part of ["any part of it", "`Space`", "selected", "empty canvas", "**Row**", "**Column**", "**Grid**", "`design/<slug>/layout.json`", "Comment mode"]) assert.ok(layout.includes(part), `the Layout entry mentions ${part}`);
|
|
849
|
+
assert.ok(!section.includes("drag always pan or zoom the canvas, even over an artboard"), "the old gesture is gone");
|
|
850
|
+
assert.ok(!section.includes("pan by dragging or scrolling"));
|
|
851
|
+
});
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
// ---- CodeRabbit round 2: reads, saves and moves that cross a reload, a design switch or the system-only view
|
|
855
|
+
|
|
856
|
+
const DESIGN_CHANGE = { slug: "alpha", file: "design.json" };
|
|
857
|
+
/** A pointer event on the viewport, which holds the pointer capture once a press began. */
|
|
858
|
+
const onViewport = (canvas: Canvas, type: string, x: number, y: number) => canvas.viewport.dispatch(type, { button: 0, pointerId: 3, clientX: x, clientY: y });
|
|
859
|
+
|
|
860
|
+
test("a design.json reload whose layout read went out during a save and answers after the save succeeded never rolls the move back", async () => {
|
|
861
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
862
|
+
const save = deferred();
|
|
863
|
+
canvas.replies[LAYOUT_URL] = save.promise;
|
|
864
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
865
|
+
const read = deferred();
|
|
866
|
+
canvas.replies[LAYOUT_URL] = read.promise;
|
|
867
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
868
|
+
save.resolve({ ok: true });
|
|
869
|
+
await settle();
|
|
870
|
+
read.resolve({ layout: null });
|
|
871
|
+
await settle();
|
|
872
|
+
await settle();
|
|
873
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "0px"]], "the read of the file from before the save is dropped");
|
|
874
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "false", "false"]);
|
|
875
|
+
assert.equal(layoutPosts(canvas).length, 1);
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
test("another page's layout.json change whose read a failed save made stale is read again once the save fails", async () => {
|
|
879
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout: { arrangement: "column", positions: {} } } });
|
|
880
|
+
const external = deferred();
|
|
881
|
+
canvas.replies[LAYOUT_URL] = external.promise;
|
|
882
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
883
|
+
const save = deferred();
|
|
884
|
+
canvas.replies[LAYOUT_URL] = save.promise;
|
|
885
|
+
canvas.document.getElementById("gd-arrange-row").dispatch("click");
|
|
886
|
+
await settle();
|
|
887
|
+
// Another page wrote Grid; this page's Row is rejected.
|
|
888
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "grid", positions: {} } };
|
|
889
|
+
external.resolve({ layout: { arrangement: "grid", positions: {} } });
|
|
890
|
+
await settle();
|
|
891
|
+
save.resolve({ __http: 400, error: "invalid-layout", reason: "disk full" });
|
|
892
|
+
await settle();
|
|
893
|
+
await settle();
|
|
894
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "false", "true"], "the other page's grid shows");
|
|
895
|
+
assert.equal(layoutPosts(canvas).length, 1, "and nothing is saved back");
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
test("a move of the system board ends unsaved when the system-only view takes its layout away", async () => {
|
|
899
|
+
const canvas = await loadLayout({ ...SYSTEM_REPLY, ...NO_LAYOUT });
|
|
900
|
+
boardTitle(canvas.world.children[0]).dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 100, clientY: 100 });
|
|
901
|
+
onViewport(canvas, "pointermove", 140, 100);
|
|
902
|
+
await canvas.serverEvent("show", { slug: null });
|
|
903
|
+
await settle();
|
|
904
|
+
onViewport(canvas, "pointermove", 180, 100);
|
|
905
|
+
onViewport(canvas, "pointerup", 180, 100);
|
|
906
|
+
await settle();
|
|
907
|
+
assert.deepEqual(canvas.posts, [], "nothing is saved");
|
|
908
|
+
assert.equal(canvas.navMode.textContent, NAVIGATING);
|
|
909
|
+
});
|
|
910
|
+
|
|
911
|
+
test("a design.json reload during a move hands the move to the rebuilt artboard, saved once on release", async () => {
|
|
912
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
913
|
+
boardTitle(canvas.world.children[1]).dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 500, clientY: 100 });
|
|
914
|
+
onViewport(canvas, "pointermove", 540, 100);
|
|
915
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
916
|
+
await settle();
|
|
917
|
+
onViewport(canvas, "pointermove", 560, 100);
|
|
918
|
+
assert.deepEqual(placed(canvas.world.children[1]), ["540px", "0px"], "the rebuilt artboard follows the pointer");
|
|
919
|
+
onViewport(canvas, "pointerup", 560, 100);
|
|
920
|
+
await settle();
|
|
921
|
+
assert.deepEqual(layoutPosts(canvas).map((post) => post.body), [{ arrangement: "free", positions: { "01-a.html": { x: 0, y: 0 }, "02-b.html": { x: 540, y: 0 } } }]);
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
test("a design.json reload during a move in an arrangement keeps the dragged position, saved on a release without another move", async () => {
|
|
925
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
926
|
+
boardTitle(canvas.world.children[1]).dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 500, clientY: 100 });
|
|
927
|
+
onViewport(canvas, "pointermove", 540, 100);
|
|
928
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
929
|
+
await settle();
|
|
930
|
+
assert.deepEqual(placed(canvas.world.children[1]), ["520px", "0px"], "the rebuilt artboard stays where it was dragged");
|
|
931
|
+
onViewport(canvas, "pointerup", 540, 100);
|
|
932
|
+
await settle();
|
|
933
|
+
assert.deepEqual(layoutPosts(canvas).map((post) => post.body), [{ arrangement: "free", positions: { "01-a.html": { x: 0, y: 0 }, "02-b.html": { x: 520, y: 0 } } }]);
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
test("a move of the system board across a design switch is cancelled and never written to the next design's layout.json", async () => {
|
|
937
|
+
const BETA_LAYOUT = "/t/api/designs/beta/layout";
|
|
938
|
+
const canvas = await loadLayout({ ...SYSTEM_REPLY, ...NO_LAYOUT });
|
|
939
|
+
const betaManifest = deferred();
|
|
940
|
+
const beta = canvas.replies["/t/api/designs/beta"];
|
|
941
|
+
canvas.replies["/t/api/designs/beta"] = betaManifest.promise;
|
|
942
|
+
canvas.replies[BETA_LAYOUT] = { layout: null };
|
|
943
|
+
const select = canvas.document.getElementById("gd-design");
|
|
944
|
+
select.value = "beta";
|
|
945
|
+
select.dispatch("change");
|
|
946
|
+
boardTitle(canvas.world.children[0]).dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 100, clientY: 100 });
|
|
947
|
+
onViewport(canvas, "pointermove", 160, 100);
|
|
948
|
+
betaManifest.resolve(beta);
|
|
949
|
+
await settle();
|
|
950
|
+
onViewport(canvas, "pointermove", 200, 100);
|
|
951
|
+
onViewport(canvas, "pointerup", 200, 100);
|
|
952
|
+
await settle();
|
|
953
|
+
assert.deepEqual(canvas.posts.map((post) => post.url), [], "nothing is saved, to alpha or beta");
|
|
954
|
+
});
|
|
955
|
+
|
|
956
|
+
test("a still press on an artboard that a design.json reload replaced opens nothing on release", async () => {
|
|
957
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
958
|
+
withClass(canvas.world.children[1], "gd-shield")[0].dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 500, clientY: 300 });
|
|
959
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
960
|
+
await settle();
|
|
961
|
+
onViewport(canvas, "pointerup", 500, 300);
|
|
962
|
+
await settle();
|
|
963
|
+
assert.equal(canvas.navMode.textContent, NAVIGATING, "no detached artboard is opened");
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
test("a failed design load that answers after the system-only view showed leaves that view alone", async () => {
|
|
967
|
+
const canvas = await loadLayout({ ...SYSTEM_REPLY, ...NO_LAYOUT });
|
|
968
|
+
const manifest = deferred();
|
|
969
|
+
canvas.replies["/t/api/designs/alpha"] = manifest.promise;
|
|
970
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
971
|
+
await canvas.serverEvent("show", { slug: null });
|
|
972
|
+
await settle();
|
|
973
|
+
assert.equal(canvas.world.children.length, 1, "the system board shows");
|
|
974
|
+
manifest.resolve({ __http: 500 });
|
|
975
|
+
await settle();
|
|
976
|
+
assert.equal(canvas.world.children.length, 1, "it still shows");
|
|
977
|
+
assert.ok(!canvas.document.getElementById("gd-status").classes.has("gd-error"), "and no design error is reported");
|
|
978
|
+
});
|
|
979
|
+
|
|
980
|
+
// ---- egdev6's review of #3146: the layout errors in the status line, Space on an arrangement button, nothing to arrange
|
|
981
|
+
|
|
982
|
+
/** The reply of the canvas server's GET layout route for a layout.json it cannot read or use (canvas-layout S17). */
|
|
983
|
+
const UNREADABLE = { __http: 422, error: "unreadable-layout", reason: "not valid JSON" };
|
|
984
|
+
const READ_FAILED = "design/alpha/layout.json could not be read: not valid JSON";
|
|
985
|
+
|
|
986
|
+
test("a layout.json the server cannot read keeps the layout shown, says so in the status line and saves nothing, until a read that answers", async () => {
|
|
987
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
988
|
+
const status = canvas.document.getElementById("gd-status");
|
|
989
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
990
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
991
|
+
assert.equal(layoutPosts(canvas).length, 1, "the free layout is saved");
|
|
992
|
+
const free = [["0px", "0px"], ["520px", "0px"]];
|
|
993
|
+
canvas.replies[LAYOUT_URL] = UNREADABLE;
|
|
994
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
995
|
+
assert.deepEqual(canvas.world.children.map(placed), free, "a layout.json change that cannot be read is no row");
|
|
996
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "false", "false"]);
|
|
997
|
+
assert.equal(status.textContent, READ_FAILED);
|
|
998
|
+
assert.ok(status.classes.has("gd-error"));
|
|
999
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
1000
|
+
await settle();
|
|
1001
|
+
assert.deepEqual(canvas.world.children.map(placed), free, "nor is a design.json reload's read of it");
|
|
1002
|
+
assert.equal(status.textContent, READ_FAILED, "and the reload still says so");
|
|
1003
|
+
assert.ok(status.classes.has("gd-error"));
|
|
1004
|
+
assert.equal(layoutPosts(canvas).length, 1, "nothing is saved over the file");
|
|
1005
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "column", positions: {} } };
|
|
1006
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
1007
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "a read that answers shows the file again");
|
|
1008
|
+
assert.equal(status.textContent, "", "and clears the read error");
|
|
1009
|
+
assert.equal(status.classes.has("gd-error"), false);
|
|
1010
|
+
assert.equal(layoutPosts(canvas).length, 1);
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
test("a design opened while its layout.json cannot be read sits in a row, says so, and saves nothing", async () => {
|
|
1014
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: UNREADABLE });
|
|
1015
|
+
const status = canvas.document.getElementById("gd-status");
|
|
1016
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]]);
|
|
1017
|
+
assert.equal(status.textContent, READ_FAILED);
|
|
1018
|
+
assert.ok(status.classes.has("gd-error"));
|
|
1019
|
+
assert.deepEqual(canvas.posts, []);
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
test("a failed save stays in the status line across a design.json reload while the layout is unsaved; a later save clears it", async () => {
|
|
1023
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
1024
|
+
const status = canvas.document.getElementById("gd-status");
|
|
1025
|
+
canvas.replies[LAYOUT_URL] = { __http: 400, error: "invalid-layout", reason: "disk full" };
|
|
1026
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
1027
|
+
assert.equal(status.textContent, "The layout of alpha could not be saved: disk full");
|
|
1028
|
+
// The file still holds no layout: the reload keeps the unsaved move, and its error.
|
|
1029
|
+
canvas.replies[LAYOUT_URL] = { layout: null };
|
|
1030
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
1031
|
+
await settle();
|
|
1032
|
+
assert.deepEqual(placed(canvas.world.children[1]), ["520px", "0px"], "the unsaved move stays");
|
|
1033
|
+
assert.equal(status.textContent, "The layout of alpha could not be saved: disk full", "the reload does not hide the failed save");
|
|
1034
|
+
assert.ok(status.classes.has("gd-error"));
|
|
1035
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
1036
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [540, 100], [[560, 100]]);
|
|
1037
|
+
assert.equal(status.textContent, "", "a save that succeeds clears it");
|
|
1038
|
+
assert.equal(status.classes.has("gd-error"), false);
|
|
1039
|
+
canvas.replies[LAYOUT_URL] = { layout: layoutPosts(canvas).at(-1)!.body };
|
|
1040
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
1041
|
+
await settle();
|
|
1042
|
+
assert.equal(status.textContent, "", "and a reload after it shows no error");
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
test("Space held on an arrangement button just clicked pans instead of pressing it again; reached by the keyboard it keeps Space", async () => {
|
|
1046
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
1047
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
1048
|
+
const grid = canvas.document.getElementById("gd-arrange-grid");
|
|
1049
|
+
grid.focus();
|
|
1050
|
+
grid.dispatch("click");
|
|
1051
|
+
await settle();
|
|
1052
|
+
assert.equal(layoutPosts(canvas).length, 1, "Grid is saved");
|
|
1053
|
+
const [x, y] = translation(canvas);
|
|
1054
|
+
assert.equal(keyAt(canvas, "keydown", " ", grid).defaultPrevented, true, "Space does not press the button");
|
|
1055
|
+
assert.ok(canvas.viewport.classes.has("gd-space-pan"));
|
|
1056
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 60], [[540, 80]]);
|
|
1057
|
+
assert.deepEqual(translation(canvas), [x + 40, y + 20], "the drag pans");
|
|
1058
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], "and moves no artboard");
|
|
1059
|
+
assert.equal(keyAt(canvas, "keyup", " ", grid).defaultPrevented, true, "nor does its release");
|
|
1060
|
+
assert.ok(!canvas.viewport.classes.has("gd-space-pan"));
|
|
1061
|
+
assert.equal(layoutPosts(canvas).length, 1, "nothing more is saved");
|
|
1062
|
+
// A button reached with Tab shows its focus ring (:focus-visible): Space presses it, as on any button.
|
|
1063
|
+
grid.matches = (selector: string) => selector === ":focus-visible";
|
|
1064
|
+
assert.equal(keyAt(canvas, "keydown", " ", grid).defaultPrevented, false);
|
|
1065
|
+
assert.ok(!canvas.viewport.classes.has("gd-space-pan"));
|
|
1066
|
+
});
|
|
1067
|
+
|
|
1068
|
+
test("the arrangement buttons are off when no boards show: a design without artboards, or one whose design.json cannot be read", async () => {
|
|
1069
|
+
const off = (canvas: Canvas) => ARRANGE_IDS.map((id) => canvas.document.getElementById(id).disabled);
|
|
1070
|
+
const empty = await loadLayout({ ...NO_LAYOUT, "/t/api/designs/alpha": { slug: "alpha", title: "Alpha", brief: "", artboards: [] } });
|
|
1071
|
+
assert.deepEqual(off(empty), [true, true, true], "a design without artboards");
|
|
1072
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
1073
|
+
assert.deepEqual(off(canvas), [false, false, false]);
|
|
1074
|
+
const manifest = canvas.replies["/t/api/designs/alpha"];
|
|
1075
|
+
canvas.replies["/t/api/designs/alpha"] = { __http: 422, error: "invalid-manifest", reason: "broken" };
|
|
1076
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
1077
|
+
await settle();
|
|
1078
|
+
assert.equal(canvas.world.children.length, 0, "no boards show");
|
|
1079
|
+
assert.deepEqual(off(canvas), [true, true, true], "a design.json that cannot be read");
|
|
1080
|
+
canvas.replies["/t/api/designs/alpha"] = manifest;
|
|
1081
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
1082
|
+
await settle();
|
|
1083
|
+
assert.deepEqual(off(canvas), [false, false, false], "they come back with the boards");
|
|
1084
|
+
});
|
|
1085
|
+
|
|
1086
|
+
test("a design.json reload still shows the manifest's warnings and the no-artboards notice; a standing save error comes first", async () => {
|
|
1087
|
+
const manifest = (artboards: unknown[], warnings?: string[]) => ({ slug: "alpha", title: "Alpha", brief: "", artboards, ...(warnings ? { warnings } : {}) });
|
|
1088
|
+
const two = [{ file: "01-a.html", title: "First", tradeoff: "", width: 400, height: 300 }, { file: "02-b.html", title: "Second", tradeoff: "", width: 400, height: 300 }];
|
|
1089
|
+
const canvas = await loadLayout({ ...SYSTEM_REPLY, ...NO_LAYOUT, "/t/api/designs/alpha": manifest(two, ["feature was ignored", "one more"]) });
|
|
1090
|
+
const status = canvas.document.getElementById("gd-status");
|
|
1091
|
+
assert.equal(status.textContent, "design.json: feature was ignored; one more");
|
|
1092
|
+
assert.ok(status.classes.has("gd-error"));
|
|
1093
|
+
canvas.replies["/t/api/designs/alpha"] = manifest([]);
|
|
1094
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
1095
|
+
await settle();
|
|
1096
|
+
assert.equal(status.textContent, "This design has no artboards yet.", "the system board shows alone");
|
|
1097
|
+
assert.equal(status.classes.has("gd-error"), false);
|
|
1098
|
+
canvas.replies["/t/api/designs/alpha"] = manifest(two, ["feature was ignored"]);
|
|
1099
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
1100
|
+
await settle();
|
|
1101
|
+
canvas.replies[LAYOUT_URL] = { __http: 400, error: "invalid-layout", reason: "disk full" };
|
|
1102
|
+
await dragFrom(boardTitle(canvas.world.children[2]), [1400, 100], [[1440, 100]]);
|
|
1103
|
+
canvas.replies[LAYOUT_URL] = { layout: null };
|
|
1104
|
+
await canvas.serverEvent("change", DESIGN_CHANGE);
|
|
1105
|
+
await settle();
|
|
1106
|
+
assert.equal(status.textContent, "The layout of alpha could not be saved: disk full; design.json: feature was ignored");
|
|
1107
|
+
assert.ok(status.classes.has("gd-error"));
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
test("a layout read that fails for another reason than an unreadable layout.json (an HTTP error, no connection) keeps the layout and says nothing", async () => {
|
|
1111
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout: { arrangement: "column", positions: {} } } });
|
|
1112
|
+
const status = canvas.document.getElementById("gd-status");
|
|
1113
|
+
for (const reply of [{ __http: 500 }, { __http: 404 }, { __throw: "offline" }]) {
|
|
1114
|
+
canvas.replies[LAYOUT_URL] = reply;
|
|
1115
|
+
await canvas.serverEvent("change", { slug: "alpha", file: "design.json" });
|
|
1116
|
+
await settle();
|
|
1117
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"], `the column stays (${JSON.stringify(reply)})`);
|
|
1118
|
+
assert.deepEqual([status.textContent, status.classes.has("gd-error")], ["", false], `nothing in the status line (${JSON.stringify(reply)})`);
|
|
1119
|
+
}
|
|
1120
|
+
assert.deepEqual(canvas.posts, []);
|
|
1121
|
+
});
|
|
1122
|
+
|
|
1123
|
+
// ---- egdev6's second review of #3146: a lost pointer capture, and no saves while layout.json cannot be used
|
|
1124
|
+
|
|
1125
|
+
test("a move whose pointer capture is lost puts the artboard back unsaved, and the next press on the empty canvas pans", async () => {
|
|
1126
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
1127
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
1128
|
+
boardTitle(canvas.world.children[1]).dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 500, clientY: 100 });
|
|
1129
|
+
onViewport(canvas, "pointermove", 560, 100);
|
|
1130
|
+
assert.deepEqual(placed(canvas.world.children[1]), ["540px", "0px"], "the artboard follows the pointer");
|
|
1131
|
+
onViewport(canvas, "lostpointercapture", 560, 100);
|
|
1132
|
+
await settle();
|
|
1133
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], "the artboard goes back");
|
|
1134
|
+
assert.equal(canvas.viewport.classes.has("gd-moving"), false, "the grabbing cursor goes");
|
|
1135
|
+
assert.deepEqual(canvas.posts, [], "nothing is saved");
|
|
1136
|
+
const [x, y] = translation(canvas);
|
|
1137
|
+
await dragFrom(canvas.viewport, [900, 600], [[940, 620]]);
|
|
1138
|
+
assert.deepEqual(translation(canvas), [x + 40, y + 20], "a new press on the empty canvas pans");
|
|
1139
|
+
assert.deepEqual(canvas.posts, []);
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
test("a pan whose pointer capture is lost ends, so the next press works; a capture lost after the release changes nothing", async () => {
|
|
1143
|
+
const canvas = await loadLayout(NO_LAYOUT);
|
|
1144
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
1145
|
+
const [x, y] = translation(canvas);
|
|
1146
|
+
onViewport(canvas, "pointerdown", 900, 600);
|
|
1147
|
+
onViewport(canvas, "pointermove", 920, 600);
|
|
1148
|
+
onViewport(canvas, "lostpointercapture", 920, 600);
|
|
1149
|
+
assert.equal(canvas.viewport.classes.has("gd-panning"), false, "the pan ends");
|
|
1150
|
+
await dragFrom(canvas.viewport, [900, 600], [[900, 640]]);
|
|
1151
|
+
assert.deepEqual(translation(canvas), [x + 20, y + 40], "the next press pans");
|
|
1152
|
+
// The browser releases the capture after a pointerup too: that release has already saved the move once.
|
|
1153
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
1154
|
+
onViewport(canvas, "lostpointercapture", 540, 100);
|
|
1155
|
+
await settle();
|
|
1156
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "0px"]], "the moved artboard stays");
|
|
1157
|
+
assert.deepEqual(layoutPosts(canvas).map((post) => post.body), [{ arrangement: "free", positions: { "01-a.html": { x: 0, y: 0 }, "02-b.html": { x: 520, y: 0 } } }]);
|
|
1158
|
+
});
|
|
1159
|
+
|
|
1160
|
+
test("while layout.json cannot be read, a move and Row/Column/Grid change only the view and save nothing; saves resume once it reads again", async () => {
|
|
1161
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: UNREADABLE });
|
|
1162
|
+
const status = canvas.document.getElementById("gd-status");
|
|
1163
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
1164
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "0px"]], "the artboard moves on screen");
|
|
1165
|
+
assert.deepEqual(canvas.posts, [], "nothing is saved over the file");
|
|
1166
|
+
assert.deepEqual([status.textContent, status.classes.has("gd-error")], [READ_FAILED, true], "the status line still says why");
|
|
1167
|
+
canvas.document.getElementById("gd-arrange-column").dispatch("click");
|
|
1168
|
+
await settle();
|
|
1169
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["0px", "380px"]], "Column arranges the boards on screen");
|
|
1170
|
+
assert.deepEqual(pressedArrangements(canvas), ["false", "true", "false"]);
|
|
1171
|
+
assert.deepEqual(canvas.posts, [], "and saves nothing");
|
|
1172
|
+
assert.deepEqual([status.textContent, status.classes.has("gd-error")], [READ_FAILED, true]);
|
|
1173
|
+
// The file can be read again: the next move is saved.
|
|
1174
|
+
canvas.replies[LAYOUT_URL] = { layout: { arrangement: "row", positions: {} } };
|
|
1175
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
1176
|
+
assert.deepEqual(pressedArrangements(canvas), ["true", "false", "false"], "the file's layout shows");
|
|
1177
|
+
assert.deepEqual([status.textContent, status.classes.has("gd-error")], ["", false]);
|
|
1178
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
1179
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
1180
|
+
assert.equal(layoutPosts(canvas).length, 1, "the move is saved");
|
|
1181
|
+
assert.equal((layoutPosts(canvas)[0].body as { arrangement: string }).arrangement, "free");
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1184
|
+
test("a layout.json missing again after it could not be read lets the page save once more", async () => {
|
|
1185
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: UNREADABLE });
|
|
1186
|
+
canvas.replies[LAYOUT_URL] = { layout: null };
|
|
1187
|
+
await canvas.serverEvent("change", LAYOUT_CHANGE);
|
|
1188
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
1189
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
1190
|
+
assert.deepEqual(layoutPosts(canvas).map((post) => post.body), [{ arrangement: "free", positions: { "01-a.html": { x: 0, y: 0 }, "02-b.html": { x: 520, y: 0 } } }]);
|
|
1191
|
+
});
|
|
1192
|
+
|
|
1193
|
+
test("a layout the page cannot use (a fraction, a position out of range) sits in a row, says so, and a move or an arrangement saves nothing", async () => {
|
|
1194
|
+
for (const position of [{ x: 1.5, y: 0 }, { x: 1e300, y: 0 }, { x: 0, y: -2_000_001 }]) {
|
|
1195
|
+
const label = JSON.stringify(position);
|
|
1196
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout: { arrangement: "free", positions: { "01-a.html": { x: 0, y: 0 }, "02-b.html": position } } } });
|
|
1197
|
+
const status = canvas.document.getElementById("gd-status");
|
|
1198
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["480px", "0px"]], label);
|
|
1199
|
+
const unusable = "design/alpha/layout.json could not be read: it holds no layout this page can use";
|
|
1200
|
+
assert.deepEqual([status.textContent, status.classes.has("gd-error")], [unusable, true], label);
|
|
1201
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
1202
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [500, 100], [[540, 100]]);
|
|
1203
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "0px"], ["520px", "0px"]], `${label}: the move shows`);
|
|
1204
|
+
canvas.document.getElementById("gd-arrange-column").dispatch("click");
|
|
1205
|
+
await settle();
|
|
1206
|
+
assert.deepEqual(canvas.posts, [], `${label}: nothing is saved`);
|
|
1207
|
+
assert.equal(status.textContent, unusable, label);
|
|
1208
|
+
}
|
|
1209
|
+
// The farthest position the server accepts is one the page uses too.
|
|
1210
|
+
const edge = await loadLayout({ [LAYOUT_URL]: { layout: { arrangement: "free", positions: { "01-a.html": { x: 0, y: 0 }, "02-b.html": { x: 2_000_000, y: 0 } } } } });
|
|
1211
|
+
assert.deepEqual(edge.world.children.map(placed), [["0px", "0px"], ["2000000px", "0px"]]);
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
test("a __proto__ key in a saved layout is an unknown board like any other: it changes no prototype and drops out of the next save", async () => {
|
|
1215
|
+
const layout = JSON.parse('{"arrangement":"free","positions":{"__proto__":{"x":7,"y":9},"01-a.html":{"x":0,"y":500},"02-b.html":{"x":600,"y":0}}}');
|
|
1216
|
+
const canvas = await loadLayout({ [LAYOUT_URL]: { layout } });
|
|
1217
|
+
assert.deepEqual(canvas.world.children.map(placed), [["0px", "500px"], ["600px", "0px"]]);
|
|
1218
|
+
assert.equal((Object.prototype as Record<string, unknown>).x, undefined, "Object.prototype is untouched");
|
|
1219
|
+
canvas.replies[LAYOUT_URL] = { ok: true };
|
|
1220
|
+
await dragFrom(boardTitle(canvas.world.children[1]), [700, 100], [[740, 100]]);
|
|
1221
|
+
assert.deepEqual(layoutPosts(canvas).map((post) => JSON.stringify(post.body)), [JSON.stringify({ arrangement: "free", positions: { "01-a.html": { x: 0, y: 500 }, "02-b.html": { x: 640, y: 0 } } })]);
|
|
1222
|
+
});
|