Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmarcon committed Dec 4, 2023
1 parent b387ea6 commit d2cbfae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/support/live_select_web/live/showcase_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ defmodule LiveSelectWeb.ShowcaseLive do
socket =
socket
|> update(:live_select_form, fn form ->
if target == ["settings", "mode"] do
if target == ~w(settings mode) do
to_form(%{}, as: :my_form)
else
form
Expand Down Expand Up @@ -343,8 +343,8 @@ defmodule LiveSelectWeb.ShowcaseLive do
"submit" ->
mode = socket.assigns.settings_form.data.mode

selected = get_in(params, ["my_form", "city_search"])
selected_text = get_in(params, ["my_form", "city_search_text_input"])
selected = get_in(params,~w(my_form city_search))
selected_text = get_in(params, ~w(my_form city_search_text_input))

{cities, locations} = extract_cities_and_locations(mode, selected_text, selected)

Expand Down
15 changes: 6 additions & 9 deletions test/live_select_tags_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,11 @@ defmodule LiveSelectTagsTest do
end

test "selection can be updated from the form", %{conn: conn} do
stub_options([
%{value: 1, label: "A"},
%{value: 2, label: "B"},
%{value: 3, label: "C"}
])
stub_options(%{
"A" => 1,
"B" => 2,
"C" => 3
})

{:ok, live, _html} = live(conn, "/?mode=tags")

Expand All @@ -462,10 +462,7 @@ defmodule LiveSelectTagsTest do

select_nth_option(live, 2, method: :click)

stub_options([
%{value: 4, label: "D"},
%{value: 5, label: "E"}
])
stub_options(%{"D" => 4, "E" => 5})

type(live, "DEE")

Expand Down
14 changes: 7 additions & 7 deletions test/live_select_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -640,23 +640,23 @@ defmodule LiveSelectTest do
end

test "selection can be updated from the form", %{conn: conn} do
stub_options(
A: 1,
B: 2,
C: 3
)
stub_options(%{
"A" => 1,
"B" => 2,
"C" => 3
})

{:ok, live, _html} = live(conn, "/")

type(live, "ABC")

select_nth_option(live, 2)

assert_selected(live, :B, 2)
assert_selected(live, "B", 2)

render_change(live, "change", %{"my_form" => %{"city_search" => 1}})

assert_selected_static(live, :A, 1)
assert_selected_static(live, "A", 1)
end

for style <- [:daisyui, :tailwind, :none, nil] do
Expand Down

0 comments on commit d2cbfae

Please sign in to comment.