Skip to content

Commit

Permalink
system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neonwatty committed Nov 5, 2024
1 parent a3fdd7b commit 61c44ac
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 47 deletions.
6 changes: 3 additions & 3 deletions rails_app/app/controllers/settings/image_paths_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def create
@image_path = ImagePath.new(image_path_params)
respond_to do |format|
if @image_path.save
flash[:notice] = "Image path was successfully created."
flash[:notice] = "Directory path successfully created!"
format.html { redirect_to [ :settings, @image_path ] }
else
flash[:alert] = @image_path.errors.full_messages[0]
Expand All @@ -39,7 +39,7 @@ def create
def update
respond_to do |format|
if @image_path.update(image_path_params)
flash[:notice] = "Image path was updated succesfully."
flash[:notice] = "Directory path updated succesfully!"
format.html { redirect_to [ :settings, @image_path ], notice: "Image path was successfully updated." }
else
flash[:alert] = @image_path.errors.full_messages[0]
Expand All @@ -53,7 +53,7 @@ def destroy
@image_path.destroy!

respond_to do |format|
flash[:notice] = "Image path was successfully destroyed."
flash[:notice] = "Directory path successfully destroyed!"
format.html { redirect_to [ :settings, :image_paths ], status: :see_other }
end
end
Expand Down
2 changes: 1 addition & 1 deletion rails_app/app/views/settings/image_paths/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
enter a valid subdirectory in /public/memes (browser cannot verify its validity)
</div>
<div>
<%= form.text_field :name, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-1/2 text-black" %>
<%= form.text_field :name, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-1/2 text-black", id: "new_image_path_text_area" %>
</div>
</div>
<div class="inline">
Expand Down
2 changes: 1 addition & 1 deletion rails_app/app/views/settings/image_paths/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<h1 class="font-bold text-4xl">Editing image path</h1>
<%= render "form", image_path: @image_path %>
<%= link_to "Back", [:settings, @image_path], class: "show-button" %>
<%= link_to "Back to image paths", [:settings, :image_paths], class: "back-button" %>
<%= link_to "Back to directory paths", [:settings, :image_paths], class: "back-button" %>
</div>
7 changes: 3 additions & 4 deletions rails_app/app/views/settings/image_paths/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<div class="w-full h-screen">
<div class="flex flex-row items-center justify-between w-full border border-b-2 border-t-0 border-r-0 border-l-0 border-black dark:border-white">
<h1 class="font-bold text-4xl mb-2">Image paths</h1>
<h1 class="font-bold text-4xl mb-2">Current directory paths</h1>
<div class="flex ml-16 mb-2">
<%= link_to "Create new image path",[:new, :settings, :image_path], class: "new-button" %>
<%= link_to "Back to settings",[:settings], class: "back-button" %>
<%= link_to "Create new",[:new, :settings, :image_path], class: "new-button" %>
</div>
</div>
<div id="image_paths" class="min-w-full h-full flex flex-col items-start">
<% @image_paths.each do |image_path| %>
<div class="flex flex-row">
<%= render image_path %>
<div class="mt-7 ml-5 text-black">
<%= link_to "Adjust / delete this image path", [:settings, image_path], class: "bg-fuchsia-200 p-2 rounded-2xl" %>
<%= link_to "Adjust / delete", [:settings, image_path], class: "bg-fuchsia-200 p-2 rounded-2xl" %>
</div>
</div>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions rails_app/app/views/settings/image_paths/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="font-bold text-4xl">New image path</h1>
<h1 class="font-bold text-4xl">New directory path</h1>
<%= render "form", image_path: @image_path %>
<%= link_to "Back to image paths", [:settings, :image_paths], class: "back-button" %>
<%= link_to "Back to directory paths", [:settings, :image_paths], class: "back-button" %>
</div>
6 changes: 3 additions & 3 deletions rails_app/app/views/settings/image_paths/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="mx-auto md:w-2/3 w-full flex">
<div class="mx-auto">
<%= render @image_path %>
<%= link_to "Edit this image path", [:edit, :settings, @image_path], class: "edit-button" %>
<%= link_to "Back to image paths", [:settings, :image_paths], class: "back-button" %>
<%= link_to "Edit this directory path", [:edit, :settings, @image_path], class: "edit-button" %>
<%= link_to "Back to directory paths", [:settings, :image_paths], class: "back-button" %>
<div class="inline-block ml-2">
<%= button_to "Destroy this image path", [:settings, @image_path], method: :delete, data: { confirm: 'Are you sure?' }, class: "delete-button" %>
<%= button_to "Destroy this directory path", [:settings, @image_path], method: :delete, data: { confirm: 'Are you sure?' }, class: "delete-button" %>
</div>
</div>
</div>
3 changes: 1 addition & 2 deletions rails_app/app/views/settings/tag_names/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<div class="flex flex-row items-center justify-between w-full border border-b-2 border-t-0 border-r-0 border-l-0 border-black dark:border-white">
<h1 class="font-bold text-4xl mb-2">Current tags</h1>
<div class="flex ml-16 mb-2">
<%= link_to "Create new tag",[:new, :settings, :tag_name], class: "new-button" %>
<%= link_to "Back to settings",[:settings], class: "back-button" %>
<%= link_to "Create new",[:new, :settings, :tag_name], class: "new-button" %>
</div>
</div>
<% content_for :title, "Current tags" %>
Expand Down
89 changes: 62 additions & 27 deletions rails_app/test/system/image_paths_test.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,76 @@
require "application_system_test_case"

class ImagePathsTest < ApplicationSystemTestCase
setup do
@image_path = image_paths(:one)
end

test "visiting the index" do
visit image_paths_url
assert_selector "h1", text: "Image paths"
end
test "visiting the index, create a new path, edit it, and delete it" do
# visit url directly
visit settings_image_paths_url
assert_selector "h1", text: "Current directory paths"

test "should create image path" do
visit image_paths_url
click_on "New image path"
# navigate via settings --> tag_names
assert_selector "ul#navigation" do
assert_selector "li#settings" do
click_on "Settings"
assert_selector "div", text: "Paths"
click_on "Paths"
sleep(0.5)
assert_selector "h1", text: "Current directory paths"
end
end

fill_in "Image path", with: @image_path.image_path
click_on "Create Image path"
# count total number of original current paths
divs_with_path_name_id = all("div[id^='image_path_']")
first_path_count = divs_with_path_name_id.count

assert_text "Image path was successfully created"
click_on "Back"
end
# click on "Create New"
click_on "Create new"
assert_selector "h1", text: "New directory path"

test "should update Image path" do
visit image_path_url(@image_path)
click_on "Edit this image path", match: :first
# enter name for new tag and create
fill_in "new_image_path_text_area", with: "test_path"
click_on "Save"
sleep(0.25)
assert_selector "div", text: "Directory path successfully created!"

fill_in "Image path", with: @image_path.image_path
click_on "Update Image path"
# # return to tags list
# click_on "Back to tags"
# sleep(0.2)
# divs_with_tag_name_id = all("div[id^='tag_name_']")
# second_tag_count = divs_with_tag_name_id.count

assert_text "Image path was successfully updated"
click_on "Back"
end
# # make sure current tag count is +1 of starting tag count
# assert second_tag_count == first_tag_count + 1

# # edit tag
# click_on "Adjust / delete", match: :first
# sleep(0.2)
# click_on "Edit this tag"
# sleep(0.2)
# fill_in "new_tag_name_text_area", with: "another_test_tag"
# click_on "Save"
# sleep(0.2)
# assert_selector "div", text: "Tag successfully updated!"
# click_on "Back to tags"
# sleep(0.2)

# # count number of tags
# divs_with_tag_name_id = all("div[id^='tag_name_']")
# third_tag_count = divs_with_tag_name_id.count
# assert third_tag_count == second_tag_count

# # delete tag
# click_on "Adjust / delete", match: :first
# sleep(0.2)
# accept_alert do
# click_on "Delete this tag"
# end
# sleep(0.2)
# assert_selector "div", text: "Tag successfully deleted!"

test "should destroy Image path" do
visit image_path_url(@image_path)
click_on "Destroy this image path", match: :first
# # count number of tags - assert the same as start
# divs_with_tag_name_id = all("div[id^='tag_name_']")
# fourth_tag_count = divs_with_tag_name_id.count
# assert fourth_tag_count == first_tag_count

assert_text "Image path was successfully destroyed"
end
end
5 changes: 1 addition & 4 deletions rails_app/test/system/tag_names_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require "application_system_test_case"

class TagNamesTest < ApplicationSystemTestCase
setup do
@tag_name = tag_names(:one)
end

test "visiting the index, create a new tag, edit it, and delete it" do
# visit url directly
Expand All @@ -26,7 +23,7 @@ class TagNamesTest < ApplicationSystemTestCase
first_tag_count = divs_with_tag_name_id.count

# click on "Create New"
click_on "Create new tag"
click_on "Create new"
assert_selector "h1", text: "New tag"

# enter name for new tag and create
Expand Down

0 comments on commit 61c44ac

Please sign in to comment.