95 lines
3.4 KiB
Elixir
95 lines
3.4 KiB
Elixir
|
|
defmodule Rsh26poolWeb.ManageLiveTest do
|
||
|
|
use Rsh26poolWeb.ConnCase
|
||
|
|
|
||
|
|
import Phoenix.LiveViewTest
|
||
|
|
|
||
|
|
alias Rsh26pool.Voting
|
||
|
|
|
||
|
|
defp new_room(overrides \\ %{}) do
|
||
|
|
{:ok, result} =
|
||
|
|
Voting.create_room(
|
||
|
|
Map.merge(
|
||
|
|
%{
|
||
|
|
"name" => "管理ルーム",
|
||
|
|
"votes_per_user" => "2",
|
||
|
|
"grouping_mode" => "false",
|
||
|
|
"leader_threshold" => "2",
|
||
|
|
"closes_at_local" => ""
|
||
|
|
},
|
||
|
|
overrides
|
||
|
|
)
|
||
|
|
)
|
||
|
|
|
||
|
|
result
|
||
|
|
end
|
||
|
|
|
||
|
|
defp authed(conn, participant) do
|
||
|
|
Plug.Test.init_test_session(conn, %{"participant_token" => participant.token})
|
||
|
|
end
|
||
|
|
|
||
|
|
test "a non-owner member is redirected to the home page", %{conn: conn} do
|
||
|
|
%{room: room} = new_room()
|
||
|
|
{:ok, member} = Voting.join_room(room, %{"name" => "一般参加者"})
|
||
|
|
|
||
|
|
assert {:error, {:redirect, %{to: "/"}}} =
|
||
|
|
conn |> authed(member) |> live(~p"/manage/#{room.room_number}")
|
||
|
|
end
|
||
|
|
|
||
|
|
test "the owner can view vote counts, rename the room, and close voting", %{conn: conn} do
|
||
|
|
%{room: room, owner: owner} = new_room(%{"votes_per_user" => "2"})
|
||
|
|
{:ok, poster} = Voting.join_room(room, %{"name" => "投稿者"})
|
||
|
|
{:ok, idea} = Voting.create_idea(room, poster, %{"text" => "人気の案"})
|
||
|
|
{:ok, voter1} = Voting.join_room(room, %{"name" => "投票者1"})
|
||
|
|
{:ok, voter2} = Voting.join_room(room, %{"name" => "投票者2"})
|
||
|
|
{:ok, _} = Voting.vote(voter1, idea.id)
|
||
|
|
{:ok, _} = Voting.vote(voter2, idea.id)
|
||
|
|
|
||
|
|
{:ok, lv, html} = conn |> authed(owner) |> live(~p"/manage/#{room.room_number}")
|
||
|
|
|
||
|
|
assert html =~ "管理ページ"
|
||
|
|
|
||
|
|
# The result row shows the idea and its vote count of 2 (rank is 1).
|
||
|
|
result_row = lv |> element("ol li", "人気の案") |> render()
|
||
|
|
assert result_row =~ "人気の案"
|
||
|
|
assert result_row =~ "2"
|
||
|
|
|
||
|
|
# Rename via the form.
|
||
|
|
lv |> form("#rename-form", room: %{name: "新しいルーム名"}) |> render_submit()
|
||
|
|
assert render(lv) =~ "新しいルーム名"
|
||
|
|
assert Voting.reload_room(room).name == "新しいルーム名"
|
||
|
|
|
||
|
|
# Close via the close button.
|
||
|
|
refute render(lv) =~ "この投票は終了しています"
|
||
|
|
lv |> element("button[phx-click='close']") |> render_click()
|
||
|
|
assert Voting.reload_room(room).status == "closed"
|
||
|
|
assert render(lv) =~ "この投票は終了しています"
|
||
|
|
end
|
||
|
|
|
||
|
|
test "in grouping mode the group cards appear after closing", %{conn: conn} do
|
||
|
|
%{room: room, owner: owner} =
|
||
|
|
new_room(%{"grouping_mode" => "true", "leader_threshold" => "2", "votes_per_user" => "3"})
|
||
|
|
|
||
|
|
{:ok, leader} = Voting.join_room(room, %{"name" => "リーダーA"})
|
||
|
|
{:ok, m1} = Voting.join_room(room, %{"name" => "メンバー1"})
|
||
|
|
{:ok, m2} = Voting.join_room(room, %{"name" => "メンバー2"})
|
||
|
|
|
||
|
|
{:ok, opinion} = Voting.create_idea(room, leader, %{"text" => "公園で花見をする"})
|
||
|
|
{:ok, _} = Voting.create_idea(room, m1, %{"text" => "案1"})
|
||
|
|
{:ok, _} = Voting.create_idea(room, m2, %{"text" => "案2"})
|
||
|
|
|
||
|
|
{:ok, _} = Voting.vote(m1, opinion.id)
|
||
|
|
{:ok, _} = Voting.vote(m2, opinion.id)
|
||
|
|
|
||
|
|
{:ok, lv, _} = conn |> authed(owner) |> live(~p"/manage/#{room.room_number}")
|
||
|
|
|
||
|
|
# No grouping section while the room is still open.
|
||
|
|
refute render(lv) =~ "グループ分けの結果"
|
||
|
|
|
||
|
|
lv |> element("button[phx-click='close']") |> render_click()
|
||
|
|
|
||
|
|
closed_html = render(lv)
|
||
|
|
assert closed_html =~ "グループ分けの結果"
|
||
|
|
assert closed_html =~ "リーダーA グループ"
|
||
|
|
end
|
||
|
|
end
|