Skip to content

Commit

Permalink
Fix weird refute_text failure
Browse files Browse the repository at this point in the history
  • Loading branch information
iHiD committed Dec 3, 2024
1 parent 92e30c4 commit 446a66c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
18 changes: 18 additions & 0 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ def assert_html(html, within: "body")
assert_includes formatted_context, formatted_html, error_msg
end

# refute_text proxies to this, so it's better to override
# this than it is to override refute_text directly.
def assert_no_text(text, **options)
# If React's not fully loaded then things incorectly not
# be there. This isn't an issue with assert_text as that
# has the waiting built in. But for this, where it will
# immediately succeed if the text doesn't exist, we end
# in scenarios where it refutes the text simply because
# React hasn't loaded yet. We have the instance variable
# so that we only do this once per test.
unless @give_react_time_to_load
sleep(1)
@give_react_time_to_load = true
end

super(:visible, text, **options)
end

def assert_text(text, **options)
options[:normalize_ws] = true unless options.key?(:normalize_ws)
super(:visible, text, **options)
Expand Down
6 changes: 4 additions & 2 deletions test/system/components/seniority_survey_modal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Components
class SenioritySurveyModalTest < ApplicationSystemTestCase
test "shows it on dashboard page" do
user = create :user, seniority: nil
create(:user_dismissed_introducer, user:, slug: "welcome-modal")

use_capybara_host do
Exercism.without_bullet do
sign_in!(user)
Expand All @@ -14,16 +16,16 @@ class SenioritySurveyModalTest < ApplicationSystemTestCase
end
end

# TODO: check why this doesn't fail
test "does not show if seniority is provided -- this should fail" do
user = create :user, seniority: :mid
create(:user_dismissed_introducer, user:, slug: "welcome-modal")

use_capybara_host do
Exercism.without_bullet do
sign_in!(user)
visit dashboard_path

assert_text "How experienced a developer are you?"
refute_text "How experienced a developer are you?"
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/system/flows/notifications/dropdown_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DrodpownTest < ApplicationSystemTestCase
include WebsocketsHelpers

test "user views notifications" do
user = create :user, seniority: :senior
user = create :user
mentor = create :user, handle: "mr-mentor"
discussion = create(:mentor_discussion, mentor:)
create :mentor_started_discussion_notification, user:, params: { discussion: }, status: :unread
Expand All @@ -27,7 +27,7 @@ class DrodpownTest < ApplicationSystemTestCase
end

test "refetches on websocket notification" do
user = create :user, seniority: :senior
user = create :user
mentor = create :user, handle: "mrs-mentor"
discussion = create(:mentor_discussion, mentor:)
create(:user_dismissed_introducer, slug: "welcome-modal", user:)
Expand All @@ -48,7 +48,7 @@ class DrodpownTest < ApplicationSystemTestCase
end

test "only loads notifications when dropdown is closed" do
user = create :user, seniority: :senior
user = create :user
mentor = create :user, handle: "mrs-mentor"
discussion = create(:mentor_discussion, mentor:)
create(:user_dismissed_introducer, slug: "welcome-modal", user:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ViewsTrackDocumentationTest < ApplicationSystemTestCase
include CapybaraHelpers

test "student views track documentation" do
user = create :user, seniority: :senior
user = create :user
track = create :track, title: "Ruby"
create(:user_dismissed_introducer, slug: "track-welcome-modal-#{track.slug}", user:)
create(:concept_exercise, track:)
Expand Down
14 changes: 7 additions & 7 deletions test/system/flows/student_requests_mentorship_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class StudentRequestsMentorship < ApplicationSystemTestCase
include MarkdownEditorHelpers

test "student requests mentorship" do
user = create :user, seniority: :mid
user = create :user
track = create :track
create(:user_dismissed_introducer, slug: "track-welcome-modal-#{track.slug}", user:)
create(:user_track, user:, track:)
Expand Down Expand Up @@ -45,7 +45,7 @@ class StudentRequestsMentorship < ApplicationSystemTestCase
end

test "form should be invalid when textarea value doesn't reach min length of 20 characters" do
user = create :user, seniority: :mid
user = create :user
track = create :track
create(:user_dismissed_introducer, slug: "track-welcome-modal-#{track.slug}", user:)
create(:user_track, user:, track:)
Expand Down Expand Up @@ -97,7 +97,7 @@ class StudentRequestsMentorship < ApplicationSystemTestCase
end

test "student can not request mentorship for hello-world" do
user = create :user, seniority: :mid
user = create :user
track = create :track
create(:user_dismissed_introducer, slug: "track-welcome-modal-#{track.slug}", user:)
create(:user_track, user:, track:)
Expand Down Expand Up @@ -130,7 +130,7 @@ class StudentRequestsMentorship < ApplicationSystemTestCase
end

test "student can not request mentorship for hello world" do
user = create :user, seniority: :mid
user = create :user
track = create :track
create(:user_track, user:, track:)
hello_world = create :concept_exercise, track:, slug: "hello-world"
Expand All @@ -152,7 +152,7 @@ class StudentRequestsMentorship < ApplicationSystemTestCase
end

test "student sees required number of completed exercises to request mentorship" do
user = create :user, seniority: :mid
user = create :user
track = create :track, title: "Ruby"
create(:user_track, user:, track:)
create :concept_exercise, track:, slug: "hello-world"
Expand All @@ -168,7 +168,7 @@ class StudentRequestsMentorship < ApplicationSystemTestCase
end

test "student requests mentorship when slots are full" do
user = create :user, seniority: :mid
user = create :user
track = create :track
create(:user_track, user:, track:)

Expand All @@ -195,7 +195,7 @@ class StudentRequestsMentorship < ApplicationSystemTestCase
end

test "student edits empty comment" do
user = create :user, seniority: :mid
user = create :user
track = create :track
create(:user_track, user:, track:)

Expand Down
8 changes: 4 additions & 4 deletions test/system/flows/user_loads_reputation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UserLoadsReputationTest < ApplicationSystemTestCase
include WebsocketsHelpers

test "user views reputation" do
user = create :user, seniority: :senior
user = create :user
external_url = "https://github.com/exercism/ruby/pulls/120"
create :user_code_review_reputation_token,
user:,
Expand Down Expand Up @@ -37,7 +37,7 @@ class UserLoadsReputationTest < ApplicationSystemTestCase
end

test "mark token as seen on hover" do
user = create :user, seniority: :senior
user = create :user
create :user_code_review_reputation_token,
user:,
created_at: 2.days.ago,
Expand All @@ -64,7 +64,7 @@ class UserLoadsReputationTest < ApplicationSystemTestCase
end

test "mark token as seen on focus" do
user = create :user, seniority: :senior
user = create :user
create :user_code_review_reputation_token,
user:,
created_at: 2.days.ago,
Expand Down Expand Up @@ -92,7 +92,7 @@ class UserLoadsReputationTest < ApplicationSystemTestCase
end

test "refetches on websocket notification" do
user = create :user, seniority: :senior
user = create :user
create(:user_dismissed_introducer, slug: "welcome-modal", user:)

use_capybara_host do
Expand Down

0 comments on commit 446a66c

Please sign in to comment.