//// Shared model builders and rendering helpers reused across the web test //// suite's per-page test modules. import at_record/gen/defs.{type Snapshot, Price, Snapshot} import at_record_web/model.{ type DiscogsResult, type Display, type Entry, type Model, Crate, DiscogsResult, Entry, Grid, LoggedIn, LoggedOut, Model, ShelfLoaded, System, blank_amend, blank_discogs, blank_form, blank_scan, } import at_record_web/pages/crate import gleam/dict import gleam/http/response.{Response} import gleam/option.{None, Some} import lustre/effect.{type Effect} import lustre/element import rsvp pub fn empty_effect() -> Effect(a) { effect.none() } pub fn unauthorized() -> rsvp.Error(String) { rsvp.HttpError(Response(401, [], "")) } pub fn base() -> Model { Model( auth: LoggedOut, route: Crate, login_handle: "", login_suggestions: [], login_error: None, view: "owned", display: Grid, theme: System, shelf: ShelfLoaded([]), crate_window: model.crate_window_size, crate_cursor: None, shelf_loading_more: False, via_handles: dict.new(), form: blank_form(), notice: None, busy: False, pending_revert: None, selected: None, editing: False, confirm_remove: False, timeline: [], release_info: None, discogs: blank_discogs(), scan: blank_scan(), amending: False, publishing: False, amend: blank_amend(), avatar: None, browse: [], browse_adding: None, browse_query: "", browse_genre: "", browse_filters_open: False, inbox: model.InboxLoading, confirm_logout: False, ignored_proposals: [], public_shelf: model.PublicShelfLoading, public_entry: model.PublicEntryLoading, pressing: model.PressingLoading, ) } pub fn logged_in() -> Model { Model(..base(), auth: LoggedIn("alice.test")) } pub fn rendered_empty_crate(view: String) -> String { Model(..logged_in(), view:, shelf: ShelfLoaded([])) |> crate.view |> element.to_string } pub fn rendered_loaded_crate(display: Display) -> String { Model(..logged_in(), display:, shelf: ShelfLoaded([an_entry()])) |> crate.view |> element.to_string } fn a_snapshot() -> Snapshot { Snapshot( artist_display: "Slint", cover: None, format: Some("LP"), thumb_url: None, title: "Spiderland", year: Some(1991), ) } pub fn an_entry() -> Entry { Entry( entry_id: "e1", status: "owned", snapshot: a_snapshot(), media_grade: Some("NM"), sleeve_grade: Some("VG+"), rating: Some(4), folder: None, notes: None, price: Some(Price(amount: 4000, currency: "EUR")), counterparty: Some("Record shop"), source: None, ) } pub fn discogs_result(id: Int) -> DiscogsResult { DiscogsResult( discogs_id: id, title: "Spiderland", artist: "Slint", year: Some(1991), format: Some("LP"), thumb_url: None, cover_url: None, ) }