133 lines
4.6 KiB
Elixir
133 lines
4.6 KiB
Elixir
defmodule ToweropsWeb.OnboardingLiveTest do
|
|
@moduledoc """
|
|
Tests for ToweropsWeb.OnboardingLive.
|
|
|
|
Note: OnboardingLive is not currently routed, so we test the module's
|
|
behavior through direct socket/event simulation rather than HTTP mounting.
|
|
"""
|
|
use ToweropsWeb.ConnCase, async: true
|
|
|
|
import Towerops.AccountsFixtures
|
|
import Towerops.OrganizationsFixtures
|
|
|
|
alias Phoenix.LiveView.Socket
|
|
alias ToweropsWeb.OnboardingLive
|
|
|
|
setup do
|
|
user = user_fixture()
|
|
organization = organization_fixture(user.id)
|
|
|
|
%{user: user, organization: organization}
|
|
end
|
|
|
|
describe "module structure" do
|
|
test "module exists and is a LiveView" do
|
|
Code.ensure_loaded!(OnboardingLive)
|
|
assert function_exported?(OnboardingLive, :mount, 3)
|
|
assert function_exported?(OnboardingLive, :handle_event, 3)
|
|
assert function_exported?(OnboardingLive, :handle_params, 3)
|
|
end
|
|
end
|
|
|
|
describe "mount/3" do
|
|
test "initializes with correct default state", %{user: user, organization: organization} do
|
|
socket =
|
|
%Socket{
|
|
assigns: %{
|
|
__changed__: %{},
|
|
current_scope: %{user: user, organization: organization},
|
|
flash: %{}
|
|
},
|
|
endpoint: ToweropsWeb.Endpoint
|
|
}
|
|
|
|
assert {:ok, socket} = OnboardingLive.mount(%{}, %{}, socket)
|
|
|
|
assert socket.assigns.step == :snmp
|
|
assert socket.assigns.organization == organization
|
|
assert socket.assigns.steps == [:snmp, :site, :billing, :agent]
|
|
assert socket.assigns.selected_provider == nil
|
|
assert socket.assigns.agent_token == nil
|
|
assert socket.assigns.agent_token_value == nil
|
|
assert socket.assigns.page_title
|
|
end
|
|
end
|
|
|
|
describe "handle_event skip" do
|
|
test "skip advances from snmp to site", %{user: user, organization: organization} do
|
|
socket =
|
|
user
|
|
|> build_socket(organization)
|
|
|> Map.put(:assigns, Map.put(build_socket(user, organization).assigns, :step, :snmp))
|
|
|
|
assert {:noreply, socket} = OnboardingLive.handle_event("skip", %{}, socket)
|
|
assert socket.assigns.step == :site
|
|
end
|
|
|
|
test "skip advances from site to billing", %{user: user, organization: organization} do
|
|
socket = build_socket(user, organization)
|
|
socket = put_in(socket.assigns.step, :site)
|
|
|
|
assert {:noreply, socket} = OnboardingLive.handle_event("skip", %{}, socket)
|
|
assert socket.assigns.step == :billing
|
|
end
|
|
end
|
|
|
|
describe "handle_event go_to_step" do
|
|
test "navigates to specified step", %{user: user, organization: organization} do
|
|
socket = build_socket(user, organization)
|
|
|
|
assert {:noreply, socket} = OnboardingLive.handle_event("go_to_step", %{"step" => "site"}, socket)
|
|
assert socket.assigns.step == :site
|
|
end
|
|
|
|
test "navigates to billing step", %{user: user, organization: organization} do
|
|
socket = build_socket(user, organization)
|
|
|
|
assert {:noreply, socket} = OnboardingLive.handle_event("go_to_step", %{"step" => "billing"}, socket)
|
|
assert socket.assigns.step == :billing
|
|
end
|
|
end
|
|
|
|
describe "handle_event select_provider" do
|
|
test "sets selected provider and creates integration form", %{user: user, organization: organization} do
|
|
socket = build_socket(user, organization)
|
|
socket = put_in(socket.assigns.step, :billing)
|
|
|
|
assert {:noreply, socket} = OnboardingLive.handle_event("select_provider", %{"provider" => "sonar"}, socket)
|
|
assert socket.assigns.selected_provider == "sonar"
|
|
assert socket.assigns.integration_form
|
|
end
|
|
end
|
|
|
|
# Helper to build a socket with required assigns for OnboardingLive
|
|
defp build_socket(user, organization) do
|
|
changeset = Towerops.Organizations.change_organization(organization)
|
|
site_changeset = Towerops.Sites.change_site(%Towerops.Sites.Site{}, %{})
|
|
|
|
%Socket{
|
|
assigns: %{
|
|
__changed__: %{},
|
|
current_scope: %{user: user, organization: organization},
|
|
flash: %{},
|
|
step: :snmp,
|
|
steps: [:snmp, :site, :billing, :agent],
|
|
organization: organization,
|
|
form: Phoenix.Component.to_form(changeset),
|
|
site_form: Phoenix.Component.to_form(site_changeset, as: "site"),
|
|
billing_providers: [
|
|
%{id: "gaiia", name: "Gaiia", icon: "hero-user-group"},
|
|
%{id: "sonar", name: "Sonar", icon: "hero-currency-dollar"},
|
|
%{id: "splynx", name: "Splynx", icon: "hero-banknotes"},
|
|
%{id: "visp", name: "VISP", icon: "hero-cloud"}
|
|
],
|
|
selected_provider: nil,
|
|
integration_form: nil,
|
|
agent_token: nil,
|
|
agent_token_value: nil,
|
|
page_title: "Setup"
|
|
},
|
|
endpoint: ToweropsWeb.Endpoint
|
|
}
|
|
end
|
|
end
|