sky.html: DEL btn at wheel center; async SAVE SKY transitions into saved state without reload; pre-save hides wheel-col so form+SAVE SKY stay centered — TDD
DEL btn (.btn-danger, "Forget sky?" data-confirm wired to the global #id_guard_portal) sits absolutely centered inside .sky-wheel-col; OK submits a POST to the new sky_delete view, which clears every sky_* field on the User model & redirects back to /dashboard/sky/.
The sky.html aperture is now uniform across saved/unsaved: form-col is always flex-column align-center justify-center so the fields + SAVE SKY pair sits visually centered. body.sky-saved adds *only* the snap-binary scroll layer (scroll-snap-type:y, modal-body display:contents, cols min-height:100% scroll-snap-align:start, wheel-col aspect-ratio cap released, form-col flex:0 0 auto so the snap basis wins) — the column-stacking is no longer gated.
Async save: SAVE SKY's success branch now calls _activateSavedState(), which adds body.sky-saved, draws the wheel from _lastChartData, pins overlay.scrollTop to the form section's offsetTop, then runs the existing _scrollApertureToTop ease-out so the wheel reveals from above instead of replacing the form with a hard cut. The wheel preview that previously redrew during typing is now gated on _savedSky — pre-first-save typing fetches the chart data (so SAVE SKY enables) but does not render the wheel, mirroring the My Sky applet's "no wheel until saved" UX. The in-room PICK SKY overlay (_sky_overlay.html) still previews live, deliberately untouched.
Pre-save the wheel-col is hidden via `body:not(.sky-saved) .sky-page .sky-wheel-col { display: none }`, so the empty SVG can't shunt the form below the fold (& the DEL btn rides the same selector since it lives inside .sky-wheel-col).
Tests: SkyDeleteTest IT class (5: clears fields, redirects, 405 on GET, login required, preserves unrelated user fields). MySkyDeleteFlowTest FT class (3: DEL btn visibility gated on sky data, NVM dismisses w. data intact, OK clears + reverts body class). MySkyAsyncSaveTest FT (1: fresh user → SAVE SKY → body picks up sky-saved, wheel SVG populates, DEL btn becomes visible — all without a page reload). All 13 sky FTs + sky ITs green; existing MySkyApertureSnapScrollTest & MySkyTimezoneRefreshTest still pass.
Code architected by Disco DeDisco <discodedisco@outlook.com>
Git commit message Co-Authored-By:
Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -467,6 +467,186 @@ class MySkyApertureSnapScrollTest(FunctionalTest):
|
||||
))
|
||||
|
||||
|
||||
class MySkyAsyncSaveTest(FunctionalTest):
|
||||
"""A fresh user (no saved sky) clicks SAVE SKY (mocked) — without a page
|
||||
reload, the page transitions into the saved state: body picks up
|
||||
.sky-saved, the wheel SVG renders, and the DEL btn becomes visible."""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
Applet.objects.get_or_create(
|
||||
slug="my-sky",
|
||||
defaults={"name": "My Sky", "grid_cols": 6, "grid_rows": 6, "context": "dashboard"},
|
||||
)
|
||||
self.gamer = User.objects.create(email="newcomer@test.io")
|
||||
self.sky_url = self.live_server_url + "/dashboard/sky/"
|
||||
|
||||
def test_save_sky_async_activates_saved_state_without_reload(self):
|
||||
self.create_pre_authenticated_session("newcomer@test.io")
|
||||
self.browser.get(self.sky_url)
|
||||
|
||||
# Pre-save state: no wheel children, body has no sky-saved class
|
||||
body = self.browser.find_element(By.TAG_NAME, "body")
|
||||
self.assertNotIn("sky-saved", body.get_attribute("class"))
|
||||
|
||||
# Mock /sky/preview + /sky/save
|
||||
self.browser.execute_script("""
|
||||
const FIXTURE = """ + _json.dumps(_CHART_FIXTURE) + """;
|
||||
window._origFetch = window.fetch;
|
||||
window.fetch = function(url, opts) {
|
||||
if (typeof url === 'string' && url.includes('/sky/preview')) {
|
||||
return Promise.resolve({ok:true, json:()=>Promise.resolve(FIXTURE)});
|
||||
}
|
||||
if (typeof url === 'string' && url.includes('/sky/save')) {
|
||||
return Promise.resolve({ok:true, json:()=>Promise.resolve({saved:true})});
|
||||
}
|
||||
return window._origFetch(url, opts);
|
||||
};
|
||||
""")
|
||||
|
||||
# Fill required form fields & dispatch input → preview enables save btn
|
||||
self.browser.execute_script("""
|
||||
document.getElementById('id_nf_date').value = '1990-06-15';
|
||||
document.getElementById('id_nf_lat').value = '51.5074';
|
||||
document.getElementById('id_nf_lon').value = '-0.1278';
|
||||
document.getElementById('id_nf_tz').value = 'Europe/London';
|
||||
document.getElementById('id_nf_date').dispatchEvent(
|
||||
new Event('input', {bubbles:true})
|
||||
);
|
||||
""")
|
||||
|
||||
confirm_btn = self.browser.find_element(By.ID, "id_sky_confirm")
|
||||
self.wait_for(lambda: self.assertIsNone(
|
||||
confirm_btn.get_attribute("disabled")
|
||||
))
|
||||
|
||||
confirm_btn.click()
|
||||
|
||||
# 1. body picks up sky-saved without a reload
|
||||
self.wait_for(lambda: self.assertIn(
|
||||
"sky-saved",
|
||||
self.browser.find_element(By.TAG_NAME, "body").get_attribute("class"),
|
||||
))
|
||||
|
||||
# 2. Wheel SVG is now drawn (has child elements)
|
||||
self.wait_for(lambda: self.assertTrue(
|
||||
self.browser.find_elements(By.CSS_SELECTOR, "#id_sky_svg > *"),
|
||||
"Wheel SVG should have children after async save",
|
||||
))
|
||||
|
||||
# 3. DEL btn visible
|
||||
del_btn = self.browser.find_element(By.CSS_SELECTOR, ".sky-wheel-col .btn-danger")
|
||||
self.assertTrue(del_btn.is_displayed())
|
||||
|
||||
|
||||
class MySkyDeleteFlowTest(FunctionalTest):
|
||||
"""A .btn-danger DEL button sits at the wheel center when sky data exists.
|
||||
Clicking it summons the global #id_guard_portal (OK / NVM); OK clears all
|
||||
sky fields on the User model and reverts the page to the form-only view."""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
Applet.objects.get_or_create(
|
||||
slug="my-sky",
|
||||
defaults={"name": "My Sky", "grid_cols": 6, "grid_rows": 6, "context": "dashboard"},
|
||||
)
|
||||
self.gamer = User.objects.create(email="stargazer@test.io")
|
||||
self.gamer.sky_chart_data = _CHART_FIXTURE
|
||||
self.gamer.sky_birth_place = "Baltimore, MD, US"
|
||||
self.gamer.sky_birth_tz = "America/New_York"
|
||||
self.gamer.sky_birth_lat = 39.2904
|
||||
self.gamer.sky_birth_lon = -76.6122
|
||||
self.gamer.sky_birth_dt = datetime(
|
||||
1990, 6, 15, 12, 0, tzinfo=zoneinfo.ZoneInfo("UTC")
|
||||
)
|
||||
self.gamer.save()
|
||||
self.sky_url = self.live_server_url + "/dashboard/sky/"
|
||||
|
||||
# ── T1 ───────────────────────────────────────────────────────────────────
|
||||
|
||||
def test_del_btn_only_visible_when_sky_data_exists(self):
|
||||
"""DEL btn is hidden for users w. no saved sky; visible once data is saved.
|
||||
The btn lives in the DOM unconditionally (so async save can reveal it) —
|
||||
visibility is gated by body.sky-saved via CSS."""
|
||||
self.create_pre_authenticated_session("stargazer@test.io")
|
||||
self.browser.get(self.sky_url)
|
||||
del_btn = self.wait_for(lambda: self.browser.find_element(
|
||||
By.CSS_SELECTOR, ".sky-wheel-col .btn-danger"
|
||||
))
|
||||
self.assertTrue(del_btn.is_displayed())
|
||||
|
||||
# Sanity: a fresh user (no chart_data) → DEL btn hidden (display:none)
|
||||
from apps.lyric.models import User as _U
|
||||
_U.objects.create(email="newcomer@test.io")
|
||||
self.create_pre_authenticated_session("newcomer@test.io")
|
||||
self.browser.get(self.sky_url)
|
||||
self.wait_for(lambda: self.browser.find_element(By.ID, "id_nf_date"))
|
||||
btns = self.browser.find_elements(By.CSS_SELECTOR, ".sky-wheel-col .btn-danger")
|
||||
self.assertTrue(
|
||||
not btns or not btns[0].is_displayed(),
|
||||
"DEL btn should not be visible before any sky data is saved",
|
||||
)
|
||||
|
||||
# ── T2 ───────────────────────────────────────────────────────────────────
|
||||
|
||||
def test_clicking_del_then_nvm_keeps_sky_data(self):
|
||||
"""DEL → guard portal → NVM dismisses; user's sky fields are untouched."""
|
||||
self.create_pre_authenticated_session("stargazer@test.io")
|
||||
self.browser.get(self.sky_url)
|
||||
|
||||
del_btn = self.wait_for(lambda: self.browser.find_element(
|
||||
By.CSS_SELECTOR, ".sky-wheel-col .btn-danger"
|
||||
))
|
||||
del_btn.click()
|
||||
|
||||
portal = self.wait_for(lambda: self.browser.find_element(By.ID, "id_guard_portal"))
|
||||
self.wait_for(lambda: self.assertIn("active", portal.get_attribute("class")))
|
||||
|
||||
portal.find_element(By.CSS_SELECTOR, ".guard-no").click()
|
||||
self.wait_for(lambda: self.assertNotIn(
|
||||
"active", portal.get_attribute("class")
|
||||
))
|
||||
|
||||
self.gamer.refresh_from_db()
|
||||
self.assertIsNotNone(self.gamer.sky_chart_data)
|
||||
self.assertEqual(self.gamer.sky_birth_place, "Baltimore, MD, US")
|
||||
|
||||
# ── T3 ───────────────────────────────────────────────────────────────────
|
||||
|
||||
def test_clicking_del_then_ok_clears_sky_and_reverts_to_form_only(self):
|
||||
"""DEL → guard portal → OK clears the user's sky fields, redirects, &
|
||||
the next sky-page render has no body.sky-saved class."""
|
||||
self.create_pre_authenticated_session("stargazer@test.io")
|
||||
self.browser.get(self.sky_url)
|
||||
|
||||
# Confirm initial saved state
|
||||
body = self.browser.find_element(By.TAG_NAME, "body")
|
||||
self.assertIn("sky-saved", body.get_attribute("class"))
|
||||
|
||||
del_btn = self.wait_for(lambda: self.browser.find_element(
|
||||
By.CSS_SELECTOR, ".sky-wheel-col .btn-danger"
|
||||
))
|
||||
del_btn.click()
|
||||
|
||||
portal = self.wait_for(lambda: self.browser.find_element(By.ID, "id_guard_portal"))
|
||||
self.wait_for(lambda: self.assertIn("active", portal.get_attribute("class")))
|
||||
|
||||
portal.find_element(By.CSS_SELECTOR, ".guard-yes").click()
|
||||
|
||||
# Page navigates back to /dashboard/sky/; body class no longer carries sky-saved
|
||||
self.wait_for(lambda: self.assertNotIn(
|
||||
"sky-saved",
|
||||
self.browser.find_element(By.TAG_NAME, "body").get_attribute("class"),
|
||||
))
|
||||
|
||||
# DB-side: every sky field is cleared
|
||||
self.gamer.refresh_from_db()
|
||||
self.assertIsNone(self.gamer.sky_chart_data)
|
||||
self.assertIsNone(self.gamer.sky_birth_dt)
|
||||
self.assertEqual(self.gamer.sky_birth_place, "")
|
||||
self.assertEqual(self.gamer.sky_birth_tz, "")
|
||||
|
||||
|
||||
class MySkyWheelConjunctionTest(FunctionalTest):
|
||||
"""Tick lines, z-raise, and dual tooltip for conjunct planets."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user