Skip to content

Commit 3cea95f

Browse files
committed
yet more system tests
1 parent b0d1d61 commit 3cea95f

11 files changed

+217
-4
lines changed

spec/system/account_setup_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# frozen_string_literal: true
22

33
RSpec.describe "account setup" do
4-
def fill_in_fields(username:)
4+
def fill_in_fields(username:, confirm: "my-password")
55
fill_in("Username", with: username)
66
fill_in("Password", with: "my-password")
7-
fill_in("Confirm", with: "my-password")
7+
fill_in("Confirm", with: confirm)
88
click_on("Next")
99
end
1010

@@ -16,6 +16,14 @@ def fill_in_fields(username:)
1616
expect(page).to have_text("Logged in as my-username")
1717
end
1818

19+
it "shows an error when passwords do not match" do
20+
visit "/"
21+
22+
fill_in_fields(username: "my-username", confirm: "wrong-password")
23+
24+
expect(page).to have_content("doesn't match")
25+
end
26+
1927
it "allows a second user to sign up" do
2028
Setting::UserSignup.create!(enabled: true)
2129
create(:user)

spec/system/application_settings_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
expect(page).to have_content("User signups are disabled")
2121
end
2222

23+
it "blocks non-admin users from settings" do
24+
login_as(default_user)
25+
26+
visit(settings_path)
27+
28+
expect(page).to have_content("No route matches")
29+
end
30+
2331
it "prevents signup when signups are disabled" do
2432
create(:user, admin: true)
2533

spec/system/feed_show_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,34 @@ def create_and_visit_feed(story_title: nil)
4343
expect(page).to have_content("New Story")
4444
end
4545

46+
it "marks all stories as read with A hotkey" do
47+
login_as(default_user)
48+
create_and_visit_feed(story_title: "My Story")
49+
50+
send_keys("A")
51+
52+
expect(page).to have_content("You've reached RSS Zero")
53+
end
54+
55+
it "refreshes the feed with r hotkey" do
56+
login_as(default_user)
57+
feed = create_and_visit_feed
58+
create(:story, feed:, title: "New Story")
59+
60+
send_keys("r")
61+
62+
expect(page).to have_content("New Story")
63+
end
64+
65+
it "navigates to add feed with a hotkey" do
66+
login_as(default_user)
67+
create_and_visit_feed
68+
69+
send_keys("a")
70+
71+
expect(page).to have_current_path(feeds_new_path)
72+
end
73+
4674
it "only marks stories from the current feed as read" do
4775
login_as(default_user)
4876
other_feed = create(:feed)

spec/system/feeds_index_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@
5050
expect(page).to have_field("Feed Name", with: feed.name)
5151
end
5252

53+
it "displays the unread count for a feed" do
54+
login_as(default_user)
55+
feed = create(:feed)
56+
create_pair(:story, feed:)
57+
58+
visit "/feeds"
59+
60+
expect(page).to have_css(".feed-unread", text: "(2)")
61+
end
62+
63+
it "displays last fetched as Never for new feeds" do
64+
login_as(default_user)
65+
create(:feed)
66+
67+
visit "/feeds"
68+
69+
expect(page).to have_content("Never")
70+
end
71+
72+
it "displays the last fetched timestamp" do
73+
login_as(default_user)
74+
create(:feed, last_fetched: Time.zone.local(2024, 6, 15, 10, 30))
75+
76+
visit "/feeds"
77+
78+
expect(page).to have_content("Jun 15, 10:30")
79+
end
80+
5381
it "links to the feed" do
5482
login_as(default_user)
5583
feed = create(:feed)

spec/system/good_job_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@
1616

1717
expect(page).to have_link("Scheduled").and have_link("Queued")
1818
end
19+
20+
it "blocks non-admin users from the dashboard" do
21+
login_as(default_user)
22+
23+
visit(good_job_path)
24+
25+
expect(page).to have_content("No route matches")
26+
end
1927
end

spec/system/import_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# frozen_string_literal: true
22

33
RSpec.describe "importing feeds" do
4+
it "allows skipping the import" do
5+
login_as(default_user)
6+
visit(feeds_import_path)
7+
8+
click_on("Not now")
9+
10+
expect(page).to have_content("We're getting you some stories to read")
11+
end
12+
413
it "allows importing feeds" do
514
login_as(default_user)
615
visit(feeds_import_path)

spec/system/keyboard_shortcuts_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ def create_stories_and_visit
5656
expect(page).to have_no_css("li.story.open")
5757
end
5858

59+
it "toggles a story open and closed with enter" do
60+
login_as(default_user)
61+
create_stories_and_visit
62+
send_keys(:enter)
63+
64+
send_keys(:enter)
65+
66+
expect(page).to have_no_css("li.story.open")
67+
end
68+
5969
def create_story_and_visit(title:)
6070
create(:story, title:)
6171
visit(news_path)
@@ -71,6 +81,31 @@ def create_story_and_visit(title:)
7181
expect(page).to have_content("My Story")
7282
end
7383

84+
def open_story_and_send(key)
85+
send_keys("j")
86+
find("li.story.cursor .story-keep-unread")
87+
send_keys(key)
88+
end
89+
90+
it "toggles keep unread with m" do
91+
login_as(default_user)
92+
create_story_and_visit(title: "My Story")
93+
open_story_and_send("m")
94+
visit(news_path)
95+
96+
expect(page).to have_content("My Story")
97+
end
98+
99+
it "refreshes the page with r" do
100+
login_as(default_user)
101+
visit(news_path)
102+
create(:story, title: "My Story")
103+
104+
send_keys("r")
105+
106+
expect(page).to have_content("My Story")
107+
end
108+
74109
it "marks all as read with A" do
75110
login_as(default_user)
76111
create_story_and_visit(title: "My Story")
@@ -97,4 +132,13 @@ def create_story_and_visit(title:)
97132

98133
expect(page).to have_current_path(feeds_new_path)
99134
end
135+
136+
it "opens the shortcuts modal with ?" do
137+
login_as(default_user)
138+
create_story_and_visit(title: "My Story")
139+
140+
send_keys("?")
141+
142+
expect(page).to have_css("#shortcuts.in", visible: :visible)
143+
end
100144
end

spec/system/login_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ def submit_login(username:, password:)
2424
expect(page).to have_content("That's the wrong password")
2525
end
2626

27+
def login_from_current_page(user)
28+
fill_in("Username", with: user.username)
29+
fill_in("Password", with: user.password)
30+
click_on("Login")
31+
end
32+
33+
it "redirects to the original page after login" do
34+
user = create(:user)
35+
visit(starred_path)
36+
37+
login_from_current_page(user)
38+
39+
expect(page).to have_current_path(starred_path)
40+
end
41+
2742
it "allows a user to log out" do
2843
login_as(default_user)
2944

spec/system/profile_spec.rb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
expect(page).to have_text("Logged in as new_username")
1414
end
1515

16-
def fill_in_username_fields(existing_password)
16+
def fill_in_username_fields(existing_password, username: "new_username")
1717
within_fieldset("Change Username") do
18-
fill_in("Username", with: "new_username")
18+
fill_in("Username", with: username)
1919
fill_in("Existing password", with: existing_password)
2020
end
2121
end
@@ -49,6 +49,29 @@ def fill_in_password_fields(existing_password, new_password)
4949
expect(page).to have_text("Unable to update profile")
5050
end
5151

52+
def fill_in_mismatched_password_fields(existing_password)
53+
within_fieldset("Change Password") do
54+
fill_in("Existing password", with: existing_password)
55+
fill_in("New password", with: "new_password")
56+
fill_in("Password confirmation", with: "different_password")
57+
end
58+
end
59+
60+
it "rejects password change with mismatched confirmation" do
61+
fill_in_mismatched_password_fields(default_user.password)
62+
click_on("Update password")
63+
64+
expect(page).to have_text("Unable to update password")
65+
end
66+
67+
it "rejects username change when already taken" do
68+
create(:user, username: "taken_name")
69+
fill_in_username_fields(default_user.password, username: "taken_name")
70+
click_on("Update username")
71+
72+
expect(page).to have_text("Unable to update profile")
73+
end
74+
5275
it "rejects password change with wrong existing password" do
5376
fill_in_password_fields("wrong_password", "new_password")
5477
click_on("Update password")

spec/system/starred_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,24 @@ def create_starred_stories(count)
7878

7979
expect(page).to have_link("Next")
8080
end
81+
82+
it "navigates to the next page" do
83+
login_as(default_user)
84+
create_starred_stories(21)
85+
visit(starred_path)
86+
87+
click_on("Next")
88+
89+
expect(page).to have_content("2 of 2")
90+
end
91+
92+
it "navigates to the next page with arrow keys" do
93+
login_as(default_user)
94+
create_starred_stories(21)
95+
visit(starred_path)
96+
97+
send_keys(:arrow_right)
98+
99+
expect(page).to have_content("2 of 2")
100+
end
81101
end

0 commit comments

Comments
 (0)