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

implement BDD #28

parent 34129b22
No related branches found
No related tags found
1 merge request!19Resolve "FR-18: Display Similar Properties on Listing View"
defmodule WhiteBreadConfig do
use WhiteBread.SuiteConfiguration
suite name: "User Registration Features",
context: UserRegistrationContext,
feature_paths: ["features/user_registration.feature"]
......@@ -57,4 +56,8 @@ defmodule WhiteBreadConfig do
suite name: "FR-15 View List of Favorite Properties",
context: FavoriteProperties,
feature_paths: ["features/favorite_properties.feature"]
suite name: "FR-18 Display Similar Properties on Listing View",
context: SimilarPropertiesContext,
feature_paths: ["features/similar_properties_view.feature"]
end
defmodule SimilarPropertiesContext do
use WhiteBread.Context
use Hound.Helpers
alias PropTrackr.Accounts
alias PropTrackr.Repo
alias PropTrackr.Accounts.User
alias PropTrackr.Properties.Property
scenario_starting_state fn _state ->
Ecto.Adapters.SQL.Sandbox.checkout(PropTrackr.Repo)
Ecto.Adapters.SQL.Sandbox.mode(PropTrackr.Repo, {:shared, self()})
Hound.start_session()
%{}
end
scenario_finalize fn _status, _state ->
Ecto.Adapters.SQL.Sandbox.checkin(PropTrackr.Repo)
Hound.end_session()
end
given_ ~r/^there exists following accounts$/, fn state, %{table_data: table} ->
table
|> Enum.map(fn user_details -> User.changeset(%User{}, user_details) end)
|> Enum.each(fn changeset -> Repo.insert!(changeset) end)
existing_user = List.first(table)
{
:ok,
state
|> Map.put(:email, existing_user[:email])
|> Map.put(:password, existing_user[:password])
|> Map.put(:user_id, existing_user[:id])
}
end
and_ ~r/^the following properties exist$/, fn state, %{table_data: table} ->
owner = Repo.get_by(User, email: state[:email])
advertisements =
table
|> Enum.map(fn details -> details |> Map.put(:reference, Ecto.UUID.generate()) end)
|> Enum.map(fn details -> {Ecto.build_assoc(owner, :properties, details), details} end)
|> Enum.map(fn {assoc, details} -> Property.changeset(assoc, details) end)
|> Enum.map(fn changeset -> Repo.insert!(changeset) end)
{
:ok,
state
|> Map.put(:advertisements, advertisements)
}
end
and_ ~r/^I go to the property page for "(?<title>[^"]+)"$/, fn state, %{title: title} ->
advertisement = Enum.find(state.advertisements, fn advertisement -> advertisement.title == title end)
navigate_to("/properties/#{advertisement.reference}")
{:ok, state}
end
then_ ~r/^I should see a message that there are no similar properties$/, fn state ->
assert visible_in_page? ~r/No similar properties found/
{:ok, state}
end
then_ ~r/^I should see only 5 similar properties$/, fn state ->
assert length(find_all_elements(:class, "similar-property")) == 5
{:ok, state}
end
then_ ~r/^I should see the all similar properties$/, fn state ->
assert length(find_all_elements(:class, "similar-property")) == length(state.advertisements) - 1
state[:advertisements] |> Enum.each(fn advertisement ->
assert visible_in_page? ~r/#{advertisement.title}/
assert visible_in_page? ~r/#{:erlang.float_to_binary(advertisement.price, decimals: 2)}/
assert visible_in_page? ~r/#{advertisement.location}/
end)
{:ok, state}
end
and_ ~r/^I click on View More for "(?<title>[^"]+)"$/, fn state, %{title: title} ->
advertisement = Enum.find(state.advertisements, fn advertisement -> advertisement.title == title end)
click({:id, "view-similar-property-#{advertisement.reference}"})
{:ok, state}
end
then_ ~r/^I should be redirected to the property page for "(?<title>[^"]+)"$/, fn state, %{title: title} ->
advertisement = Enum.find(state.advertisements, fn advertisement -> advertisement.title == title end)
assert current_path() == "/properties/#{advertisement.reference}"
assert visible_in_page? ~r/#{advertisement.title}/
{:ok, state}
end
end
Feature: FR-18 Display Similar Properties on Listing View
Scenario: User should see empty message when no other properties exist
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 |
| Really cool property | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
And I go to the property page for "Really cool property"
Then I should see a message that there are no similar properties
Scenario: User should not see a similar property that is not in available state
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 |
| Really cool property | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
| Really cool property 2 | Selling this really really house | sell | house | reserved | London | 3 | 100.0 | 2 | 5 | 500000 |
| Really cool property 3 | Selling this really really house | sell | house | unavailable | London | 3 | 100.0 | 2 | 5 | 500000 |
And I go to the property page for "Really cool property"
Then I should see a message that there are no similar properties
Scenario: User should see similar properties
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 |
| Really cool property | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
| Really cool property 2 | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
| Really cool property 3 | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
And I go to the property page for "Really cool property"
Then I should see the all similar properties
Scenario: User should not see more than 5 similar properties
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 |
| Really cool property | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
| Really cool property 2 | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
| Really cool property 3 | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
| Really cool property 4 | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
| Really cool property 5 | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
| Really cool property 6 | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
| Really cool property 7 | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
And I go to the property page for "Really cool property"
Then I should see only 5 similar properties
Scenario: User should be redirected to the property page when clicking on a similar property View More 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 the following properties exist
| title | description | type | property_type | state | location | room_count | area | floor | floor_count | price |
| Really cool property | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
| Really cool property 2 | Selling this really really house | sell | house | available | London | 3 | 100.0 | 2 | 5 | 500000 |
And I go to the property page for "Really cool property"
And I click on View More for "Really cool property 2"
Then I should be redirected to the property page for "Really cool property 2"
......@@ -111,7 +111,7 @@
<p class="text-sm text-gray-600">No similar properties found</p>
<% else %>
<%= for property <- @similar_properties do %>
<div class="flex items-center justify-between mt-4">
<div class="flex items-center justify-between mt-4 similar-property">
<div>
<p class="text-sm text-gray-600"><%= property.title %></p>
<p class="text-sm text-gray-600"><%= :erlang.float_to_binary(property.price, decimals: 2) %></p>
......
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