diff --git a/web/src/crate_web/route.gleam b/web/src/crate_web/route.gleam index 9343604..4f18f60 100644 --- a/web/src/crate_web/route.gleam +++ b/web/src/crate_web/route.gleam @@ -49,15 +49,15 @@ pub fn to_path(route: Route) -> String { /// Which bottom-tab section a route belongs to, so drill-downs off a tab /// (a record, the scan flow, a pressing) still show that tab active instead -/// of none. `Add` owns its own section rather than folding into `Crate`, so -/// the CRATE tab doesn't light up while the visitor is on the add form; the -/// centre "+" slot lights up instead, see `nav.add_tab`. +/// of none. The centre "+" slot owns the whole add flow, scan included: it +/// links into `Scan`, so anything less would have it go dark on its own +/// destination while CRATE lit up instead (see `nav.add_tab`). /// `PublicCrate`/`PublicRecord` map to themselves since they're reached /// outside the tab bar entirely. pub fn section(route: Route) -> Route { case route { - Crate | Scan | ScanReview | ScanDone | Record(_) | RecordAmend(_) -> Crate - Add -> Add + Crate | Record(_) | RecordAmend(_) -> Crate + Add | Scan | ScanReview | ScanDone -> Add Browse | PressingDetail(_, _) -> Browse Feed -> Feed Settings | EditInbox | EditProposalDetail(_) -> Settings diff --git a/web/test/nav_test.gleam b/web/test/nav_test.gleam index 971bc1a..cc2da9f 100644 --- a/web/test/nav_test.gleam +++ b/web/test/nav_test.gleam @@ -19,7 +19,7 @@ import gleam/string import lustre/element import support.{an_entry, empty_effect, logged_in, open_tags, tag_with} -/// Every drill-down maps to its tab's own section (crate/browse/settings +/// Every drill-down maps to its tab's own section (crate/add/browse/settings /// each own several, feed maps only to itself); public routes are the one /// family left unmapped (each maps to itself instead of a real section). pub fn route_section_maps_every_drilldown_to_its_tab_test() { @@ -28,9 +28,9 @@ pub fn route_section_maps_every_drilldown_to_its_tab_test() { #(Record("e1"), Crate), #(RecordAmend("e1"), Crate), #(Add, Add), - #(Scan, Crate), - #(ScanReview, Crate), - #(ScanDone, Crate), + #(Scan, Add), + #(ScanReview, Add), + #(ScanDone, Add), #(Browse, Browse), #(PressingDetail("did:plc:abc", "3jz"), Browse), #(Feed, Feed), @@ -141,3 +141,18 @@ pub fn every_route_change_clears_the_page_scoped_state_test() { assert after.discogs.confirm_disconnect == False }) } + +/// The "+" slot links into the scan flow, so it has to light up there: a +/// control that goes dark on its own destination (and hands the highlight +/// to CRATE) is telling the visitor they went somewhere else. +pub fn the_add_slot_lights_up_on_its_own_destination_test() { + [Scan, ScanReview, ScanDone, Add] + |> list.each(fn(destination) { + let html = + view.view(Model(..logged_in(), route: destination)) |> element.to_string + let slot = tag_with(html, "a", "aria-label=\"Add a record\"") + assert string.contains(slot, "class=\"tab-add is-active\"") + assert string.contains(slot, "aria-current=\"page\"") + assert !string.contains(tag_with(html, "a", "href=\"/\""), "is-active") + }) +}