berrypod/test/simpleshop_theme/theme/preview_data_test.exs
Jamey Greenwood d4dbd8998f fix: resolve compilation warnings and update tests to match implementation
- Remove unused generate_mood/1, generate_typography/1, generate_shape/1,
  generate_density/1 functions from CSSGenerator (now handled via CSS
  data attributes)
- Prefix unused _opts parameters in Printify.Client
- Remove unused created_products variable from MockupGenerator
- Update CSSGeneratorTest to test actual generated CSS (accent colors,
  font size scale, layout width, etc.)
- Update PresetsTest to match 8 presets (not 9)
- Fix PreviewDataTest to accept local image paths
- Update ThemeLiveTest to use correct selectors and match actual UI
2026-01-15 22:36:15 +00:00

202 lines
5.6 KiB
Elixir

defmodule SimpleshopTheme.Theme.PreviewDataTest do
use ExUnit.Case, async: true
alias SimpleshopTheme.Theme.PreviewData
describe "products/0" do
test "returns a list of products" do
products = PreviewData.products()
assert is_list(products)
assert length(products) > 0
end
test "each product has required fields" do
products = PreviewData.products()
product = List.first(products)
assert is_map(product)
assert Map.has_key?(product, :id)
assert Map.has_key?(product, :name)
assert Map.has_key?(product, :description)
assert Map.has_key?(product, :price)
assert Map.has_key?(product, :image_url)
assert Map.has_key?(product, :category)
assert Map.has_key?(product, :in_stock)
assert Map.has_key?(product, :on_sale)
end
test "products have valid prices" do
products = PreviewData.products()
for product <- products do
assert is_integer(product.price)
assert product.price > 0
if product.compare_at_price do
assert is_integer(product.compare_at_price)
assert product.compare_at_price > product.price
end
end
end
test "products have image URLs" do
products = PreviewData.products()
for product <- products do
assert is_binary(product.image_url)
# Images can be either local paths (starting with /) or full URLs
assert String.starts_with?(product.image_url, "/") or
String.starts_with?(product.image_url, "http")
if product.hover_image_url do
assert is_binary(product.hover_image_url)
assert String.starts_with?(product.hover_image_url, "/") or
String.starts_with?(product.hover_image_url, "http")
end
end
end
test "some products are on sale" do
products = PreviewData.products()
on_sale_products = Enum.filter(products, & &1.on_sale)
assert length(on_sale_products) > 0
end
test "on-sale products have compare_at_price" do
products = PreviewData.products()
on_sale_products = Enum.filter(products, & &1.on_sale)
for product <- on_sale_products do
assert product.compare_at_price != nil
end
end
end
describe "cart_items/0" do
test "returns a list of cart items" do
cart_items = PreviewData.cart_items()
assert is_list(cart_items)
assert length(cart_items) > 0
end
test "each cart item has required fields" do
cart_items = PreviewData.cart_items()
item = List.first(cart_items)
assert is_map(item)
assert Map.has_key?(item, :product)
assert Map.has_key?(item, :quantity)
assert Map.has_key?(item, :variant)
end
test "cart items have valid quantities" do
cart_items = PreviewData.cart_items()
for item <- cart_items do
assert is_integer(item.quantity)
assert item.quantity > 0
end
end
test "cart items reference valid products" do
cart_items = PreviewData.cart_items()
for item <- cart_items do
product = item.product
assert is_map(product)
assert Map.has_key?(product, :id)
assert Map.has_key?(product, :name)
assert Map.has_key?(product, :price)
end
end
end
describe "testimonials/0" do
test "returns a list of testimonials" do
testimonials = PreviewData.testimonials()
assert is_list(testimonials)
assert length(testimonials) > 0
end
test "each testimonial has required fields" do
testimonials = PreviewData.testimonials()
testimonial = List.first(testimonials)
assert is_map(testimonial)
assert Map.has_key?(testimonial, :id)
assert Map.has_key?(testimonial, :author)
assert Map.has_key?(testimonial, :content)
assert Map.has_key?(testimonial, :rating)
assert Map.has_key?(testimonial, :date)
end
test "testimonials have valid ratings" do
testimonials = PreviewData.testimonials()
for testimonial <- testimonials do
assert is_integer(testimonial.rating)
assert testimonial.rating >= 1
assert testimonial.rating <= 5
end
end
test "testimonials have content" do
testimonials = PreviewData.testimonials()
for testimonial <- testimonials do
assert is_binary(testimonial.content)
assert String.length(testimonial.content) > 0
end
end
end
describe "categories/0" do
test "returns a list of categories" do
categories = PreviewData.categories()
assert is_list(categories)
assert length(categories) > 0
end
test "each category has required fields" do
categories = PreviewData.categories()
category = List.first(categories)
assert is_map(category)
assert Map.has_key?(category, :id)
assert Map.has_key?(category, :name)
assert Map.has_key?(category, :slug)
assert Map.has_key?(category, :product_count)
assert Map.has_key?(category, :image_url)
end
test "categories have valid slugs" do
categories = PreviewData.categories()
for category <- categories do
assert is_binary(category.slug)
assert String.match?(category.slug, ~r/^[a-z0-9-]+$/)
end
end
test "categories have product counts" do
categories = PreviewData.categories()
for category <- categories do
assert is_integer(category.product_count)
assert category.product_count >= 0
end
end
end
describe "has_real_products?/0" do
test "returns false when no real products exist" do
assert PreviewData.has_real_products?() == false
end
end
end