wire shop LiveViews to DB queries and improve search UX
Replace PreviewData indirection in all shop LiveViews with direct Products context queries. Home, collection, product detail and error pages now query the database. Categories loaded once in ThemeHook. Cart hydration no longer falls back to mock data. PreviewData kept only for the theme editor. Search modal gains keyboard navigation (arrow keys, Enter, Escape), Cmd+K/Ctrl+K shortcut, full ARIA combobox pattern, LiveView navigate links, and 150ms debounce. SearchModal JS hook manages selection state and highlight. search.ex gets transaction safety on reindex and a public remove_product/1. 10 new integration tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -288,15 +288,27 @@ defmodule SimpleshopTheme.Products.ProductTest do
|
||||
product = %{
|
||||
provider_data: %{
|
||||
"options" => [
|
||||
%{"name" => "Size", "values" => [%{"title" => "S"}, %{"title" => "M"}]},
|
||||
%{"name" => "Color", "values" => [%{"title" => "Red"}]}
|
||||
%{
|
||||
"name" => "Size",
|
||||
"type" => "size",
|
||||
"values" => [%{"title" => "S"}, %{"title" => "M"}]
|
||||
},
|
||||
%{
|
||||
"name" => "Color",
|
||||
"type" => "color",
|
||||
"values" => [%{"title" => "Red", "colors" => ["#FF0000"]}]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
types = Product.option_types(product)
|
||||
assert length(types) == 2
|
||||
assert hd(types) == %{name: "Size", values: ["S", "M"]}
|
||||
assert hd(types) == %{name: "Size", type: :size, values: [%{title: "S"}, %{title: "M"}]}
|
||||
|
||||
color_type = Enum.at(types, 1)
|
||||
assert color_type.type == :color
|
||||
assert hd(color_type.values) == %{title: "Red", hex: "#FF0000"}
|
||||
end
|
||||
|
||||
test "returns empty list when no provider_data" do
|
||||
|
||||
@@ -196,4 +196,18 @@ defmodule SimpleshopTheme.SearchTest do
|
||||
assert Search.search("alpine") != []
|
||||
end
|
||||
end
|
||||
|
||||
describe "remove_product/1" do
|
||||
test "removes a product from the index", %{ocean: ocean} do
|
||||
assert Search.search("ocean") != []
|
||||
|
||||
Search.remove_product(ocean.id)
|
||||
|
||||
assert Search.search("ocean") == []
|
||||
end
|
||||
|
||||
test "is a no-op for unindexed product" do
|
||||
assert Search.remove_product(-1) == :ok
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user