Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PropTrackr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kerdo
PropTrackr
Merge requests
!15
Resolve "FR-09: Update Property Advertisement"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "FR-09: Update Property Advertisement"
19-fr-09-update-property-advertisement
into
main
Overview
2
Commits
4
Pipelines
2
Changes
9
All threads resolved!
Hide all comments
Merged
shyngys
requested to merge
19-fr-09-update-property-advertisement
into
main
5 months ago
Overview
2
Commits
4
Pipelines
2
Changes
9
All threads resolved!
Hide all comments
Expand
Closes
#19 (closed)
0
0
Merge request reports
Compare
main
version 1
9ad14179
5 months ago
main (base)
and
latest version
latest version
e2e1a6cc
4 commits,
5 months ago
version 1
9ad14179
3 commits,
5 months ago
9 files
+
553
−
8
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
9
Search (e.g. *.vue) (Ctrl+P)
features/contexts/property_update_context.exs
0 → 100644
+
159
−
0
Options
defmodule
PropertyUpdateContext
do
use
WhiteBread
.
Context
use
Hound
.
Helpers
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
)
random_user
=
List
.
last
(
table
)
{
:ok
,
state
|>
Map
.
put
(
:email
,
existing_user
[
:email
])
|>
Map
.
put
(
:password
,
existing_user
[
:password
])
|>
Map
.
put
(
:random_email
,
random_user
[
:email
])
|>
Map
.
put
(
:random_password
,
random_user
[
:password
])
}
end
and_
~r/^the following properties exist$/
,
fn
state
,
%{
table_data:
table
}
->
logged_in_user
=
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
(
logged_in_user
,
: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 am logged in$/
,
fn
state
->
setup_session
(
state
[
:email
],
state
[
:password
])
{
:ok
,
state
}
end
and_
~r/^I navigate to my property's details page$/
,
fn
state
->
advertisement
=
List
.
first
(
state
[
:advertisements
])
click
({
:id
,
"edit-
#{
advertisement
.
reference
}
"
})
{
:ok
,
state
}
end
when_
~r/^I click the edit button$/
,
fn
state
->
click
({
:id
,
"edit-property"
})
{
:ok
,
state
}
end
and_
~r/^I update the following fields$/
,
fn
state
,
%{
table_data:
table
}
->
data
=
List
.
first
(
table
)
fill_field
({
:id
,
"title"
},
data
[
:title
])
fill_field
({
:id
,
"description"
},
data
[
:description
])
select_dropdown
(
"type"
,
data
[
:type
])
select_dropdown
(
"property_type"
,
data
[
:property_type
])
select_dropdown
(
"state"
,
data
[
:state
])
fill_field
({
:id
,
"location"
},
data
[
:location
])
fill_field
({
:id
,
"room_count"
},
data
[
:room_count
])
fill_field
({
:id
,
"area"
},
data
[
:area
])
fill_field
({
:id
,
"floor"
},
data
[
:floor
])
fill_field
({
:id
,
"price"
},
data
[
:price
])
{
:ok
,
state
|>
Map
.
put
(
:updated_data
,
data
)
}
end
and_
~r/^I click save changes$/
,
fn
state
->
click
({
:id
,
"save-changes"
})
{
:ok
,
state
}
end
then_
~r/^I should see a success message$/
,
fn
state
->
assert
visible_in_page?
~r/Property updated successfully./
{
:ok
,
state
}
end
and_
~r/^I should be redirected back to the property page$/
,
fn
state
->
advertisement
=
List
.
first
(
state
[
:advertisements
])
assert
current_path
()
==
"/properties/
#{
advertisement
.
reference
}
"
{
:ok
,
state
}
end
and_
~r/^I should see the updated property details$/
,
fn
state
->
advertisement
=
state
[
:updated_data
]
assert
visible_in_page?
~r/#{advertisement.title}/
assert
visible_in_page?
~r/#{advertisement.description}/
assert
visible_in_page?
~r/#{advertisement.type}/i
assert
visible_in_page?
~r/#{advertisement.property_type}/i
assert
visible_in_page?
~r/#{advertisement.location}/
assert
visible_in_page?
~r/#{advertisement.price}/
assert
visible_in_page?
~r/#{advertisement.room_count}/
assert
visible_in_page?
~r/#{advertisement.area}/
assert
visible_in_page?
~r/#{advertisement.floor}/
assert
visible_in_page?
~r/#{advertisement.state}/i
{
:ok
,
state
}
end
then_
~r/^I should see error message$/
,
fn
state
->
assert
visible_in_page?
~r/Oops, something went wrong! Please check the errors below./
{
:ok
,
state
}
end
and_
~r/^I should see the edit page again$/
,
fn
state
->
assert
visible_in_page?
~r/Edit Property/
{
:ok
,
state
}
end
and_
~r/^I am logged in as a random user who does not own the advertisement$/
,
fn
state
->
setup_session
(
state
[
:random_email
],
state
[
:random_password
])
{
:ok
,
state
}
end
and_
~r/^I navigate to the property's details page$/
,
fn
state
->
advertisement
=
List
.
first
(
state
[
:advertisements
])
click
({
:id
,
"edit-
#{
advertisement
.
reference
}
"
})
{
:ok
,
state
}
end
then_
~r/^I should not see an edit button$/
,
fn
state
->
assert
not
visible_in_page?
~r/Edit Property/
{
: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
# https://stackoverflow.com/a/49861811
defp
select_dropdown
(
drop_down_id
,
option
)
do
find_element
(
:css
,
"#
#{
drop_down_id
}
option[value='
#{
option
}
']"
)
|>
click
()
end
end
Loading