diff --git a/README.md b/README.md index bf2690f..a320013 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Bonfire.UiBoundaries +# Bonfire.UI.Boundaries A template for creating custom extensions for [Bonfire](https://bonfire.cafe/) @@ -10,7 +10,7 @@ git clone https://github.com/bonfire-networks/bonfire_ui_boundaries.git {your-ex cd {your-extension-name-here} ``` - Rename all the modules names to match your extension name: - - Find & replace Bonfire.UiBoundaries -> Bonfire.YourExtensionName + - Find & replace Bonfire.UI.Boundaries -> Bonfire.YourExtensionName - Find & replace bonfire_ui_boundaries -> bonfire_your_extension_name - Rename the `bonfire_ui_boundaries.exs` config file to match your extension name `bonfire_your_extension_name.exs` - Add paths to the router if you need it. If you add paths you will need to include the route module on [bonfire-app router module](https://github.com/bonfire-networks/bonfire-app/blob/main/lib/web/router.ex#L51) @@ -32,7 +32,7 @@ cd {your-extension-name-here} git push -u origin main ``` - Add the extension on your bonfire deps.path to include it in your local development -- Add `use_if_enabled(Bonfire.UiBoundaries.Web.Routes)` in your app's `Router` module +- Add `use_if_enabled(Bonfire.UI.Boundaries.Web.Routes)` in your app's `Router` module - Add the extension on deps.git also (specifying the branch name) to allow others that do not have it in their fork to use it - Write a meaningful readme - TADA 🔥! @@ -52,8 +52,8 @@ declare_extension( "ExtensionTemplate", icon: "bi:app", default_nav: [ - Bonfire.UiBoundaries.Web.HomeLive, - Bonfire.UiBoundaries.Web.AboutLive + Bonfire.UI.Boundaries.Web.HomeLive, + Bonfire.UI.Boundaries.Web.AboutLive ]) ``` diff --git a/config/bonfire_ui_boundaries.exs b/config/bonfire_ui_boundaries.exs index 32e8b29..4c44505 100644 --- a/config/bonfire_ui_boundaries.exs +++ b/config/bonfire_ui_boundaries.exs @@ -1,3 +1,6 @@ import Config -#### Extension-specific compile-time configuration goes here, everything else should be in `Bonfire.UiBoundaries.RuntimeConfig` +#### Extension-specific compile-time configuration goes here, everything else should be in `Bonfire.UI.Boundaries.RuntimeConfig` + +config :bonfire_ui_boundaries, + endpoint_module: Bonfire.Web.Endpoint diff --git a/config/config.exs b/config/config.exs index ef95e27..81cfd70 100755 --- a/config/config.exs +++ b/config/config.exs @@ -1,6 +1,6 @@ import Config -#### General configuration useful for tests, everything else should be in `bonfire_ui_boundaries.exs` or `Bonfire.UiBoundaries.RuntimeConfig` +#### General configuration useful for tests, everything else should be in `bonfire_ui_boundaries.exs` or `Bonfire.UI.Boundaries.RuntimeConfig` # You probably won't want to touch these. You might override some in # other config files. diff --git a/config/runtime.exs b/config/runtime.exs index 975dd5d..e099bea 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -1,3 +1,3 @@ import Config -Bonfire.UiBoundaries.RuntimeConfig.config() +Bonfire.UI.Boundaries.RuntimeConfig.config() diff --git a/lib/fake.ex b/lib/fake.ex index e54170e..b88ab65 100644 --- a/lib/fake.ex +++ b/lib/fake.ex @@ -1,2 +1,2 @@ -defmodule Bonfire.UiBoundaries.Fake do +defmodule Bonfire.UI.Boundaries.Fake do end diff --git a/lib/integration.ex b/lib/integration.ex index 480d963..f98db91 100644 --- a/lib/integration.ex +++ b/lib/integration.ex @@ -1,4 +1,4 @@ -defmodule Bonfire.UiBoundaries do +defmodule Bonfire.UI.Boundaries do @moduledoc "./README.md" |> File.stream!() |> Enum.drop(1) |> Enum.join() alias Bonfire.Common.Config diff --git a/lib/migrations.ex b/lib/migrations.ex index 13b0b76..59eb930 100755 --- a/lib/migrations.ex +++ b/lib/migrations.ex @@ -1,4 +1,4 @@ -defmodule Bonfire.UiBoundaries.Migrations do +defmodule Bonfire.UI.Boundaries.Migrations do @moduledoc false use Ecto.Migration end diff --git a/lib/runtime_config.ex b/lib/runtime_config.ex index 54f4233..dfc08a8 100644 --- a/lib/runtime_config.ex +++ b/lib/runtime_config.ex @@ -1,4 +1,4 @@ -defmodule Bonfire.UiBoundaries.RuntimeConfig do +defmodule Bonfire.UI.Boundaries.RuntimeConfig do use Bonfire.Common.Localise @behaviour Bonfire.Common.ConfigModule diff --git a/lib/web/components/acls/acl_live.sface b/lib/web/components/acls/acl_live.sface index 9bdf77a..2ad4542 100644 --- a/lib/web/components/acls/acl_live.sface +++ b/lib/web/components/acls/acl_live.sface @@ -145,13 +145,9 @@ {l("Remove")} <:open_btn> - + diff --git a/lib/web/components/acls/edit_acl_button/edit_acl_button_live.sface b/lib/web/components/acls/edit_acl_button/edit_acl_button_live.sface index fee24cb..5487a28 100644 --- a/lib/web/components/acls/edit_acl_button/edit_acl_button_live.sface +++ b/lib/web/components/acls/edit_acl_button/edit_acl_button_live.sface @@ -85,8 +85,8 @@ <:open_btn> - +
+ {l("Edit")}
\ No newline at end of file diff --git a/lib/web/components/acls/edit_acl_live.sface b/lib/web/components/acls/edit_acl_live.sface index 6672b40..bd059b5 100644 --- a/lib/web/components/acls/edit_acl_live.sface +++ b/lib/web/components/acls/edit_acl_live.sface @@ -79,7 +79,7 @@ {l("Remove")} <:open_btn> - +
{l("Remove")}
diff --git a/lib/web/components/circles/circle_live.sface b/lib/web/components/circles/circle_live.sface index 5b30149..f4789d4 100644 --- a/lib/web/components/circles/circle_live.sface +++ b/lib/web/components/circles/circle_live.sface @@ -52,8 +52,8 @@ <:open_btn> - +
+ {l("Edit circle")}
@@ -70,8 +70,8 @@ )}

<:open_btn> - +
<#Icon iconify="ph:trash-fill" class="w-4 h-4" /> + {l("Delete circle")}
<:action_btns> <:open_btn> - +
{l("Edit name")}
@@ -118,7 +118,7 @@ )}

<:open_btn> - +
{l("Delete circle")}
<:action_btns> +
{l("Remove")}
diff --git a/lib/web/components/display/boundary_icon_stateless_live.sface b/lib/web/components/display/boundary_icon_stateless_live.sface index f9d447a..b1a5321 100644 --- a/lib/web/components/display/boundary_icon_stateless_live.sface +++ b/lib/web/components/display/boundary_icon_stateless_live.sface @@ -18,14 +18,14 @@ /> <:open_btn> - + diff --git a/lib/web/components/set/boundaries_general_access_live.sface b/lib/web/components/set/boundaries_general_access_live.sface index d7ce7f7..2027496 100644 --- a/lib/web/components/set/boundaries_general_access_live.sface +++ b/lib/web/components/set/boundaries_general_access_live.sface @@ -25,10 +25,10 @@ hide_custom={@hide_custom} /> <:open_btn> - + diff --git a/lib/web/components/set/boundary_items_live.sface b/lib/web/components/set/boundary_items_live.sface index 5547cb7..64f9bb7 100644 --- a/lib/web/components/set/boundary_items_live.sface +++ b/lib/web/components/set/boundary_items_live.sface @@ -64,9 +64,9 @@ <:open_btn> - + --> diff --git a/mix.exs b/mix.exs index bfb0401..b2a092d 100755 --- a/mix.exs +++ b/mix.exs @@ -1,6 +1,6 @@ Code.eval_file("mess.exs", (if File.exists?("../../lib/mix/mess.exs"), do: "../../lib/mix/")) -defmodule Bonfire.UiBoundaries.MixProject do +defmodule Bonfire.UI.Boundaries.MixProject do use Mix.Project def project do diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index ac10fe7..8e4fdc8 100755 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -5,7 +5,7 @@ # Inside the script, you can read and write to any of your # repositories directly: # -# Bonfire.UiBoundaries.Repo.insert!(%Bonfire.UiBoundaries.SomeSchema{}) +# Bonfire.UI.Boundaries.Repo.insert!(%Bonfire.UI.Boundaries.SomeSchema{}) # # We recommend using the bang functions (`insert!`, `update!` # and so on) as they will fail if something goes wrong. diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex index 0b93c54..952023e 100755 --- a/test/support/channel_case.ex +++ b/test/support/channel_case.ex @@ -1,4 +1,4 @@ -defmodule Bonfire.UiBoundaries.ChannelCase do +defmodule Bonfire.UI.Boundaries.ChannelCase do @moduledoc """ This module defines the test case to be used by channel tests. @@ -17,13 +17,13 @@ defmodule Bonfire.UiBoundaries.ChannelCase do use ExUnit.CaseTemplate - import Bonfire.UiBoundaries + import Bonfire.UI.Boundaries using do quote do # Import conveniences for testing with channels import Phoenix.ChannelTest - import Bonfire.UiBoundaries.ChannelCase + import Bonfire.UI.Boundaries.ChannelCase # The default endpoint for testing @endpoint Application.compile_env!(:bonfire, :endpoint_module) diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 1c079fe..821a0c4 100755 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -1,4 +1,4 @@ -defmodule Bonfire.UiBoundaries.ConnCase do +defmodule Bonfire.UI.Boundaries.ConnCase do @moduledoc """ This module defines the test case to be used by tests that require setting up a connection. @@ -26,14 +26,15 @@ defmodule Bonfire.UiBoundaries.ConnCase do import Bonfire.UI.Common.Testing.Helpers import Phoenix.LiveViewTest - # import Bonfire.UiBoundaries.ConnCase, async: true + # import Bonfire.UI.Boundaries.ConnCase, async: true + import PhoenixTest - import Bonfire.UiBoundaries.Test.ConnHelpers - import Bonfire.UiBoundaries.Test.FakeHelpers + import Bonfire.UI.Boundaries.Test.ConnHelpers + import Bonfire.UI.Boundaries.Test.FakeHelpers - alias Bonfire.UiBoundaries.Fake - import Bonfire.UiBoundaries.Fake - # alias Bonfire.UiBoundaries.Web.Router.Helpers, as: Routes + alias Bonfire.UI.Boundaries.Fake + import Bonfire.UI.Boundaries.Fake + # alias Bonfire.UI.Boundaries.Web.Router.Helpers, as: Routes # The default endpoint for testing @endpoint Application.compile_env!(:bonfire, :endpoint_module) @@ -41,7 +42,7 @@ defmodule Bonfire.UiBoundaries.ConnCase do end setup tags do - import Bonfire.UiBoundaries + import Bonfire.UI.Boundaries Bonfire.Common.Test.Interactive.setup_test_repo(tags) diff --git a/test/support/conn_helpers.ex b/test/support/conn_helpers.ex index d5830bd..4e8ce2a 100644 --- a/test/support/conn_helpers.ex +++ b/test/support/conn_helpers.ex @@ -1,4 +1,4 @@ -defmodule Bonfire.UiBoundaries.Test.ConnHelpers do +defmodule Bonfire.UI.Boundaries.Test.ConnHelpers do import ExUnit.Assertions import Plug.Conn import Phoenix.ConnTest diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 9282b24..d91f477 100755 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -1,4 +1,4 @@ -defmodule Bonfire.UiBoundaries.DataCase do +defmodule Bonfire.UI.Boundaries.DataCase do @moduledoc """ This module defines the setup for tests requiring access to the application's data layer. @@ -10,19 +10,19 @@ defmodule Bonfire.UiBoundaries.DataCase do we enable the SQL sandbox, so changes done to the database are reverted at the end of every test. If you are using PostgreSQL, you can even run database tests asynchronously - by setting `use Bonfire.UiBoundaries.DataCase, async: true`, although + by setting `use Bonfire.UI.Boundaries.DataCase, async: true`, although this option is not recommended for other databases. """ use ExUnit.CaseTemplate - import Bonfire.UiBoundaries + import Bonfire.UI.Boundaries using do quote do import Ecto import Ecto.Changeset import Ecto.Query - # import Bonfire.UiBoundaries.DataCase + # import Bonfire.UI.Boundaries.DataCase end end diff --git a/test/support/data_helpers.ex b/test/support/data_helpers.ex index 7e4e742..5229ba4 100755 --- a/test/support/data_helpers.ex +++ b/test/support/data_helpers.ex @@ -1,4 +1,4 @@ -defmodule Bonfire.UiBoundaries.DataHelpers do +defmodule Bonfire.UI.Boundaries.DataHelpers do # import ExUnit.Assertions - # alias Bonfire.UiBoundaries.Fake + # alias Bonfire.UI.Boundaries.Fake end diff --git a/test/support/fake_helpers.ex b/test/support/fake_helpers.ex index b481b9b..c84b59b 100755 --- a/test/support/fake_helpers.ex +++ b/test/support/fake_helpers.ex @@ -1,12 +1,12 @@ -defmodule Bonfire.UiBoundaries.Test.FakeHelpers do +defmodule Bonfire.UI.Boundaries.Test.FakeHelpers do alias Bonfire.Data.Identity.Account - alias Bonfire.UiBoundaries.Fake - alias Bonfire.UiBoundaries.Accounts - alias Bonfire.UiBoundaries.Users + alias Bonfire.UI.Boundaries.Fake + alias Bonfire.UI.Boundaries.Accounts + alias Bonfire.UI.Boundaries.Users import ExUnit.Assertions - import Bonfire.UiBoundaries + import Bonfire.UI.Boundaries - import Bonfire.UiBoundaries.Fake + import Bonfire.UI.Boundaries.Fake end diff --git a/test/web/block_test.exs b/test/web/block_test.exs index a7499d2..aa340ed 100644 --- a/test/web/block_test.exs +++ b/test/web/block_test.exs @@ -1,5 +1,5 @@ defmodule Bonfire.Boundaries.BlockTest do - use Bonfire.Boundaries.ConnCase, async: true + use Bonfire.UI.Boundaries.ConnCase, async: true @moduletag :ui alias Bonfire.Social.Fake @@ -10,180 +10,118 @@ defmodule Bonfire.Boundaries.BlockTest do import Bonfire.Common.Enums import Bonfire.UI.Me - test "Ghost a user works" do - # create a bunch of users + setup do account = fake_account!() me = fake_user!(account) alice = fake_user!(account) - # login as me + bob = fake_user!(account) + carl = fake_user!(account) conn = conn(user: me, account: account) - # navigate to alice profile - {:ok, view, _html} = live(conn, "/@#{alice.character.username}") - # open the block modal - - view - |> element("li[data-role=ghost_modal] div[data-role=open_modal]") - |> render_click() - - # block alice - view - |> element("button[data-role=ghost]") - |> render_click() - # open_browser(view) - - assert render(view) =~ "ghosted" - assert render(view) =~ "Unghost" + {:ok, conn: conn, account: account, me: me, alice: alice, bob: bob, carl: carl} end - test "Silence a user works" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) - # login as me - conn = conn(user: me, account: account) - # navigate to alice profile - {:ok, view, _html} = live(conn, "/@#{alice.character.username}") - # open the block modal - - view - |> element("li[data-role=silence_modal] div[data-role=open_modal]") - |> render_click() - - # block alice - view - |> element("button[data-role=silence]") - |> render_click() + test "Ghost a user works (PhoenixTest)", %{conn: conn, alice: alice} do + conn + |> visit("/@#{alice.character.username}") + |> click_button("Ghost #{alice.profile.name}") + |> click_button("[data-role=ghost]", "Ghost") + |> assert_has("[role=alert]", text: "ghosted") + end - assert render(view) =~ "silenced" - assert render(view) =~ "Unsilence" + test "Silence a user works (PhoenixTest)", %{conn: conn, alice: alice} do + conn + |> visit("/@#{alice.character.username}") + |> click_button("Silence #{alice.profile.name}") + |> click_button("[data-role=silence]", "Silence") + |> assert_has("[role=alert]", text: "silenced") end - test "I can see a list of ghosted users" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) - bob = fake_user!(account) - carl = fake_user!(account) - # ghost alice and bob + test "I can see a list of ghosted users", %{ + conn: conn, + me: me, + alice: alice, + bob: bob, + carl: carl + } do assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(alice, :ghost, current_user: me) assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(bob, :ghost, current_user: me) assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(carl, :silence, current_user: me) - # login as me and navigate to ghosted page in settings - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/boundaries/ghosted") - # check that alice and bob are there - assert render(view) =~ alice.profile.name - assert render(view) =~ bob.profile.name - # check that carl is not there - refute render(view) =~ carl.profile.name + + conn + |> visit("/boundaries/ghosted") + |> assert_has("#circle_preview", text: alice.profile.name) + |> assert_has("#circle_preview", text: bob.profile.name) + |> refute_has("#circle_preview", text: carl.profile.name) end - test "I can see a list of silenced users" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) - bob = fake_user!(account) - carl = fake_user!(account) - # ghost alice and bob - assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(alice, :ghost, current_user: me) - assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(bob, :ghost, current_user: me) - assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(carl, :silence, current_user: me) - # login as me and navigate to ghosted page in settings - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/boundaries/silenced") - # check that alice and bob are there - refute render(view) =~ alice.profile.name - refute render(view) =~ bob.profile.name - # check that carl is not there - assert render(view) =~ carl.profile.name + test "I can see a list of silenced users", %{ + conn: conn, + me: me, + alice: alice, + bob: bob, + carl: carl + } do + assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(alice, :silence, current_user: me) + assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(bob, :silence, current_user: me) + assert {:ok, _ghosted} = Bonfire.Boundaries.Blocks.block(carl, :ghost, current_user: me) + + conn + |> visit("/boundaries/silenced") + |> assert_has("#circle_preview", text: alice.profile.name) + |> assert_has("#circle_preview", text: bob.profile.name) + |> refute_has("#circle_preview", text: carl.profile.name) end - test "I can unghost a previously ghosted user" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) - bob = fake_user!(account) - carl = fake_user!(account) - # ghost alice and bob + test "I can unghost a previously ghosted user", %{conn: conn, me: me, alice: alice} do assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(alice, :ghost, current_user: me) - # login as me and navigate to ghosted page in settings - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/boundaries/ghosted") - # check that alice is there - assert render(view) =~ alice.profile.name - # remove from the ghosted list - view - |> element("button[data-role=remove_user]") - |> render_click() - - assert render(view) =~ "Unblocked!" - refute render(view) =~ alice.profile.name + + conn + |> visit("/boundaries/ghosted") + |> assert_has("#circle_preview", text: alice.profile.name) + |> click_button("[data-role=remove_user]", "Remove") + |> assert_has("[role=alert]", text: "Unblocked!") + |> refute_has("#circle_preview", text: alice.profile.name) end - test "I can unsilence a previously silenced user" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) - bob = fake_user!(account) - carl = fake_user!(account) - # ghost alice and bob + test "I can unsilence a previously silenced user", %{conn: conn, me: me, alice: alice} do assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(alice, :silence, current_user: me) - # login as me and navigate to ghosted page in settings - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/boundaries/silenced") - # check that alice is there - assert render(view) =~ alice.profile.name - # remove from the ghosted list - view - |> element("button[data-role=remove_user]") - |> render_click() - - assert render(view) =~ "Unblocked!" - refute render(view) =~ alice.profile.name + + conn + |> visit("/boundaries/silenced") + |> assert_has("#circle_preview", text: alice.profile.name) + |> click_button("[data-role=remove_user]", "Remove") + |> assert_has("[role=alert]", text: "Unblocked!") + |> refute_has("#circle_preview", text: alice.profile.name) end - test "I can see if I silenced a user from their profile page" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) + test "I can see if I silenced a user from their profile page", %{ + conn: conn, + me: me, + alice: alice + } do assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(alice, :silence, current_user: me) - # navigate to alice profile - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/@#{alice.character.username}") - # check that there is a silenced label - assert render(view) =~ "silenced" + + conn + |> visit("/@#{alice.character.username}") + |> assert_has("[data-id=hero_data]", text: "silenced") end - test "I can see if I ghosted a user from their profile page" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) + test "I can see if I ghosted a user from their profile page", %{ + conn: conn, + me: me, + alice: alice + } do assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(alice, :ghost, current_user: me) - # navigate to alice profile - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/@#{alice.character.username}") - # check that there is a silenced label - assert render(view) =~ "ghosted" + + conn + |> visit("/@#{alice.character.username}") + |> assert_has("[data-id=hero_data]", text: "ghosted") end describe "if I silenced a user i will not receive any update from it" do - test "i'll not see anything they publish in feeds" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) + test "i'll not see anything they publish in feeds", %{conn: conn, alice: alice, me: me} do assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(alice, :silence, current_user: me) - conn = conn(user: alice, account: account) - {:ok, view, _html} = live(conn, "/feed") - # write a post html_body = "epic html message" attrs = %{post_content: %{html_body: html_body}} @@ -194,22 +132,13 @@ defmodule Bonfire.Boundaries.BlockTest do boundary: "local" ) - # login as me - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/feed/local") - # check that the post is not there - refute render(view) =~ html_body + conn + |> visit("/feed/local") + |> refute_has("article", text: html_body) end - test "i'll be able to view their profile, I cannot read post via direct link" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) + test "i'll still be able to view their profile", %{conn: conn, alice: alice, me: me} do assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(alice, :silence, current_user: me) - conn = conn(user: alice, account: account) - {:ok, view, _html} = live(conn, "/feed") - # write a post html_body = "epic html message" attrs = %{post_content: %{html_body: html_body}} @@ -220,29 +149,31 @@ defmodule Bonfire.Boundaries.BlockTest do boundary: "local" ) - # login as me - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/feed/local") - # check that the post is not there - refute render(view) =~ html_body - assert {:ok, profile, _html} = live(conn, "/@#{alice.character.username}") + conn + |> visit("/@#{alice.character.username}") + |> assert_has("[data-id=hero_data]", text: alice.profile.name) + end + + test "I cannot read post via direct link", %{conn: conn, alice: alice, me: me} do + assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(alice, :silence, current_user: me) + html_body = "epic html message" + attrs = %{post_content: %{html_body: html_body}} - # navigate to previously created post - assert {:ok, thread, _html} = live(conn, "/post/#{post.id}") + {:ok, post} = + Posts.publish( + current_user: alice, + post_attrs: attrs, + boundary: "local" + ) - # view the post previously created - refute render(thread) =~ html_body + # FIXME: This test is failing, user can access a post made by a silenced user + conn + |> visit("/post/#{post.id}") + |> refute_has("#thread_main_object", text: html_body) end - test "i'll not see any @ mentions from them" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) + test "i'll not see any @ mentions from them", %{conn: conn, me: me, alice: alice} do assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(alice, :silence, current_user: me) - conn = conn(user: alice, account: account) - {:ok, view, _html} = live(conn, "/feed") - # write a post as alice and mention me html_body = "@#{me.character.username} epic html message" attrs = %{post_content: %{html_body: html_body}} @@ -250,29 +181,21 @@ defmodule Bonfire.Boundaries.BlockTest do Posts.publish( current_user: alice, post_attrs: attrs, - boundary: "mention" + boundary: "public" ) - # login as me - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/notifications") - # check that the post is not there - refute render(view) =~ html_body - {:ok, view, _html} = live(conn, "/feed/local") - # check that the post is not there - refute render(view) =~ html_body + conn + |> visit("/notifications") + |> refute_has("article", text: html_body) + + conn + |> visit("/feed/local") + |> refute_has("article", text: html_body) end - test "i'll not see any DMs from them" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) + test "i'll not see any DMs from them", %{conn: conn, me: me, alice: alice} do assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(alice, :silence, current_user: me) - conn = conn(user: alice, account: account) - {:ok, view, _html} = live(conn, "/feed") - # write a post as alice and mention me - html_body = "@#{alice.character.username} epic html message" + html_body = "epic html message" attrs = %{post_content: %{html_body: html_body}} {:ok, post} = @@ -283,36 +206,19 @@ defmodule Bonfire.Boundaries.BlockTest do to_circles: [me.character.id] ) - # login as me - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/messages") - # check that the post is not there - refute render(view) =~ html_body + conn + |> visit("/messages") + |> refute_has("article", text: html_body) end - - # test "I'll not be able to follow them" do - # # create a bunch of users - # account = fake_account!() - # me = fake_user!(account) - # alice = fake_user!(account) - # assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(alice, :silence, current_user: me) - # conn = conn(user: me, account: account) - # {:ok, view, _html} = live(conn, "/@#{alice.character.username}") - - # refute has_element?(view, "div[data-role=follow_wrapper] a[data-id=follow]") - # end end describe "if I ghosted a user they will not be able to interact with me or with my content" do - test "Nothing I post privately will be shown to them from now on" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) + test "Nothing I post privately will be shown to them from now on", %{ + account: account, + alice: alice, + me: me + } do assert {:ok, _ghosted} = Bonfire.Boundaries.Blocks.block(alice, :ghost, current_user: me) - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/feed") - # write a post html_body = "epic html message" attrs = %{post_content: %{html_body: html_body}} @@ -325,20 +231,18 @@ defmodule Bonfire.Boundaries.BlockTest do # login as alice conn = conn(user: alice, account: account) - {:ok, view, _html} = live(conn, "/feed/local") - # check that the post is not there - refute render(view) =~ html_body + + conn + |> visit("/feed/local") + |> refute_has("article", text: html_body) end - test "They may still be able to see things I post publicly. " do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) + test "They cannot see things I post publicly when logged.", %{ + account: account, + alice: alice, + me: me + } do assert {:ok, _ghosted} = Bonfire.Boundaries.Blocks.block(alice, :ghost, current_user: me) - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/feed") - # write a post html_body = "epic html message" attrs = %{post_content: %{html_body: html_body}} @@ -350,21 +254,15 @@ defmodule Bonfire.Boundaries.BlockTest do ) # login as alice - conn = conn() - {:ok, view, _html} = live(conn, "/feed") - # check that the post is not there - assert render(view) =~ html_body + conn = conn(user: alice, account: account) + + conn + |> visit("/feed/explore") + |> refute_has("article", text: html_body) end - test "I won't be able to @ mention them. " do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) + test "I won't be able to @ mention them.", %{account: account, alice: alice, me: me} do assert {:ok, _ghosted} = Bonfire.Boundaries.Blocks.block(alice, :ghost, current_user: me) - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/feed") - # write a post and mention alice html_body = "@#{alice.character.username} epic html message" attrs = %{post_content: %{html_body: html_body}} @@ -372,28 +270,23 @@ defmodule Bonfire.Boundaries.BlockTest do Posts.publish( current_user: me, post_attrs: attrs, - boundary: "mention" + boundary: "public" ) # login as alice conn = conn(user: alice, account: account) - {:ok, view, _html} = live(conn, "/notifications") - # check that the post is not there - refute render(view) =~ html_body - {:ok, view, _html} = live(conn, "/feed/local") - # check that the post is not there - refute render(view) =~ html_body + + conn + |> visit("/notifications") + |> refute_has("article", text: html_body) + + conn + |> visit("/feed/local") + |> refute_has("article", text: html_body) end - test "I won't be able to DM them. " do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) + test "I won't be able to DM them.", %{account: account, alice: alice, me: me} do assert {:ok, _ghosted} = Bonfire.Boundaries.Blocks.block(alice, :ghost, current_user: me) - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/feed") - # write a post and DM alice html_body = "epic html message" attrs = %{post_content: %{html_body: html_body}} @@ -407,181 +300,141 @@ defmodule Bonfire.Boundaries.BlockTest do # login as alice conn = conn(user: alice, account: account) - {:ok, view, _html} = live(conn, "/messages") - # check that the post is not there - refute render(view) =~ html_body - end - # WIP: This test is failing, but im not sure this is the right behavior - # test "they won't be able to follow me" do - # # create a bunch of users - # account = fake_account!() - # me = fake_user!(account) - # alice = fake_user!(account) - # assert {:ok, _ghosted} = Bonfire.Boundaries.Blocks.block(alice, :ghost, current_user: me) - # conn = conn(user: alice, account: account) - # {:ok, view, _html} = live(conn, "/@#{me.character.username}") - - # view - # |> element("div[data-role=follow_wrapper] a[data-id=follow]") - # |> render_click() - - # assert has_element?(view, "div[data-role=follow_wrapper] a[data-id=follow]") - # end + conn + |> visit("/messages") + |> refute_has("article", text: html_body) + end end describe "Admin" do - # test "As an admin I can ghost a user instance-wide" do - # # create a bunch of users - # account = fake_account!() - # me = fake_user!(account) - # alice = fake_user!(account) - # bob = fake_user!(account) - # # make myself an admin - # Bonfire.Me.Users.make_admin(me) - # assert {:ok, _ghosted} = Bonfire.Boundaries.Blocks.block(alice.id, :ghost, :instance_wide) - # # login as bob - # conn = conn(user: bob, account: account) - # {:ok, view, _html} = live(conn, "/feed") - # # write a post - # html_body = "epic html message" - # attrs = %{post_content: %{html_body: html_body}} - - # {:ok, post} = - # Posts.publish( - # current_user: bob, - # post_attrs: attrs, - # boundary: "local" - # ) - - # # login as alice - # conn = conn(user: alice, account: account) - # {:ok, view, _html} = live(conn, "/feed/local") - # # check that the post is not there - # refute render(view) =~ html_body - # end - - # test "As an admin I can silence a user instance-wide" do - # # create a bunch of users - # account = fake_account!() - # me = fake_user!(account) - # alice = fake_user!(account) - # bob = fake_user!(account) - # # make myself an admin - # Bonfire.Me.Users.make_admin(me) - # assert {:ok, _ghosted} = Bonfire.Boundaries.Blocks.block(alice.id, :ghost, :instance_wide) - # # login as bob - # conn = conn(user: bob, account: account) - # {:ok, view, _html} = live(conn, "/feed") - # # write a post - # html_body = "epic html message" - # attrs = %{post_content: %{html_body: html_body}} - - # {:ok, post} = - # Posts.publish( - # current_user: alice, - # post_attrs: attrs, - # boundary: "local" - # ) - - # # login as bob - # conn = conn(user: bob, account: account) - # {:ok, view, _html} = live(conn, "/feed/local") - # # check that the post is not there - # refute render(view) =~ html_body - # end - - test "As an admin I can see a list of instance-wide ghosted users" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) - bob = fake_user!(account) - carl = fake_user!(account) + test "As an admin I can ghost a user instance-wide", %{ + me: me, + alice: alice, + bob: bob, + account: account + } do + Bonfire.Me.Users.make_admin(me) + assert {:ok, _ghosted} = Bonfire.Boundaries.Blocks.block(alice.id, :ghost, :instance_wide) + html_body = "epic html message" + attrs = %{post_content: %{html_body: html_body}} + + {:ok, post} = + Posts.publish( + current_user: bob, + post_attrs: attrs, + boundary: "local" + ) + + # login as alice + conn = conn(user: alice, account: account) + + conn + |> visit("/feed/local") + |> refute_has("article", text: html_body) + + {:ok, view, _html} = live(conn, "/feed/local") + end + + test "As an admin I can silence a user instance-wide", %{ + me: me, + alice: alice, + bob: bob, + account: account + } do + Bonfire.Me.Users.make_admin(me) + assert {:ok, _ghosted} = Bonfire.Boundaries.Blocks.block(alice.id, :ghost, :instance_wide) + # write a post + html_body = "epic html message" + attrs = %{post_content: %{html_body: html_body}} + + {:ok, post} = + Posts.publish( + current_user: alice, + post_attrs: attrs, + boundary: "local" + ) + + # login as bob + conn = conn(user: bob, account: account) + + conn + |> visit("/feed/local") + |> refute_has("article", text: html_body) + end + + test "As an admin I can see a list of instance-wide ghosted users", %{ + conn: conn, + me: me, + alice: alice, + bob: bob, + carl: carl + } do Bonfire.Me.Users.make_admin(me) - # ghost alice and bob assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(alice, :ghost, :instance_wide) assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(bob, :ghost, :instance_wide) assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(carl, :silence, :instance_wide) - # login as me and navigate to ghosted page in settings - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/boundaries/instance_ghosted") - # check that alice and bob are there - assert render(view) =~ alice.profile.name - assert render(view) =~ bob.profile.name - # check that carl is not there - refute render(view) =~ carl.profile.name + + conn + |> visit("/boundaries/instance_ghosted") + |> assert_has("#circle_preview", text: alice.profile.name) + |> assert_has("#circle_preview", text: bob.profile.name) + |> refute_has("#circle_preview", text: carl.profile.name) end - test "As an admin I can see a list of instance-wide silenced users" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) - bob = fake_user!(account) - carl = fake_user!(account) + test "As an admin I can see a list of instance-wide silenced users", %{ + conn: conn, + me: me, + alice: alice, + bob: bob, + carl: carl + } do Bonfire.Me.Users.make_admin(me) - # ghost alice and bob assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(alice, :ghost, :instance_wide) assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(bob, :ghost, :instance_wide) assert {:ok, _silenced} = Bonfire.Boundaries.Blocks.block(carl, :silence, :instance_wide) - # login as me and navigate to ghosted page in settings - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/boundaries/instance_silenced") - # check that alice and bob are not there - refute render(view) =~ alice.profile.name - refute render(view) =~ bob.profile.name - # check that carl is there - assert render(view) =~ carl.profile.name + + conn + |> visit("/boundaries/instance_silenced") + |> refute_has("#circle_preview", text: alice.profile.name) + |> refute_has("#circle_preview", text: bob.profile.name) + |> assert_has("#circle_preview", text: carl.profile.name) end - test "As an admin I can unghost a previously ghosted user instance-wide" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) + test "As an admin I can unghost a previously ghosted user instance-wide", %{ + conn: conn, + me: me, + alice: alice, + bob: bob, + carl: carl + } do {:ok, me} = Users.make_admin(me) - alice = fake_user!(account) - bob = fake_user!(account) - carl = fake_user!(account) - # ghost alice and bob - assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(alice, :ghost, :instance_wide) - # login as me and navigate to ghosted page in settings - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/boundaries/instance_ghosted") - # check that alice is there - assert render(view) =~ alice.profile.name - # remove from the ghosted list - view - |> element("button[data-role=remove_user]") - |> render_click() - - assert render(view) =~ "Unblocked!" - refute render(view) =~ alice.profile.name + + conn + |> visit("/boundaries/instance_ghosted") + |> assert_has("#circle_preview", text: alice.profile.name) + |> click_button("[data-role=remove_user]", "Remove") + |> assert_has("[role=alert]", text: "Unblocked!") + |> refute_has("#circle_preview", text: alice.profile.name) end - test "As an admin I can unsilence a previously silenced user instance-wide" do - # create a bunch of users - account = fake_account!() - me = fake_user!(account) - alice = fake_user!(account) - bob = fake_user!(account) - carl = fake_user!(account) - # ghost alice and bob + test "As an admin I can unsilence a previously silenced user instance-wide", %{ + conn: conn, + me: me, + alice: alice, + bob: bob, + carl: carl + } do assert {:ok, _ghost} = Bonfire.Boundaries.Blocks.block(alice, :silence, :instance_wide) - # login as me and navigate to ghosted page in settings {:ok, me} = Users.make_admin(me) - conn = conn(user: me, account: account) - {:ok, view, _html} = live(conn, "/boundaries/instance_silenced") - # check that alice is there - assert render(view) =~ alice.profile.name - # remove from the ghosted list - view - |> element("button[data-role=remove_user]") - |> render_click() - - assert render(view) =~ "Unblocked!" - refute render(view) =~ alice.profile.name + + conn + |> visit("/boundaries/instance_silenced") + |> assert_has("#circle_preview", text: alice.profile.name) + |> click_button("[data-role=remove_user]", "Remove") + |> assert_has("[role=alert]", text: "Unblocked!") + |> refute_has("#circle_preview", text: alice.profile.name) end end end diff --git a/test/web/boundaries_in_feeds_test.exs b/test/web/boundaries_in_feeds_test.exs index 285df7e..2e89bd8 100644 --- a/test/web/boundaries_in_feeds_test.exs +++ b/test/web/boundaries_in_feeds_test.exs @@ -1,5 +1,5 @@ defmodule Bonfire.Boundaries.InFeedsTest do - use Bonfire.Boundaries.ConnCase, async: true + use Bonfire.UI.Boundaries.ConnCase, async: true @moduletag :ui alias Bonfire.Social.Fake diff --git a/test/web/boundaries_on_post.exs b/test/web/boundaries_on_post.exs index 4ab2dcd..88b399c 100644 --- a/test/web/boundaries_on_post.exs +++ b/test/web/boundaries_on_post.exs @@ -1,5 +1,5 @@ defmodule Bonfire.Boundaries.OnPostTest do - use Bonfire.Boundaries.ConnCase, async: true + use Bonfire.UI.Boundaries.ConnCase, async: true @moduletag :ui alias Bonfire.Social.Fake diff --git a/test/web/live_handler_test.exs b/test/web/live_handler_test.exs index c8aa1c8..f09cbe0 100644 --- a/test/web/live_handler_test.exs +++ b/test/web/live_handler_test.exs @@ -1,5 +1,5 @@ defmodule Bonfire.Boundaries.LiveHandlerTest do - use Bonfire.Boundaries.ConnCase, async: true + use Bonfire.UI.Boundaries.ConnCase, async: true @moduletag :ui diff --git a/test/web/negative_boundaries_test.exs b/test/web/negative_boundaries_test.exs index 508b544..cc4e32a 100644 --- a/test/web/negative_boundaries_test.exs +++ b/test/web/negative_boundaries_test.exs @@ -1,5 +1,5 @@ defmodule Bonfire.Boundaries.NegativeBoundariesTest do - use Bonfire.Boundaries.ConnCase, async: true + use Bonfire.UI.Boundaries.ConnCase, async: true @moduletag :ui alias Bonfire.Social.Fake diff --git a/test/web/roles_test.exs b/test/web/roles_test.exs index 1274046..4a4d2f4 100644 --- a/test/web/roles_test.exs +++ b/test/web/roles_test.exs @@ -1,5 +1,5 @@ defmodule Bonfire.Boundaries.Web.RolesTest do - use Bonfire.Boundaries.ConnCase, async: true + use Bonfire.UI.Boundaries.ConnCase, async: true @moduletag :ui