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

update BDD to match 3.2 and 3.3 #29

parent 2cc3d7b8
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
...@@ -168,6 +168,28 @@ defmodule PropertySearchContext do ...@@ -168,6 +168,28 @@ defmodule PropertySearchContext do
{:ok, state} {:ok, state}
end end
and_ ~r/^I go to the homepage$/, fn state ->
navigate_to("/")
{:ok, state}
end
then_ ~r/^I should not see a search button$/, fn state ->
refute visible_in_page? ~r/Search/
els = find_all_elements(:id, "search_button")
assert length(els) == 0
{:ok, state}
end
and_ ~r/^I go to the search URL$/, fn state ->
navigate_to("/search")
{:ok, state}
end
then_ ~r/^I should be redirected to the login page$/, fn state ->
assert current_path() == "/login"
{:ok, state}
end
defp setup_session(email, password) do defp setup_session(email, password) do
navigate_to("/login") navigate_to("/login")
fill_field({:id, "email"}, email) fill_field({:id, "email"}, email)
......
Feature: FR-13, FR-19 & FR-20: Property Search and Revisit Feature: FR-13, FR-19 & FR-20: Property Search and Revisit
Scenario: User should see filter options and boundaries for search Scenario: 3.2, 3.3 Authenticated user should see filter options and boundaries for search
Given there exists following accounts Given there exists following accounts
| name | surname | birth_date | phone_number | email | password | confirm_password | | name | surname | birth_date | phone_number | email | password | confirm_password |
| Existing | Account | 2000-01-01 | 000 | existing.account@gmail.com | password | password | | Existing | Account | 2000-01-01 | 000 | existing.account@gmail.com | password | password |
...@@ -10,6 +10,7 @@ Feature: FR-13, FR-19 & FR-20: Property Search and Revisit ...@@ -10,6 +10,7 @@ Feature: FR-13, FR-19 & FR-20: Property Search and Revisit
| Rent property | Also a really cool property | rent | apartment | available | London, UK | 3 | 160.0 | 2 | 5 | 6000 | | Rent property | Also a really cool property | rent | apartment | available | London, UK | 3 | 160.0 | 2 | 5 | 6000 |
| Rent property Tartu | Also a really cool property | rent | apartment | available | Tartu, Estonia | 2 | 120.0 | 1 | 2 | 800 | | Rent property Tartu | Also a really cool property | rent | apartment | available | Tartu, Estonia | 2 | 120.0 | 1 | 2 | 800 |
| Buy property Tartu | Also a really cool property | sell | apartment | available | Tartu, Estonia | 2 | 120.0 | 1 | 2 | 800000 | | Buy property Tartu | Also a really cool property | sell | apartment | available | Tartu, Estonia | 2 | 120.0 | 1 | 2 | 800000 |
And I am logged in
And I want to perform a search And I want to perform a search
Then I should see all countries of the properties in the filter options Then I should see all countries of the properties in the filter options
And I should see all cities of the properties in the filter options And I should see all cities of the properties in the filter options
...@@ -18,7 +19,7 @@ Feature: FR-13, FR-19 & FR-20: Property Search and Revisit ...@@ -18,7 +19,7 @@ Feature: FR-13, FR-19 & FR-20: Property Search and Revisit
And I should see a max room filter with the room count of the properties And I should see a max room filter with the room count of the properties
And I should see a min room filter with the room count of the properties And I should see a min room filter with the room count of the properties
Scenario: User should be able to search with default values Scenario: 3.2, 3.3 Authenticated user should be able to search with default values
Given there exists following accounts Given there exists following accounts
| name | surname | birth_date | phone_number | email | password | confirm_password | | name | surname | birth_date | phone_number | email | password | confirm_password |
| Existing | Account | 2000-01-01 | 000 | existing.account@gmail.com | password | password | | Existing | Account | 2000-01-01 | 000 | existing.account@gmail.com | password | password |
...@@ -28,11 +29,26 @@ Feature: FR-13, FR-19 & FR-20: Property Search and Revisit ...@@ -28,11 +29,26 @@ Feature: FR-13, FR-19 & FR-20: Property Search and Revisit
| Rent property | Also a really cool property | rent | apartment | available | London, UK | 3 | 160.0 | 2 | 5 | 6000 | | Rent property | Also a really cool property | rent | apartment | available | London, UK | 3 | 160.0 | 2 | 5 | 6000 |
| Rent property Tartu | Also a really cool property | rent | apartment | available | Tartu, Estonia | 2 | 120.0 | 1 | 2 | 800 | | Rent property Tartu | Also a really cool property | rent | apartment | available | Tartu, Estonia | 2 | 120.0 | 1 | 2 | 800 |
| Buy property Tartu | Also a really cool property | sell | apartment | available | Tartu, Estonia | 2 | 120.0 | 1 | 2 | 800000 | | Buy property Tartu | Also a really cool property | sell | apartment | available | Tartu, Estonia | 2 | 120.0 | 1 | 2 | 800000 |
And I am logged in
And I want to perform a search And I want to perform a search
When I click on the search button When I click on the search button
Then I should see "3" properties Then I should see "3" properties
Scenario: Authenticated users should see saved search queries Scenario: 3.2 Unauthenticated user should not see a search button
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 I go to the homepage
Then I should not see a search button
Scenario: 3.2 Unauthenticated user should be redirected to login when visiting search URL
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 I go to the search URL
Then I should be redirected to the login page
Scenario: 3.2 Authenticated users should see saved search queries
Given there exists following accounts Given there exists following accounts
| name | surname | birth_date | phone_number | email | password | confirm_password | | name | surname | birth_date | phone_number | email | password | confirm_password |
| Existing | Account | 2000-01-01 | 000 | existing.account@gmail.com | password | password | | Existing | Account | 2000-01-01 | 000 | existing.account@gmail.com | password | password |
...@@ -44,4 +60,3 @@ Feature: FR-13, FR-19 & FR-20: Property Search and Revisit ...@@ -44,4 +60,3 @@ Feature: FR-13, FR-19 & FR-20: Property Search and Revisit
And I perform a search And I perform a search
And I want to search And I want to search
Then I should see a saved search query Then I should see a saved search query
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
</.link> </.link>
<% end %> <% end %>
<%= if not @is_search do %> <%= if not @is_search and @conn.assigns[:current_user] do %>
<.link href={~p"/search"}> <.link href={~p"/search"}>
<.button type="button" class="text-white rounded px-4 py-2" id="search"> <.button type="button" class="text-white rounded px-4 py-2" id="search">
Search Search
......
...@@ -10,42 +10,51 @@ defmodule PropTrackrWeb.SearchController do ...@@ -10,42 +10,51 @@ defmodule PropTrackrWeb.SearchController do
alias PropTrackr.NotInterested alias PropTrackr.NotInterested
def index(conn, _params) do def index(conn, _params) do
min_price = from(p in Property, select: min(p.price)) |> Repo.one current_user = conn.assigns.current_user
max_price = from(p in Property, select: max(p.price)) |> Repo.one
min_rooms = 0
max_rooms = from(p in Property, select: max(p.room_count)) |> Repo.one
locations = from(p in Property, select: p.location) |> Repo.all if current_user do
cities = Enum.map(locations, fn location -> String.split(location, ",") |> hd |> String.trim() end) min_price = from(p in Property, select: min(p.price)) |> Repo.one
cities = Enum.uniq(cities) max_price = from(p in Property, select: max(p.price)) |> Repo.one
countries = Enum.map(locations, fn location -> String.split(location, ",") |> tl |> hd |> String.trim() end)
countries = Enum.uniq(countries)
changeset = Search.changeset(%Search{}) min_rooms = 0
max_rooms = from(p in Property, select: max(p.room_count)) |> Repo.one
current_user = conn.assigns.current_user locations = from(p in Property, select: p.location) |> Repo.all
previous_searches = case current_user do cities = Enum.map(locations, fn location -> String.split(location, ",") |> hd |> String.trim() end)
nil -> [] cities = Enum.uniq(cities)
_ -> countries = Enum.map(locations, fn location -> String.split(location, ",") |> tl |> hd |> String.trim() end)
Repo.all( countries = Enum.uniq(countries)
from s in Search,
where: s.user_id == ^current_user.id,
order_by: [desc: s.inserted_at]
)
end
render( changeset = Search.changeset(%Search{})
conn, "search.html",
changeset: changeset, current_user = conn.assigns.current_user
min_price: min_price, previous_searches = case current_user do
max_price: max_price, nil -> []
min_rooms: min_rooms, _ ->
max_rooms: max_rooms, Repo.all(
cities: cities, from s in Search,
countries: countries, where: s.user_id == ^current_user.id,
previous_searches: previous_searches order_by: [desc: s.inserted_at]
) )
end
render(
conn, "search.html",
changeset: changeset,
min_price: min_price,
max_price: max_price,
min_rooms: min_rooms,
max_rooms: max_rooms,
cities: cities,
countries: countries,
previous_searches: previous_searches
)
else
conn
|> put_flash(:error, "You are not logged in")
|> redirect(to: "/login")
end
end end
def create(conn, %{ "search" => search }) do def create(conn, %{ "search" => search }) do
......
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