|
| 1 | +defmodule HeroixWeb.GameViewTest do |
| 2 | + use HeroixWeb.ConnCase |
| 3 | + |
| 4 | + import Phoenix.ConnTest |
| 5 | + import Phoenix.LiveViewTest |
| 6 | + alias Heroix.Settings |
| 7 | + @endpoint HeroixWeb.Endpoint |
| 8 | + |
| 9 | + setup do |
| 10 | + Heroix.GameInstaller.reset() |
| 11 | + Heroix.GameUninstaller.reset() |
| 12 | + |
| 13 | + %{} |
| 14 | + end |
| 15 | + |
| 16 | + describe "install button" do |
| 17 | + test "starts installing a game", %{conn: conn} do |
| 18 | + {:ok, view, _html} = live(conn, "/library/0afb9d54dd3743a582b48b506466d3f8") |
| 19 | + |
| 20 | + view |> element("button", "Add Game") |> render_click() |
| 21 | + view |> element("button", "Install") |> render_click() |
| 22 | + |
| 23 | + assert Heroix.GameInstaller.installing() == "0afb9d54dd3743a582b48b506466d3f8" |
| 24 | + end |
| 25 | + |
| 26 | + test "adds a game to the install queue", %{conn: conn} do |
| 27 | + Heroix.GameInstaller.install_game("0a697c1235fb4706a635cfa33f0306ec", %{}) |
| 28 | + |
| 29 | + assert Heroix.GameInstaller.installing() == "0a697c1235fb4706a635cfa33f0306ec" |
| 30 | + |
| 31 | + {:ok, view, _html} = live(conn, "/library/0afb9d54dd3743a582b48b506466d3f8") |
| 32 | + |
| 33 | + view |> element("button", "Add Game") |> render_click() |
| 34 | + view |> element("button", "Install") |> render_click() |
| 35 | + |
| 36 | + assert Heroix.GameInstaller.installing() == "0a697c1235fb4706a635cfa33f0306ec" |
| 37 | + |
| 38 | + assert Heroix.GameInstaller.queue() == [ |
| 39 | + %{app_name: "0afb9d54dd3743a582b48b506466d3f8", opts: %{"install_path" => nil}} |
| 40 | + ] |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + describe "stop installation button" do |
| 45 | + test "cancels the installation", %{conn: conn} do |
| 46 | + Heroix.GameInstaller.install_game("0a697c1235fb4706a635cfa33f0306ec", %{}) |
| 47 | + |
| 48 | + assert Heroix.GameInstaller.installing() == "0a697c1235fb4706a635cfa33f0306ec" |
| 49 | + assert Heroix.GameInstaller.queue() == [] |
| 50 | + |
| 51 | + {:ok, view, html} = live(conn, "/library/0a697c1235fb4706a635cfa33f0306ec") |
| 52 | + |
| 53 | + assert html =~ "Starting installation..." |
| 54 | + |
| 55 | + view |> element("button", "Stop Installation") |> render_click() |
| 56 | + |
| 57 | + assert :sys.get_state(GameInstaller).stopping() == "0a697c1235fb4706a635cfa33f0306ec" |
| 58 | + end |
| 59 | + end |
| 60 | + |
| 61 | + describe "uninstall button" do |
| 62 | + test "triggers the game uninstallation", %{conn: conn} do |
| 63 | + {:ok, view, _html} = live(conn, "/library/Godwit") |
| 64 | + |
| 65 | + view |> element("button", "Uninstall") |> render_click() |
| 66 | + |
| 67 | + assert :sys.get_state(GameUninstaller).uninstalling == "Godwit" |
| 68 | + end |
| 69 | + end |
| 70 | + |
| 71 | + describe "settings" do |
| 72 | + test "shows games settings", %{conn: conn} do |
| 73 | + HeroixWeb.Endpoint.subscribe("settings") |
| 74 | + |
| 75 | + {:ok, view, _html} = live(conn, "/library/Condor") |
| 76 | + |
| 77 | + refute view |> element("#game.show-config") |> has_element?() |
| 78 | + |
| 79 | + view |> element("button", "Config") |> render_click() |
| 80 | + |
| 81 | + assert view |> element("#game.show-config") |> has_element?() |
| 82 | + |
| 83 | + assert Settings.legendary_game_config("Condor")["language"] == nil |
| 84 | + |
| 85 | + view |
| 86 | + |> element("#game-config form") |
| 87 | + |> render_change(%{"_target" => ["language"], "language" => "en"}) |
| 88 | + |
| 89 | + assert Settings.legendary_game_config("Condor")["language"] == "en" |
| 90 | + |
| 91 | + view |
| 92 | + |> element("#game-config input[name=\"language\"]") |
| 93 | + |> render_blur() |
| 94 | + |
| 95 | + assert_received %Phoenix.Socket.Broadcast{event: "save_legendary_config"} |
| 96 | + end |
| 97 | + end |
| 98 | +end |
0 commit comments