forge
Explore
Log in

Don't you dare go Hollow

the file box takes a dropped hand: dragover on the upload label claims a files drag and wears the accent state, dragleave strips it only when the pointer leaves the box, and a drop hands its files to the input and fires the change the picker would — so the drop rides the same label, requestSubmit and multipart XHR path the picker does, progress bar and cancel and nav guard alike, and a drop while an upload runs is swallowed; the class is the client's own and registers through __izOwn so the live refresh keeps it, and the browser pass drives real DataTransfer events through the mark, the unmark and a two-file drop to chips

Browse files at this commit

0585aa5da8076e24b5b96b4e1cdec9d8e4508429Ahmet Kaan GümüşParent: 29cf541
crates/iz-web/src/layout.rsmodified+22 -0
@@ -670,6 +670,28 @@ pub async fn soft_nav_script(cx: &Cx) -> Result {
670 } \670 } \
671 if (control.hasAttribute && control.hasAttribute('data-autosubmit')) { control.form.requestSubmit(); } \671 if (control.hasAttribute && control.hasAttribute('data-autosubmit')) { control.form.requestSubmit(); } \
672 }); \672 }); \
673+ document.addEventListener('dragover', function (e) { \
674+ var box = e.target.closest ? e.target.closest('.file-upload-box') : null; \
675+ if (!box || !e.dataTransfer || e.dataTransfer.types.indexOf('Files') === -1) { return; } \
676+ e.preventDefault(); \
677+ e.dataTransfer.dropEffect = 'copy'; \
678+ window.__izOwn(box, ['file-upload-over'], []); \
679+ }); \
680+ document.addEventListener('dragleave', function (e) { \
681+ var box = e.target.closest ? e.target.closest('.file-upload-box') : null; \
682+ if (box && !box.contains(e.relatedTarget)) { box.classList.remove('file-upload-over'); } \
683+ }); \
684+ document.addEventListener('drop', function (e) { \
685+ var box = e.target.closest ? e.target.closest('.file-upload-box') : null; \
686+ if (!box) { return; } \
687+ e.preventDefault(); \
688+ box.classList.remove('file-upload-over'); \
689+ var input = box.querySelector('.file-upload-input'); \
690+ var form = input ? input.form : null; \
691+ if (!input || !form || form.__izUploading || !e.dataTransfer || !e.dataTransfer.files || e.dataTransfer.files.length === 0) { return; } \
692+ input.files = e.dataTransfer.files; \
693+ input.dispatchEvent(new Event('change', { bubbles: true })); \
694+ }); \
673 document.addEventListener('click', function (e) { \695 document.addEventListener('click', function (e) { \
674 var link = e.target.closest ? e.target.closest('a') : null; \696 var link = e.target.closest ? e.target.closest('a') : null; \
675 if (link) { \697 if (link) { \
crates/iz-web/tests/browser/drop.mjsadded+179 -0
@@ -0,0 +1,179 @@
1+// The drop hand: `tests/http.rs` can assert the shape of the served
2+// script, but no form post can produce a drag — only a browser builds a
3+// DataTransfer that carries real File objects, and only its events reach
4+// the delegated dragover/dragleave/drop listeners on the upload box.
5+// setInputFiles is no substitute either: it fills the input directly and
6+// never touches the drag path.
7+//
8+// Drives the task detail's file box end to end: dragover must mark the
9+// box, dragleave for the document body must unmark it, and a drop of two
10+// files must ride the same change -> requestSubmit -> multipart XHR path
11+// the picker uses — the landed chips are the proof, with zero page errors.
12+//
13+// Wants the server run.sh leaves behind, plus the session cookie it mints:
14+// IZ_SESSION_COOKIE carries the sealed token the fake im knows — the same
15+// minted session soft-nav runs on, so the owner is already provisioned.
16+// Standalone runs need it too: there is no form left to sign in through:
17+//
18+// node crates/iz-web/tests/browser/drop.mjs http://127.0.0.1:7791
19+//
20+// Playwright lives outside the repo, exactly as soft-nav.mjs says.
21+const { chromium } = await import(process.env.IZ_PLAYWRIGHT || 'playwright');
22+
23+const base = process.argv[2] || 'http://127.0.0.1:7791';
24+const shots = process.env.SHOT_DIR || '.';
25+const failures = [];
26+const note = (line) => console.log(line);
27+
28+const session = process.env.IZ_SESSION_COOKIE;
29+if (!session) {
30+ note('FAIL IZ_SESSION_COOKIE is empty — run through run.sh');
31+ process.exit(1);
32+}
33+
34+const browser = await chromium.launch();
35+const ctx = await browser.newContext();
36+await ctx.addCookies([{ name: 'iz_session', value: session, url: base }]);
37+const page = await ctx.newPage();
38+const errors = [];
39+page.on('pageerror', (e) => errors.push('PE ' + e.message));
40+page.on('console', (m) => {
41+ if (m.type() === 'error') errors.push('CON ' + m.text());
42+});
43+
44+await page.goto(base + '/', { waitUntil: 'networkidle' });
45+if (await page.locator('.board-stage').count() === 0) {
46+ failures.push(`signing in landed on ${page.url()} with no board`);
47+}
48+
49+// The task to drop onto, made the way a hand does: the new-task modal,
50+// server-rendered off /?new=1, submitted by its own button.
51+if (!failures.length) {
52+ await page.goto(base + '/?new=1', { waitUntil: 'networkidle' });
53+ await page.fill('.new-task-form input[name="title"]', 'Drop holds');
54+ await page.click('.new-task-form button[type="submit"]');
55+ const landed = await page
56+ .waitForFunction(
57+ () => !document.querySelector('.modal-new-task') && document.querySelector('.board-stage'),
58+ { timeout: 5000 },
59+ )
60+ .then(() => true)
61+ .catch(() => false);
62+ if (!landed) failures.push('the new task never landed on the board');
63+}
64+
65+// The card opens into the task detail, whose file box sits behind the
66+// Files tab — the modal lands on the Task tab, and the tab is a soft-nav
67+// link, so the box arrives on a second fetch-swap. Earlier scripts in the
68+// run leave their own cards behind, so take the first.
69+if (!failures.length) {
70+ await page.locator('.card-title').first().click();
71+ const tabsThere = await page
72+ .waitForFunction(() => document.querySelector('.detail-tabs'), { timeout: 5000 })
73+ .then(() => true)
74+ .catch(() => false);
75+ if (!tabsThere) {
76+ failures.push(`the task detail never showed its tabs at ${page.url()}`);
77+ } else {
78+ await page.locator('a.detail-tab[href$="tab=files"]').click();
79+ const boxThere = await page
80+ .waitForFunction(() => document.querySelector('.file-upload-box'), { timeout: 10000 })
81+ .then(() => true)
82+ .catch(() => false);
83+ if (!boxThere) failures.push(`the Files tab never showed the file box at ${page.url()}`);
84+ }
85+}
86+
87+// The hover mark: a dragover carrying real files must paint the box —
88+// the one state the picker's change path can never reach.
89+if (!failures.length) {
90+ const over = await page.evaluate(() => {
91+ const box = document.querySelector('.file-upload-box');
92+ if (!box) return null;
93+ const dt = new DataTransfer();
94+ dt.items.add(new File(['iz one'], 'dropped-a.txt', { type: 'text/plain' }));
95+ box.dispatchEvent(new DragEvent('dragover', { bubbles: true, cancelable: true, dataTransfer: dt }));
96+ return box.classList.contains('file-upload-over');
97+ });
98+ if (over !== true) {
99+ failures.push(`dragover never marked the box (over=${over})`);
100+ } else {
101+ // The class lands in one tick, and `color` has no transition —
102+ // the text wears the accent at once — while border-color rides
103+ // the ~150ms interpolation. Equality is the settled paint: poll
104+ // for the border reaching the accent the text already wears.
105+ const painted = await page
106+ .waitForFunction(
107+ () => {
108+ const b = document.querySelector('.file-upload-box');
109+ if (!b) {
110+ return false;
111+ }
112+ const cs = getComputedStyle(b);
113+ return cs.borderColor === cs.color;
114+ },
115+ { timeout: 3000 },
116+ )
117+ .then(() => true)
118+ .catch(() => false);
119+ if (!painted) failures.push('dragover never repainted the box border');
120+ else await page.screenshot({ path: `${shots}/drop-hover.png` });
121+ }
122+}
123+
124+// Leaving for the body — outside the box — must strip the mark; only a
125+// relatedTarget still inside the box would rightly keep it.
126+if (!failures.length) {
127+ const gone = await page.evaluate(() => {
128+ const box = document.querySelector('.file-upload-box');
129+ if (!box) return null;
130+ const dt = new DataTransfer();
131+ box.dispatchEvent(new DragEvent('dragleave', {
132+ bubbles: true, cancelable: true, dataTransfer: dt, relatedTarget: document.body,
133+ }));
134+ return box.classList.contains('file-upload-over');
135+ });
136+ if (gone !== false) failures.push(`dragleave from outside never unmarked the box (over=${gone})`);
137+}
138+
139+// The drop itself: two real files into the box, riding the change ->
140+// requestSubmit -> multipart XHR path. The chips are the proof the upload
141+// ran and the detail swapped them in — network work, not a repaint, hence
142+// the long wait.
143+if (!failures.length) {
144+ await page.evaluate(() => {
145+ const box = document.querySelector('.file-upload-box');
146+ const dt = new DataTransfer();
147+ dt.items.add(new File(['iz one'], 'dropped-a.txt', { type: 'text/plain' }));
148+ dt.items.add(new File(['iz two'], 'dropped-b.txt', { type: 'text/plain' }));
149+ box.dispatchEvent(new DragEvent('drop', { bubbles: true, cancelable: true, dataTransfer: dt }));
150+ });
151+ const dropped = await page
152+ .waitForFunction(
153+ () => {
154+ const names = [...document.querySelectorAll('.file-chip-name')]
155+ .map((el) => el.textContent.trim()).sort();
156+ return names.length === 2 && names[0] === 'dropped-a.txt' && names[1] === 'dropped-b.txt';
157+ },
158+ { timeout: 10000 },
159+ )
160+ .then(() => true)
161+ .catch(() => false);
162+ if (!dropped) {
163+ const chips = await page.evaluate(() =>
164+ [...document.querySelectorAll('.file-chip-name')].map((el) => el.textContent.trim()));
165+ failures.push(`the dropped files never landed as chips — chips: ${chips.join(' | ')}`);
166+ } else {
167+ await page.screenshot({ path: `${shots}/drop-landed.png` });
168+ }
169+}
170+
171+await browser.close();
172+
173+note(`page errors ${errors.length ? errors.join(' | ') : 'none'}`);
174+if (errors.length) failures.push(`page errors: ${errors.join(' | ')}`);
175+if (failures.length) {
176+ for (const f of failures) note('FAIL ' + f);
177+ process.exit(1);
178+}
179+note('PASS the drop rides the real upload path: dragover marked the box, dragleave unmarked it, and both dropped files landed as chips');
crates/iz-web/tests/browser/run.shmodified+4 -0
@@ -115,3 +115,7 @@ SHOT_DIR="$shots" node "$repo/crates/iz-web/tests/browser/moment.mjs" "http://12
115 # The avatar proxy's own pass, same minted session and owner as the moment115 # The avatar proxy's own pass, same minted session and owner as the moment
116 # field. Either script failing fails the run.116 # field. Either script failing fails the run.
117 SHOT_DIR="$shots" node "$repo/crates/iz-web/tests/browser/photo.mjs" "http://127.0.0.1:$port"117 SHOT_DIR="$shots" node "$repo/crates/iz-web/tests/browser/photo.mjs" "http://127.0.0.1:$port"
118+
119+# The file drop's own pass, same minted session and owner as the avatar
120+# proxy. Either script failing fails the run.
121+SHOT_DIR="$shots" node "$repo/crates/iz-web/tests/browser/drop.mjs" "http://127.0.0.1:$port"
style/main.scssmodified+2 -0
@@ -2728,6 +2728,8 @@ img.avatar {
2728 cursor: pointer;2728 cursor: pointer;
2729 2729
2730 &:hover { border-color: var(--accent); }2730 &:hover { border-color: var(--accent); }
2731+ // A drag parked over the box wears the same accent as `:hover`.
2732+ &.file-upload-over { border-color: var(--accent); color: var(--accent); }
2731 2733
2732 &:has(.file-upload-input:focus-visible) {2734 &:has(.file-upload-input:focus-visible) {
2733 outline: 2px solid var(--accent);2735 outline: 2px solid var(--accent);