crmne / cluster-headache-tracker

Cluster Headache Tracker is a free, open-source web application designed to help individuals suffering from cluster headaches track and manage their condition. By providing detailed logging, visual insights, and easy sharing with healthcare providers, this tool aims to improve the understanding and treatment of cluster headaches.
https://clusterheadachetracker.com
GNU General Public License v3.0
12 stars 2 forks source link

Tests pass when running `rails test test:system` but don't when using `git push` or in GitHub CI #67

Closed crmne closed 2 weeks ago

crmne commented 2 weeks ago

Describe the bug When running rails test test:system tests pass successfully, but not when using git push, which fires up the tests via overcommit, or in GitHub CI.

To Reproduce Steps to reproduce the behavior:

  1. git push

Expected behavior Tests passing.

Screenshots failures_test_visiting_the_index failures_test_marking_ongoing_headache_as_complete failures_test_generating_and_copying_share_link failures_test_filtering_headache_logs failures_test_creating_a_new_headache_log failures_test_filtering_chart_data failures_test_charts_show_no_data_message_when_filtered_with_no_results

Desktop (please complete the following information):

Additional context GitHub CI logs: https://github.com/crmne/cluster-headache-tracker/actions/runs/11583716798/job/32249432330

These are the git push logs:

$ git push
Running pre-push hooks
Check for security vulnerabilities.........................[Brakeman] OK
Upload files tracked by Git LFS..............................[GitLfs] OK
Run Minitest test suite....................................[Minitest] FAILED
Running 42 tests in a single process (parallelization threshold is 50)
Run options: --seed 47316

# Running:

........Capybara starting Puma...
* Version 6.4.3, codename: The Eagle of Durango
* Min threads: 0, max threads: 4
* Listening on http://127.0.0.1:40851
[Screenshot Image]: /home/carmine/Code/Personal/cluster-headache-tracker/tmp/screenshots/failures_test_charts_show_no_data_message_when_filtered_with_no_results.png
E

Error:
ChartsTest#test_charts_show_no_data_message_when_filtered_with_no_results:
Capybara::ElementNotFound: Unable to find visible link or button "Filters"
    test/system/charts_test.rb:35:in `block in <class:ChartsTest>'

bin/rails test test/system/charts_test.rb:33

[Screenshot Image]: /home/carmine/Code/Personal/cluster-headache-tracker/tmp/screenshots/failures_test_filtering_chart_data.png
E

Error:
ChartsTest#test_filtering_chart_data:
Capybara::ElementNotFound: Unable to find visible link or button "Filters"
    test/system/charts_test.rb:22:in `block in <class:ChartsTest>'

bin/rails test test/system/charts_test.rb:20

.....[Screenshot Image]: /home/carmine/Code/Personal/cluster-headache-tracker/tmp/screenshots/failures_test_creating_a_new_headache_log.png
E

Error:
HeadacheLogsTest#test_creating_a_new_headache_log:
Capybara::ElementNotFound: Unable to find field "Start time" that is not disabled
    test/system/headache_logs_test.rb:22:in `block in <class:HeadacheLogsTest>'

bin/rails test test/system/headache_logs_test.rb:18

.[Screenshot Image]: /home/carmine/Code/Personal/cluster-headache-tracker/tmp/screenshots/failures_test_filtering_headache_logs.png
E

Error:
HeadacheLogsTest#test_filtering_headache_logs:
Capybara::ElementNotFound: Unable to find visible link or button "Filters"
    test/system/headache_logs_test.rb:64:in `block in <class:HeadacheLogsTest>'

bin/rails test test/system/headache_logs_test.rb:62

[Screenshot Image]: /home/carmine/Code/Personal/cluster-headache-tracker/tmp/screenshots/failures_test_generating_and_copying_share_link.png
E

Error:
HeadacheLogsTest#test_generating_and_copying_share_link:
Capybara::ElementNotFound: Unable to find link or button "Share with Healthcare Provider"
    test/system/headache_logs_test.rb:77:in `block in <class:HeadacheLogsTest>'

bin/rails test test/system/headache_logs_test.rb:75

[Screenshot Image]: /home/carmine/Code/Personal/cluster-headache-tracker/tmp/screenshots/failures_test_marking_ongoing_headache_as_complete.png
E

Error:
HeadacheLogsTest#test_marking_ongoing_headache_as_complete:
Capybara::ElementNotFound: Unable to find field "End time" that is not disabled
    test/system/headache_logs_test.rb:55:in `block in <class:HeadacheLogsTest>'

bin/rails test test/system/headache_logs_test.rb:47

.[Screenshot Image]: /home/carmine/Code/Personal/cluster-headache-tracker/tmp/screenshots/failures_test_visiting_the_index.png
F

Failure:
HeadacheLogsTest#test_visiting_the_index [test/system/headache_logs_test.rb:13]:
expected to find css "h1" but there were no matches

bin/rails test test/system/headache_logs_test.rb:11

....................

Finished in 23.409421s, 1.7941 runs/s, 3.3747 assertions/s.
42 runs, 79 assertions, 1 failures, 6 errors, 0 skips
DEPRECATION WARNING: `to_time` will always preserve the full timezone rather than offset of the receiver in Rails 8.0. To opt in to the new behavior, set `config.active_support.to_time_preserves_timezone = :zone`. (called from <top (required)> at /home/carmine/Code/Personal/cluster-headache-tracker/config/environment.rb:5)
DEPRECATION WARNING: `to_time` will always preserve the full timezone rather than offset of the receiver in Rails 8.0. To opt in to the new behavior, set `config.active_support.to_time_preserves_timezone = :zone`. (called from <top (required)> at /home/carmine/Code/Personal/cluster-headache-tracker/config/environment.rb:5)

✗ One or more pre-push hooks failed

error: failed to push some refs to 'github.com:crmne/cluster-headache-tracker.git'
PhilTee commented 2 weeks ago

Still trying to get my local env set up to run (Rails 8, nice!)

I'm looking at your test/system/headache_logs_test.rb file, and at the fill_in method calls on lines 22 and 55 I think fill_in is case-sensitive, so it is looking for "Start time" and "End time", when the screen shots have an uppercase T in Time for both fields.

I'll see if I can confirm once my old clunky MacBook has finished updating rbenv and installing Ruby 3.3.5

PhilTee commented 2 weeks ago

Yeah, I've got test/system/headache_logs_test.rb passing now. I don't think I have permissions to push up a branch though. I'll call it a day for now, as it's almost 1AM here 😴

diff --git a/test/system/headache_logs_test.rb b/test/system/headache_logs_test.rb
index 4d5febc..dd46230 100644
--- a/test/system/headache_logs_test.rb
+++ b/test/system/headache_logs_test.rb
@@ -10,7 +10,7 @@ class HeadacheLogsTest < ApplicationSystemTestCase

   test "visiting the index" do
     visit headache_logs_url
-    assert_selector "h1", text: "Headache Logs"
+    assert_selector "div.navbar-center", text: "Headache Logs"
     assert_selector ".stats", count: 1
     assert_selector ".card", minimum: 1
   end
@@ -19,7 +19,7 @@ class HeadacheLogsTest < ApplicationSystemTestCase
     visit headache_logs_url
     click_on "New"

-    fill_in "Start time", with: Time.current.strftime("%Y-%m-%dT%H:%M")
+    fill_in "Start Time", with: Time.current.strftime("%Y-%m-%dT%H:%M")
     fill_in "Intensity", with: 7
     fill_in "Medication", with: "Sumatriptan + Oxygen"
     fill_in "Triggers", with: "Lack of sleep, Stress"
@@ -52,7 +52,7 @@ class HeadacheLogsTest < ApplicationSystemTestCase
     assert_text "Ongoing"

     click_on "Update Log"
-    fill_in "End time", with: Time.current.strftime("%Y-%m-%dT%H:%M")
+    fill_in "End Time", with: Time.current.strftime("%Y-%m-%dT%H:%M")
     click_on "Update Headache log"

     assert_text "Headache log was successfully updated"
@@ -61,8 +61,8 @@ class HeadacheLogsTest < ApplicationSystemTestCase

   test "filtering headache logs" do
     visit headache_logs_url
-    click_on "Filters"
-
+    open_accordion("filters")
+
     fill_in "Start Date", with: Date.yesterday
     fill_in "End Date", with: Date.tomorrow
     fill_in "Triggers", with: "Sleeping"
@@ -74,8 +74,8 @@ class HeadacheLogsTest < ApplicationSystemTestCase

   test "generating and copying share link" do
     visit headache_logs_url
-    click_on "Share with Healthcare Provider"
-    click_on "Generate Share Link"
+    open_accordion("share")
+    click_on "Generate New Link"

     assert_text "Share link generated successfully"

@@ -92,4 +92,12 @@ class HeadacheLogsTest < ApplicationSystemTestCase

     assert_text "Successfully imported"
   end
+
+  def open_accordion(data_attribute)
+    # Locate the accordion using the data attribute selector
+    accordion = find("details[data-accordion=\"#{data_attribute}\"]")
+    accordion.click
+
+    assert_selector "details[open][data-accordion=\"#{data_attribute}\"]"
+  end
 end
crmne commented 2 weeks ago

Hi @PhilTee thank you so much for the fix!

In order to push a fix you need to make a Pull Request, which will enable you to get credit for your work since your name will be associated with the commit, and will enable me to do a code review. Here's the step by step guide:

  1. Fork this repo
  2. Push the fix in your repos main branch
  3. Open a PR to this repo
PhilTee commented 2 weeks ago

Haha! Sorry, I forgot to fork the repo first! The dangers of playing at silly o'clock! I'll get this done later today. Have a good one! 🙌🏻

PhilTee commented 2 weeks ago

PR submitted for this issue here: https://github.com/crmne/cluster-headache-tracker/pull/69

All tests passing within the PR, including the system tests. fill_in issue resolved added helper method to ApplicationSystemTestCase allowing Capybara to open accordions

Logic of one test has had to be changed in the generating and copying share link test. The user already had a share link, so when the modal is opened the Generate New Link button is displayed instead of the Generate Share Link button. Hope that's ok.

crmne commented 2 weeks ago

Great work @PhilTee !

PhilTee commented 2 weeks ago

Great work @PhilTee !

Thanks! Anything else I can take a look at?

crmne commented 2 weeks ago

Thanks! Anything else I can take a look at?

Thank you! There's this issue about a new feature that would introduce separate medication tracking from headache tracking. The concept is not fully fleshed out, and the UI would need to be thought about more in depth, but happy to have discussions on the other issue about it!