Skip to content

Commit

Permalink
Test for Targets One Parent action (#813)
Browse files Browse the repository at this point in the history
* Fix: Wrong string replacement

* Setup targets-one-parent action models test

* Targets One Parent Action test

* Fix Standard
  • Loading branch information
newstler authored Aug 2, 2023
1 parent f821960 commit 71891df
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
17 changes: 15 additions & 2 deletions test/bin/setup-action-models-system-test
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if [ -z "${CIRCLE_NODE_INDEX}" ] || [ "${CIRCLE_NODE_INDEX}" == "0" ]; then
TARGETS_MANY_ACTION='project.update(name: "#{project.name} archived")'
PERFORM_METHOD_WITH_CONTENT=" def perform_on_target(project)\n ${TARGETS_MANY_ACTION}"

test/bin/portable-string-replace app/models/projects/archive_action.rb "# This is where you implement the operation you want to perform on each target." "project.update(name: \"#{project.name} archived\")"
test/bin/portable-string-replace app/models/projects/archive_action.rb "# This is where you implement the operation you want to perform on the action's target." "project.update(name: \"#{project.name} archived\")"
else
echo "Skipping the \`targets-many\` action on this CI node."
fi
Expand All @@ -28,11 +28,24 @@ if [ -z "${CIRCLE_NODE_INDEX}" ] || [ "${CIRCLE_NODE_INDEX}" == "1" ]; then
rails db:migrate
bin/super-scaffold action-model:targets-one Publish Listing Team

test/bin/portable-string-replace app/models/projects/archive_action.rb "# This is where you implement the operation you want to perform on each target." "listing.update(name: \"#{listing.name} published\")"
test/bin/portable-string-replace app/models/projects/archive_action.rb "# This is where you implement the operation you want to perform on the action's target." "listing.update(name: \"#{listing.name} published\")"
else
echo "Skipping the \`targets-one\` action on this CI node."
fi

if [ -z "${CIRCLE_NODE_INDEX}" ] || [ "${CIRCLE_NODE_INDEX}" == "3" ]; then
bundle exec spring rails g model Customer team:references name:string
bin/super-scaffold crud Customer Team name:text_field --sidebar="ti.ti-user"
bundle exec spring rails g model Notification customer:references text:string read:boolean
bin/super-scaffold crud Notification Customer,Team text:text_field read:boolean --sidebar="ti.ti-email"
rails db:migrate
bin/super-scaffold action-model:targets-one-parent MarkAllAsRead Notification Customer

test/bin/portable-string-replace app/models/notifications/mark_all_as_read_action.rb "# This is where you implement the operation you want to perform on the target." "customer.notifications.update(read: true)"
else
echo "Skipping the \`targets-one-parent\` action on this CI node."
fi

if [ -z "${CIRCLE_NODE_INDEX}" ] || [ "${CIRCLE_NODE_INDEX}" == "2" ]; then
bundle exec spring rails g model Article team:references name:string
bin/super-scaffold crud Article Team name:text_field --sidebar="ti.ti-world"
Expand Down
38 changes: 38 additions & 0 deletions test/system/action_models_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def setup
[
"Projects::ArchiveAction",
"Listings::PublishAction",
"Notifications::MarkAllAsReadAction",
"Articles::CsvImportAction"
].each do |class_name|
class_name.constantize
Expand Down Expand Up @@ -123,6 +124,43 @@ def setup
end
end

# targets-one-parent action
if defined?(Notifications::MarkAllAsReadAction)
test "developers can mark as read all notifications of a customer" do
login_as(@jane, scope: :user)
visit account_team_path(@jane.current_team)

3.times do |n|
click_on "Add New Customer"
fill_in "Name", with: "Test Customer #{n}"
click_on "Create Customer"
assert page.has_content? "Customer was successfully created."

3.times do |i|
click_on "Add New Notification"
fill_in "Text", with: "Test Notification #{i}"
click_on "Create Notification"
assert page.has_content? "Notification was successfully created."
click_on "Back"
end

# TODO: "Back" button didn't work here
click_on "Customers"
end

click_on "Test Customer 1"

# Developers can click "Mark All As Read" on a multiple records.
assert page.has_content?("Mark All As Read")
click_on "Mark All As Read"

# Confirm action page
click_on "Perform Mark All As Read Action"

assert page.has_content?("Mark All As Read Action was successfully created.")
end
end

# performs-import action
if defined?(Articles::CsvImportAction)
test "developers can import CSV file information to their records" do
Expand Down

0 comments on commit 71891df

Please sign in to comment.