Skip to content

Commit 9ce2c76

Browse files
authored
5 - Testing Interactions (#24)
* and setup on the desktop * Three tests to test increment, one good, two ungood. One test to test decrement and that's mine * matching version of elixir and OTP in actions with the asdf versions in .tool-versions
1 parent 08d8411 commit 9ce2c76

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-24.04]
11-
otp: [27.x]
12-
elixir: [1.18.3]
11+
otp: [26.1.2]
12+
elixir: [1.15.7]
1313
services:
1414
postgres:
1515
image: postgres
@@ -44,4 +44,5 @@ jobs:
4444
run: |
4545
mix compile --force --
4646
mix test test/ranger_web/live/greet_live_test.exs
47-
mix test test/ranger_web/live/avatar_live_test.exs
47+
mix test test/ranger_web/live/avatar_live_test.exs
48+
mix test test/ranger_web/live/counter_live_test.exs

test/ranger_web/live/counter_live_test.exs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,52 @@ defmodule RangerWeb.CounterLiveTest do
22
use RangerWeb.ConnCase
33

44
import Phoenix.LiveViewTest
5+
6+
@tag :good
7+
test "user can increase count", %{conn: conn} do
8+
{:ok, view, _html} = live(conn, ~p"/counter")
9+
10+
view
11+
|> element("#increment")
12+
|> render_click()
13+
14+
assert has_element?(view, "#count", "1")
15+
end
16+
17+
@tag :ungood
18+
test "user can increase count (less effective)", %{conn: conn} do
19+
{:ok, view, _html} = live(conn, ~p"/counter")
20+
21+
html =
22+
view
23+
|> element("#increment")
24+
|> render_click()
25+
26+
# this just asserts that "1" is somewhere in the html.
27+
# ... which is a bit dumb.
28+
assert html =~ "1"
29+
30+
end
31+
32+
@tag :ungood
33+
test "user can increase counter (bypasses HTML - not good)", %{conn: conn} do
34+
{:ok, view, _} = live(conn, ~p"/counter")
35+
36+
render_click(view, "increase")
37+
38+
assert has_element?(view, "#count", "1")
39+
end
40+
41+
42+
@tag :mine
43+
test "user can decreease count", %{conn: conn} do
44+
{:ok, view, html} = live(conn, ~p"/counter")
45+
46+
view
47+
|> element("#decrement")
48+
|> render_click()
49+
50+
assert has_element?(view, "#count", "-1")
51+
end
52+
553
end

0 commit comments

Comments
 (0)