Skip to content

Commit

Permalink
Merge branch 'cbj/trip-planner-input-errors' into cbj/trip-planner-in…
Browse files Browse the repository at this point in the history
…put-improvements
  • Loading branch information
thecristen committed Feb 5, 2025
2 parents 8d40e15 + 64893a8 commit 6bf251b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions assets/ts/ui/autocomplete/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,11 @@ const TRIP_PLANNER = ({
pushToLiveView({});
},
onStateChange({ prevState, state }) {
// Send changed input text to LiveView
if (state.query !== prevState.query) {
const newInputData = state.query === "" ? {} : { name: state.query };
const isCleared = state.query === "";
const changedToClosedState = prevState.isOpen && !state.isOpen;
// Send changed input text to LiveView when leaving this input
if (changedToClosedState) {
const newInputData = isCleared ? {} : { name: state.query };
pushToLiveView(newInputData);
}
},
Expand Down
17 changes: 17 additions & 0 deletions test/dotcom/trip_plan/input_form_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ defmodule Dotcom.TripPlan.InputFormTest do
refute changeset.errors[:from]
end

test "adds error if invalid location" do
changeset =
InputForm.changeset(%{
"to" => %{
"latitude" => "",
"longitude" => "",
"name" => Faker.Cat.breed(),
"stop_id" => ""
}
})

refute changeset.valid?

expected_error = InputForm.error_message(:to)
assert {^expected_error, _} = changeset.errors[:to]
end

test "adds error if from & to are the same" do
changeset =
InputForm.changeset(%{
Expand Down

0 comments on commit 6bf251b

Please sign in to comment.