forked from phoenix-playground/phoenix_playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_controller_test.exs
executable file
·45 lines (37 loc) · 1 KB
/
demo_controller_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env elixir
Mix.install([
{:phoenix_playground, "~> 0.1.3"}
])
defmodule DemoController do
use Phoenix.Controller, formats: [:html]
use Phoenix.Component
plug :put_layout, false
plug :put_view, __MODULE__
def index(conn, params) do
count =
case Integer.parse(params["count"] || "") do
{n, ""} -> n
_ -> 0
end
render(conn, :index, count: count)
end
def index(assigns) do
~H"""
<span>Count: <%= @count %></span>
<button onclick={"window.location.href='/?count=#{@count + 1}'"}>+</button>
<button onclick={"window.location.href='/?count=#{@count - 1}'"}>-</button>
"""
end
end
Logger.configure(level: :info)
ExUnit.start()
defmodule DemoControllerTest do
use ExUnit.Case
use PhoenixPlayground.Test, controller: DemoController
test "it works" do
conn = get(build_conn(), "/")
assert html_response(conn, 200) =~ "Count: 0"
conn = get(build_conn(), "/?count=1")
assert html_response(conn, 200) =~ "Count: 1"
end
end