Skip to content
Snippets Groups Projects
Commit 2cc3d7b8 authored by Kerdo Kurs's avatar Kerdo Kurs
Browse files

add BDD #29

parent 33ac2853
No related branches found
No related tags found
2 merge requests!37Draft: Resolve "Implement simple search query",!35Implement tests for FR-19 and FR-20
Pipeline #46603 passed
......@@ -29,6 +29,7 @@ defmodule PropertySearchContext do
:ok,
state
|> Map.put(:email, existing_user[:email])
|> Map.put(:password, existing_user[:password])
}
end
......@@ -144,4 +145,34 @@ defmodule PropertySearchContext do
{:ok, state}
end
and_ ~r/^I am logged in$/, fn state ->
setup_session(state[:email], state[:password])
{:ok, state}
end
and_ ~r/^I want to search$/, fn state ->
navigate_to("/")
click({:id, "search"})
{:ok, state}
end
and_ ~r/^I perform a search$/, fn state ->
click({:id, "search_button"})
{:ok, state}
end
then_ ~r/^I should see a saved search query$/, fn state ->
assert visible_in_page? ~r/Previous searches/
el_count = length(find_all_elements(:class, "previous-search"))
assert el_count == 1
{:ok, state}
end
defp setup_session(email, password) do
navigate_to("/login")
fill_field({:id, "email"}, email)
fill_field({:id, "password"}, password)
click({:id, "login_button"})
end
end
......@@ -31,3 +31,17 @@ Feature: FR-13, FR-19 & FR-20: Property Search and Revisit
And I want to perform a search
When I click on the search button
Then I should see "3" properties
Scenario: Authenticated users should see saved search queries
Given there exists following accounts
| name | surname | birth_date | phone_number | email | password | confirm_password |
| Existing | Account | 2000-01-01 | 000 | existing.account@gmail.com | password | password |
And the following properties exist
| title | description | type | property_type | state | location | room_count | area | floor | floor_count | price |
| Rent property | Also a really cool property | rent | apartment | available | London, UK | 3 | 160.0 | 2 | 5 | 6000 |
And I am logged in
And I want to search
And I perform a search
And I want to search
Then I should see a saved search query
......@@ -77,6 +77,7 @@ defmodule PropTrackr.Search do
|> validate_required([:type, :location, :min_price, :max_price, :min_rooms, :max_rooms])
|> validate_minmax(:min_price, :max_price)
|> validate_minmax(:min_rooms, :max_rooms)
|> cast_areas()
end
defp validate_minmax(changeset, min_key, max_key) do
......@@ -89,4 +90,13 @@ defmodule PropTrackr.Search do
true -> changeset
end
end
defp cast_areas(changeset) do
areas = get_field(changeset, :areas)
if areas == nil do
put_change(changeset, :areas, [])
else
changeset
end
end
end
......@@ -12,7 +12,7 @@
<h3 class="font-bold">Previous searches</h3>
<ul>
<%= for search <- @previous_searches do %>
<li>
<li class="previous-search">
<.link navigate={"/search/#{search.id}"} class="underline">
<%= "#{search.type} in #{search.location} with #{Enum.join(search.areas, ", ")} areas, #{search.min_price} - #{search.max_price} € price range and #{search.min_rooms} - #{search.max_rooms} rooms" %>
</.link>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment