Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/924
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Aug 18, 2024
1 parent 9017bf7 commit 7c9093c
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 87 deletions.
2 changes: 1 addition & 1 deletion lib/components/message_threads_live.sface
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
context={@context}
/>

<ul class="divide-y divide-base-content/20">
<ul id="message_threads" class="divide-y divide-base-content/20">
<li class="hover:bg-base-content/5" :for={%{activity: activity} <- e(@threads, :edges, [])}>
<LinkPatchLive
to={permalink(e(activity, :replied, :thread_id, nil), e(activity, :object_id, nil))}
Expand Down
2 changes: 2 additions & 0 deletions lib/messages_routes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ defmodule Bonfire.UI.Messages.Routes do
pipe_through(:browser)
pipe_through(:user_required)

live("/message/:id", MessagesLive)

live("/messages/:id", MessagesLive, as: Bonfire.Data.Social.Message)
live("/messages/:id/reply/:reply_to_id", MessagesLive, as: Bonfire.Data.Social.Message)
live("/messages/@:username", MessagesLive, as: Bonfire.Data.Social.Message)
Expand Down
2 changes: 2 additions & 0 deletions lib/views/messages_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ defmodule Bonfire.UI.Messages.MessagesLive do
feed_id: feed_id,
activity: nil,
object: nil,
tab_id: nil,
threads: [],
# reply_to_id: nil,
# thread_id: nil,
thread_mode: maybe_to_atom(e(params, "mode", nil)) || :flat,
Expand Down
219 changes: 133 additions & 86 deletions test/smart_input/create_message_test.exs
Original file line number Diff line number Diff line change
@@ -1,90 +1,82 @@
defmodule Bonfire.UI.Messages.CreatePost.Test do
defmodule Bonfire.UI.Messages.CreateMessageTest do
use Bonfire.UI.Messages.ConnCase, async: true
use Bonfire.Common.Utils
import Bonfire.Files.Simulation

alias Bonfire.Social.Fake
alias Bonfire.Posts
alias Bonfire.Messages
alias Bonfire.Social.Graph.Follows
alias Bonfire.Files.Test

@moduletag :todo

test "create a post with uploads" do
# Create alice user
account = fake_account!()
alice = fake_user!(account)
describe "send a message" do
test "shows a confirmation flash" do
some_account = fake_account!()
someone = fake_user!(some_account)
recipient = fake_user!()

# login as alice
conn = conn(user: alice, account: account)
{:ok, view, _html} = live(conn, "/write")
content = "here is an epic html message"

file = Path.expand("../fixtures/icon.png", __DIR__)
# open_browser(view)
conn = conn(user: someone, account: some_account)

icon =
file_input(view, "#smart_input_form", :files, [
%{
name: "image.png",
content: File.read!(file),
type: "image/png"
}
])
next = "/settings"
{:ok, view, _html} = live(conn, next)
# open_browser(view)

uploaded = render_upload(icon, "image.png")
# wait for persistent smart input to be ready
live_pubsub_wait(view)

# create a post
content = "here is an epic html post"
assert sent =
view
|> form("#smart_input form")
|> render_submit(%{
"create_object_type" => "message",
"to_circles" => [id(recipient)],
"post" => %{"post_content" => %{"html_body" => content}}
})

assert posted =
view
|> form("#smart_input_form")
|> render_submit(%{
"to_boundaries" => "public",
"post" => %{"post_content" => %{"html_body" => content}}
})
# |> Floki.text() =~ "sent"

assert [ok] = find_flash(posted)
{:ok, refreshed_view, _html} = live(conn, "/feed/local")
# open_browser(refreshed_view)
end
live_pubsub_wait(view)
assert [ok] = find_flash(sent)
assert ok |> Floki.text() =~ "Sent"
end

describe "create a post" do
test "shows a confirmation flash message" do
test "shows up in sender's message threads list" do
some_account = fake_account!()
someone = fake_user!(some_account)
recipient = fake_user!()

content = "here is an epic html post"
content = "here is an epic html message"

conn = conn(user: someone, account: some_account)

next = "/settings"
# |> IO.inspect
{:ok, view, _html} = live(conn, next)
# open_browser(view)

# wait for persistent smart input to be ready
live_pubsub_wait(view)

assert posted =
assert sent =
view
|> form("#smart_input form")
|> render_submit(%{
"to_boundaries" => "public",
"create_object_type" => "message",
"to_circles" => [id(recipient)],
"post" => %{"post_content" => %{"html_body" => content}}
})

# |> Floki.text() =~ "Posted"

live_pubsub_wait(view)
assert [ok] = find_flash(posted)
assert ok |> Floki.text() =~ "Posted"
next = "/messages"
# |> IO.inspect
{:ok, profile, _html} = live(conn, next)
assert has_element?(profile, "#message_threads", content)
end

test "shows up on my profile timeline" do
test "shows up in recipients's message threads list" do
some_account = fake_account!()
someone = fake_user!(some_account)
recipient = fake_user!()

content = "here is an epic html post"
content = "here is an epic html message"

conn = conn(user: someone, account: some_account)

Expand All @@ -94,93 +86,148 @@ defmodule Bonfire.UI.Messages.CreatePost.Test do
# open_browser(view)
live_pubsub_wait(view)

assert posted =
assert sent =
view
|> form("#smart_input form")
|> render_submit(%{
"to_boundaries" => "public",
"create_object_type" => "message",
"to_circles" => [id(recipient)],
"post" => %{"post_content" => %{"html_body" => content}}
})

next = "/user"
conn = conn(user: recipient)

next = "/messages"
# |> IO.inspect
{:ok, profile, _html} = live(conn, next)
assert has_element?(profile, "[data-id=feed]", content)
assert has_element?(profile, "#message_threads", content)
end

test "shows up in feed right away" do
test "does not show up on my profile timeline" do
some_account = fake_account!()
someone = fake_user!(some_account)
recipient = fake_user!()

content = "here is a post to test pubsub"
content = "here is an epic html message"

conn = conn(user: someone, account: some_account)

next = "/feed"
next = "/settings"
# |> IO.inspect
{:ok, view, _html} = live(conn, next)

assert view
|> form("#smart_input form")
|> render_submit(%{
"to_boundaries" => "public",
"post" => %{"post_content" => %{"html_body" => content}}
})

# check if post appears instantly on home feed (with pubsub)
# open_browser(view)
live_pubsub_wait(view)

assert has_element?(view, "[data-id=feed]", content)
assert sent =
view
|> form("#smart_input form")
|> render_submit(%{
"create_object_type" => "message",
"to_circles" => [id(recipient)],
"post" => %{"post_content" => %{"html_body" => content}}
})

next = "/user"
# |> IO.inspect
{:ok, profile, _html} = live(conn, next)
refute has_element?(profile, "[data-id=feed]", content)
end

@tag :todo
test "has the correct permissions when replying" do
test "recipient can send reply, which appears instantly on thread page" do
alice = fake_user!("none")

bob = fake_user!("contribute")
recipient = fake_user!()

attrs = %{
post_content: %{
summary: "summary",
name: "test post name",
html_body: "@#{bob.character.username} first post</p>"
name: "test message name",
html_body: "first message"
}
}

assert {:ok, op} =
Posts.publish(current_user: alice, post_attrs: attrs, boundary: "mentions")
Messages.send(alice, attrs, recipient)

content = "here is an epic html post"
content = "epic reply"

conn = conn(user: bob)
conn = conn(user: recipient)

next = "/post/#{id(op)}"
next = "/messages/#{id(op)}"
# |> IO.inspect
{:ok, view, _html} = live(conn, next)
live_pubsub_wait(view)

# open_browser(view)

assert _click =
view
|> element("[data-id=action_reply]")
|> render_click()

# open_browser(view)
assert sent =
view
|> form("#smart_input form")
|> render_submit(%{
"create_object_type" => "message",
"to_circles" => [id(alice)],
"post" => %{"post_content" => %{"html_body" => content}}
})

assert view
|> form("#smart_input form")
|> render_submit(%{
"to_boundaries" => "mentions",
"post" => %{"post_content" => %{"html_body" => content}}
})
assert [ok] = find_flash(sent)
assert ok |> Floki.text() =~ "Sent"

conn2 = conn(user: alice)

next = "/@#{bob.character.username}"
# next = "/@#{bob.character.username}"
# |> IO.inspect
{:ok, feed, _html} = live(conn2, next)
assert has_element?(feed, "[data-id=feed]", content)
live_pubsub_wait(view)
open_browser(view)

assert has_element?(feed, "[data-role=thread]", content)
end

# fix first in `Bonfire.UI.Posts`
@tag :todo
test "with uploads" do
# Create alice user
account = fake_account!()
alice = fake_user!(account)
recipient = fake_user!()

# login as alice
conn = conn(user: alice, account: account)
{:ok, view, _html} = live(conn, "/write")

file = Path.expand("../fixtures/icon.png", __DIR__)
# open_browser(view)

icon =
file_input(view, "#smart_input_form", :files, [
%{
name: "image.png",
content: File.read!(file),
type: "image/png"
}
])

uploaded = render_upload(icon, "image.png")

# create a post
content = "here is an epic html message"

assert sent =
view
|> form("#smart_input_form")
|> render_submit(%{
"create_object_type" => "message",
"to_circles" => [id(recipient)],
"post" => %{"post_content" => %{"html_body" => content}}
})

# WIP: does this test do what's expected?
assert [ok] = find_flash(sent)
{:ok, refreshed_view, _html} = live(conn, "/feed/local")
# open_browser(refreshed_view)
end
end
end

0 comments on commit 7c9093c

Please sign in to comment.