diff --git a/app/frontend/scss/components/checks.scss b/app/frontend/scss/components/checks.scss index 26f3f5d..f0e20e6 100644 --- a/app/frontend/scss/components/checks.scss +++ b/app/frontend/scss/components/checks.scss @@ -1,4 +1,4 @@ -.table-checks { +.checks-table { .action a { color: black; } diff --git a/app/helpers/checks_helper.rb b/app/helpers/checks_helper.rb index 81dfd3d..f779644 100644 --- a/app/helpers/checks_helper.rb +++ b/app/helpers/checks_helper.rb @@ -37,8 +37,9 @@ module ChecksHelper data: { toggle: "tooltip", placement: "bottom", - title: check_last_success_title(check) - }) + title: check_last_success_title(check), + }, + ) end def current_criterias diff --git a/app/views/checks/_filters.html.erb b/app/views/checks/_filters.html.erb index 1c84746..80e6b17 100644 --- a/app/views/checks/_filters.html.erb +++ b/app/views/checks/_filters.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/checks/_table.html.erb b/app/views/checks/_table.html.erb index a9d8cfc..fcda912 100644 --- a/app/views/checks/_table.html.erb +++ b/app/views/checks/_table.html.erb @@ -1,5 +1,5 @@
- +
diff --git a/test/system/.rubocop.yml b/test/system/.rubocop.yml new file mode 100644 index 0000000..229dd53 --- /dev/null +++ b/test/system/.rubocop.yml @@ -0,0 +1,4 @@ +inherit_from: ../../.rubocop.yml + +Metrics/ClassLength: + Enabled: false diff --git a/test/system/checks_test.rb b/test/system/checks_test.rb index e7be944..994346c 100644 --- a/test/system/checks_test.rb +++ b/test/system/checks_test.rb @@ -4,8 +4,6 @@ class ChecksTest < ApplicationSystemTestCase setup do @user = create(:user) login_as(@user) - - @check = create(:check, :with_notifications, user: @user) end test "create a check and a notification without kind" do @@ -33,12 +31,13 @@ class ChecksTest < ApplicationSystemTestCase end test "remove a notification" do - visit edit_check_path(@check) - notification = @check.notifications.first + check = create(:check, :with_notifications, domain: "dom-with-notif.net", user: @user) + visit edit_check_path(check) + notification = check.notifications.first selector = "[data-notification-id=\"#{notification.id}\"]" - assert_difference "Notification.where(check_id: #{@check.id}).count", -1 do + assert_difference "Notification.where(check_id: #{check.id}).count", -1 do within selector do find(".btn-danger").click end @@ -48,7 +47,8 @@ class ChecksTest < ApplicationSystemTestCase end test "update a check" do - visit edit_check_path(@check) + check = create(:check, :with_notifications, domain: "dom-with-notif.net", user: @user) + visit edit_check_path(check) fill_in "check[comment]", with: "My comment" @@ -57,18 +57,19 @@ class ChecksTest < ApplicationSystemTestCase assert_equal checks_path, page.current_path assert page.has_css?(".alert-success") - @check.reload - assert_equal "My comment", @check.comment + check.reload + assert_equal "My comment", check.comment end test "add a notification" do - visit edit_check_path(@check) + check = create(:check, :with_notifications, domain: "dom-with-notif.net", user: @user) + visit edit_check_path(check) recipient = "recipient2@example.org" fill_in("check[notifications_attributes][2][recipient]", with: recipient) fill_in("check[notifications_attributes][2][interval]", with: 55) - assert_difference "Notification.where(check_id: #{@check.id}).count", +1 do + assert_difference "Notification.where(check_id: #{check.id}).count", +1 do click_button "Update Check" assert_equal checks_path, page.current_path @@ -83,6 +84,176 @@ class ChecksTest < ApplicationSystemTestCase assert notification.pending? end + test "list my checks" do + create(:check, :domain, domain: "dom.com", domain_expires_at: Time.new(2018, 7, 5, 12), user: @user) # rubocop:disable Metrics/LineLength + create(:check, :ssl, domain: "ssldom.com", user: @user) + create(:check, :ssl, domain: "ssldom2.com", user: @user) + + visit checks_path + + within ".checks-table" do + assert page.has_content?("SSL", count: 2) + assert page.has_content?("Domain", count: 1) + end + + within ".check-row:first-of-type" do + assert page.has_content?("Domain") + assert page.has_content?("dom.com") + assert page.has_content?("Thursday, July 5, 2018") + end + end + + test "list filterable by domain and ssl" do + create_list(:check, 2, :domain, domain: "mydom.fr", user: @user) + create_list(:check, 1, :ssl, domain: "ssl.com", user: @user) + + visit checks_path + + assert page.has_css?(".check-row", count: 3) + + within ".checks-filters" do + click_on "Domain" + assert find_link("Domain").matches_css? ".active" + assert find_link("SSL").not_matches_css? ".active" + end + + within ".checks-table" do + assert page.has_css?(".check-row", count: 2) + assert page.has_content?("Domain", count: 2) + end + + within ".checks-filters" do + click_on "SSL" + assert find_link("SSL").matches_css? ".active" + assert find_link("Domain").not_matches_css? ".active" + end + + within ".checks-table" do + assert page.has_css?(".check-row", count: 1) + assert page.has_content?("SSL", count: 1) + assert page.has_content?("ssl.com") + end + end + + test "list filterable by check in error" do + create(:check, user: @user) + create(:check, :last_runs_failed, created_at: 1.week.ago, user: @user) + + visit checks_path + + within ".checks-table" do + assert page.has_css?(".check-row", count: 2) + assert page.has_css?(".in-error", count: 1) + end + + within ".checks-filters" do + click_on(I18n.t("checks.filters.with_error")) + end + + within ".checks-table" do + assert page.has_css?(".check-row", count: 1) + assert page.has_css?(".in-error", count: 1) + end + end + + test "list filterable by name string" do + create(:check, user: @user) + create(:check, domain: "chexpire.org", user: @user) + create(:check, domain: "chexpire.net", user: @user) + + visit checks_path + + within ".checks-filters" do + fill_in("by_domain", with: "chex") + click_button + end + + within ".checks-table" do + assert page.has_css?(".check-row", count: 2) + assert page.has_content?("chexpire.", count: 2) + end + end + + test "list is paginated" do + create(:check, user: @user) + + visit checks_path + assert page.has_no_css?("ul.pagination") + + create_list(:check, 50, user: @user) + + visit checks_path + assert page.has_css?("ul.pagination") + end + + test "list is sortable by name" do + visit checks_path + + create(:check, domain: "a.org", user: @user) + create(:check, domain: "b.org", user: @user) + + visit checks_path + + within ".checks-table thead th:nth-of-type(2)" do + find(".sort-links:first-child").click + end + + within ".check-row:first-of-type" do + page.has_content? "a.org" + end + + within ".checks-table thead th:nth-of-type(2)" do + find(".sort-links:last-child").click + end + + within ".check-row:first-of-type" do + page.has_content? "b.org" + end + end + + test "list is sorted by expiration date by default" do + visit checks_path + + create(:check, domain_expires_at: Time.new(2018, 7, 6, 12), user: @user) + create(:check, domain_expires_at: Time.new(2018, 7, 5, 12), user: @user) + + visit checks_path + + within ".check-row:first-of-type" do + page.has_content? "Thursday, July 5, 2018" + end + end + + test "list is sortable by expiration date" do + visit checks_path + + create(:check, domain_expires_at: Time.new(2018, 7, 5, 12), user: @user) + create(:check, domain_expires_at: Time.new(2018, 7, 6, 12), user: @user) + + visit checks_path + + within ".check-row:first-of-type" do + page.has_content? "Thursday, July 5, 2018" + end + + # only a desc link because of default sort + within ".checks-table thead th:nth-of-type(3)" do + find(".sort-links a").click + end + + within ".check-row:first-of-type" do + page.has_content? "Friday, July 6, 2018" + end + + within ".checks-table thead th:nth-of-type(3)" do + find(".sort-links a").click + end + + within ".check-row:first-of-type" do + page.has_content? "Thursday, July 5, 2018" + end + end + private # rubocop:disable Metrics/AbcSize