diff --git a/lib/labelmaker_web/router.ex b/lib/labelmaker_web/router.ex
index f5a6d25..2dfd006 100644
--- a/lib/labelmaker_web/router.ex
+++ b/lib/labelmaker_web/router.ex
@@ -18,6 +18,7 @@ defmodule LabelmakerWeb.Router do
pipe_through :browser
live "/", Home
+ get "/labels", LabelsController, :index
get "/:label", LabelController, :show
end
diff --git a/test/labelmaker_web/controllers/labels_controller_test.exs b/test/labelmaker_web/controllers/labels_controller_test.exs
new file mode 100644
index 0000000..fed2fb5
--- /dev/null
+++ b/test/labelmaker_web/controllers/labels_controller_test.exs
@@ -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