manual submission redesign phase G
This commit is contained in:
@@ -16,7 +16,7 @@ test("compass stays hidden until permission and a heading, then rotates and hide
|
||||
<button id="burst-stop" type="button"></button><p id="burst-error"></p>
|
||||
</form>
|
||||
<div id="manual-submission"></div>
|
||||
<div id="manual-compass" hidden><div id="manual-compass-rose"></div><span id="manual-compass-heading"></span></div>
|
||||
<div id="manual-compass-home"><div id="manual-compass" hidden><div id="manual-compass-rose"></div><span id="manual-compass-heading"></span></div></div>
|
||||
</body></html>`, { url: "https://example.test/" });
|
||||
const { window } = dom;
|
||||
Object.defineProperty(window, "isSecureContext", { value: true });
|
||||
@@ -24,8 +24,10 @@ test("compass stays hidden until permission and a heading, then rotates and hide
|
||||
class MockOrientation {}
|
||||
MockOrientation.requestPermission = () => new Promise((resolve) => { resolvePermission = resolve; });
|
||||
window.DeviceOrientationEvent = MockOrientation;
|
||||
const previous = Object.fromEntries(["window", "document", "navigator", "DeviceOrientationEvent"].map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)]));
|
||||
for (const [key, value] of Object.entries({ window, document: window.document, navigator: window.navigator, DeviceOrientationEvent: MockOrientation })) {
|
||||
let submissions = 0;
|
||||
window.htmx = { ajax: () => { submissions++; } };
|
||||
const previous = Object.fromEntries(["window", "document", "navigator", "DeviceOrientationEvent", "htmx", "DOMParser"].map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)]));
|
||||
for (const [key, value] of Object.entries({ window, document: window.document, navigator: window.navigator, DeviceOrientationEvent: MockOrientation, htmx: window.htmx, DOMParser: window.DOMParser })) {
|
||||
Object.defineProperty(globalThis, key, { configurable: true, writable: true, value });
|
||||
}
|
||||
try {
|
||||
@@ -51,6 +53,36 @@ test("compass stays hidden until permission and a heading, then rotates and hide
|
||||
assert.equal(window.document.querySelector("#manual-direction-degrees").value, "1");
|
||||
button.click();
|
||||
assert.equal(compass.hidden, true);
|
||||
window.document.querySelector("#manual-increase").click();
|
||||
assert.equal(window.document.querySelector("#manual-occurrences").value, "2");
|
||||
window.document.querySelector("#manual-decrease").click();
|
||||
assert.equal(window.document.querySelector("#manual-occurrences").value, "1");
|
||||
|
||||
window.document.querySelector("#manual-direction-panel").outerHTML = '<div id="manual-direction-panel"><p class="manual-direction-panel__copy"></p><button id="manual-capture-direction"></button><div id="manual-direction-status"></div></div>';
|
||||
const opened = window.document.querySelector("#manual-direction-panel");
|
||||
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterSwap", { detail: { target: opened } }));
|
||||
assert.equal(compass.parentElement.id, "manual-direction-panel");
|
||||
window.document.body.dispatchEvent(new window.CustomEvent("htmx:beforeSwap", { detail: { target: opened } }));
|
||||
assert.equal(compass.parentElement.id, "manual-compass-home");
|
||||
opened.outerHTML = '<div id="manual-direction-panel"><p id="manual-direction-summary">Not captured</p></div>';
|
||||
const closed = window.document.querySelector("#manual-direction-panel");
|
||||
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterSwap", { detail: { target: closed } }));
|
||||
assert.equal(window.document.querySelector("#manual-direction-summary").textContent, "North · 1°");
|
||||
|
||||
const submit = window.document.querySelector("#manual-submit");
|
||||
const form = window.document.querySelector("#manual-report-form");
|
||||
submit.click();
|
||||
submit.click();
|
||||
assert.equal(submissions, 1);
|
||||
assert.equal(submit.disabled, true);
|
||||
window.document.querySelector("#manual-submission").outerHTML = '<div id="manual-submission" data-result="success">Received</div>';
|
||||
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterRequest", { detail: { elt: form, xhr: { status: 200 } } }));
|
||||
assert.equal(submit.disabled, false);
|
||||
submit.click();
|
||||
assert.equal(submissions, 2);
|
||||
window.document.body.dispatchEvent(new window.CustomEvent("htmx:afterRequest", { detail: { elt: form, xhr: { status: 400, responseText: '<div id="manual-submission" data-result="error">Try again</div>' } } }));
|
||||
assert.equal(window.document.querySelector("#manual-submission").dataset.result, "error");
|
||||
assert.equal(submit.disabled, false);
|
||||
} finally {
|
||||
for (const [key, descriptor] of Object.entries(previous)) {
|
||||
if (descriptor === undefined) delete globalThis[key];
|
||||
|
||||
Reference in New Issue
Block a user