Claude set up a '/labels' endpoint
This commit is contained in:
93
test/labelmaker_web/controllers/labels_controller_test.exs
Normal file
93
test/labelmaker_web/controllers/labels_controller_test.exs
Normal file
@@ -0,0 +1,93 @@
|
||||
defmodule LabelmakerWeb.LabelsControllerTest do
|
||||
use LabelmakerWeb.ConnCase, async: false
|
||||
|
||||
@label_dir Path.join(:code.priv_dir(:labelmaker), "static/labels")
|
||||
|
||||
setup do
|
||||
# Clean up test images before each test
|
||||
File.rm_rf!(@label_dir)
|
||||
File.mkdir_p!(@label_dir)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "renders empty state when no labels exist", %{conn: conn} do
|
||||
conn = get(conn, ~p"/labels")
|
||||
|
||||
assert html_response(conn, 200) =~ "No labels generated yet"
|
||||
assert html_response(conn, 200) =~ "Create Your First Label"
|
||||
end
|
||||
|
||||
test "lists all generated labels", %{conn: conn} do
|
||||
# Generate some test labels
|
||||
_conn1 = get(conn, ~p"/TestLabel1?color=red")
|
||||
_conn2 = get(conn, ~p"/TestLabel2?color=blue")
|
||||
_conn3 = get(conn, ~p"/TestLabel3?color=green")
|
||||
|
||||
# Visit labels page
|
||||
conn = get(conn, ~p"/labels")
|
||||
html = html_response(conn, 200)
|
||||
|
||||
assert html =~ "Generated Labels"
|
||||
assert html =~ "Total labels: 3"
|
||||
end
|
||||
|
||||
test "displays label information correctly", %{conn: conn} do
|
||||
# Generate a test label
|
||||
_conn = get(conn, ~p"/MyLabel?color=yellow&size=96")
|
||||
|
||||
# Visit labels page
|
||||
conn = get(conn, ~p"/labels")
|
||||
html = html_response(conn, 200)
|
||||
|
||||
# Should show size and modified date
|
||||
assert html =~ "Size:"
|
||||
assert html =~ "Modified:"
|
||||
assert html =~ "View Full Size"
|
||||
end
|
||||
|
||||
test "shows labels sorted by most recent first", %{conn: conn} do
|
||||
# Generate labels with delays to ensure different timestamps
|
||||
_conn1 = get(conn, ~p"/First")
|
||||
Process.sleep(100)
|
||||
_conn2 = get(conn, ~p"/Second")
|
||||
Process.sleep(100)
|
||||
_conn3 = get(conn, ~p"/Third")
|
||||
|
||||
# Visit labels page
|
||||
conn = get(conn, ~p"/labels")
|
||||
html = html_response(conn, 200)
|
||||
|
||||
# Should show all labels
|
||||
assert html =~ "Total labels: 3"
|
||||
end
|
||||
|
||||
test "handles missing labels directory gracefully", %{conn: conn} do
|
||||
# Remove the labels directory entirely
|
||||
File.rm_rf!(@label_dir)
|
||||
|
||||
conn = get(conn, ~p"/labels")
|
||||
|
||||
assert html_response(conn, 200) =~ "No labels generated yet"
|
||||
end
|
||||
|
||||
test "includes link back to home", %{conn: conn} do
|
||||
conn = get(conn, ~p"/labels")
|
||||
html = html_response(conn, 200)
|
||||
|
||||
assert html =~ "Back to Home"
|
||||
assert html =~ ~p"/"
|
||||
end
|
||||
|
||||
test "shows clickable URLs for each label", %{conn: conn} do
|
||||
_conn = get(conn, ~p"/ClickableTest")
|
||||
|
||||
conn = get(conn, ~p"/labels")
|
||||
html = html_response(conn, 200)
|
||||
|
||||
# Should have a URL input field
|
||||
assert html =~ "/labels/"
|
||||
assert html =~ ".png"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user