Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Sep 11, 2024
1 parent 9aed4d0 commit 21cea6a
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
defmodule MindwendelWeb.BrainstormingLive.ShowSortByLabelTest do
use MindwendelWeb.ConnCase
import Phoenix.LiveViewTest
alias Mindwendel.Brainstormings

alias Mindwendel.Factory

setup do
%{brainstorming: Factory.insert!(:brainstorming)}
moderating_user = Factory.insert!(:user)
brainstorming = Factory.insert!(:brainstorming)
Brainstormings.add_moderating_user(brainstorming, moderating_user)
%{brainstorming: brainstorming, moderating_user: moderating_user}
end

test "contains button \"Sort by labels\"", %{
conn: conn,
brainstorming: brainstorming
brainstorming: brainstorming,
moderating_user: moderating_user
} do
{:ok, show_live_view, _html} =
live(conn, Routes.brainstorming_show_path(conn, :show, brainstorming))
conn
|> init_test_session(%{current_user_id: moderating_user.id})
|> live(Routes.brainstorming_show_path(conn, :show, brainstorming))

assert show_live_view
|> has_element?(html_selector_button_sort_by_labels(brainstorming))
end

# The order of the labels is the defined by the column position_order
test "sort ideas by labels", %{conn: conn, brainstorming: brainstorming} do
test "sort ideas by labels", %{conn: conn, brainstorming: brainstorming, moderating_user: moderating_user} do
idea_with_first_label =
Factory.insert!(:idea, %{
brainstorming: brainstorming,
@@ -36,7 +43,9 @@ defmodule MindwendelWeb.BrainstormingLive.ShowSortByLabelTest do
idea_without_label = Factory.insert!(:idea, %{brainstorming: brainstorming})

{:ok, show_live_view, _html} =
live(conn, Routes.brainstorming_show_path(conn, :show, brainstorming))
conn
|> init_test_session(%{current_user_id: moderating_user.id})
|> live(Routes.brainstorming_show_path(conn, :show, brainstorming))

rendered =
show_live_view
16 changes: 16 additions & 0 deletions test/mindwendel_web/live/live_helpers_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule MindwendelWeb.LiveHelpersTest do
use MindwendelWeb.ConnCase
import Phoenix.LiveViewTest
alias Mindwendel.Brainstormings

alias Mindwendel.Factory

@@ -17,4 +18,19 @@ defmodule MindwendelWeb.LiveHelpersTest do

assert html =~ "in 29 days"
end

test "contains sort button by likes for admin", %{
conn: conn,
brainstorming: brainstorming
} do
moderating_user = Factory.insert!(:user)
Brainstormings.add_moderating_user(brainstorming, moderating_user)

{:ok, view, _html} =
conn
|> init_test_session(%{current_user_id: moderating_user.id})
|> live(Routes.brainstorming_show_path(conn, :show, brainstorming))

assert view |> has_element?(".btn[title|='Sort by likes']")
end
end

0 comments on commit 21cea6a

Please sign in to comment.