Skip to content

Commit caae525

Browse files
committed
more system test coverage
1 parent f8bed6a commit caae525

File tree

6 files changed

+213
-0
lines changed

6 files changed

+213
-0
lines changed

spec/system/archive_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe "archive" do
4+
def create_read_stories(count)
5+
count.times { create(:story, :read) }
6+
end
7+
8+
it "displays read stories" do
9+
login_as(default_user)
10+
create(:story, :read, title: "Old Story")
11+
12+
visit(archive_path)
13+
14+
expect(page).to have_content("Old Story")
15+
end
16+
17+
it "shows a message when no stories have been read" do
18+
login_as(default_user)
19+
20+
visit(archive_path)
21+
22+
expect(page).to have_content("you haven't read any stories")
23+
end
24+
25+
it "paginates read stories" do
26+
login_as(default_user)
27+
create_read_stories(21)
28+
29+
visit(archive_path)
30+
31+
expect(page).to have_link("Next")
32+
end
33+
end

spec/system/feed_edit_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe "feeds/edit" do
4+
def visit_edit_feed
5+
feed = create(:feed)
6+
visit("/feeds/#{feed.id}/edit")
7+
end
8+
9+
it "allows updating a feed name" do
10+
login_as(default_user)
11+
visit_edit_feed
12+
13+
fill_in("Feed Name", with: "New Name")
14+
click_on("Save")
15+
16+
expect(page).to have_content("Updated the feed")
17+
end
18+
19+
it "allows updating a feed URL" do
20+
login_as(default_user)
21+
visit_edit_feed
22+
23+
fill_in("Feed URL", with: "http://new.example.com")
24+
click_on("Save")
25+
26+
expect(page).to have_content("Updated the feed")
27+
end
28+
end

spec/system/feed_show_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe "feeds/show" do
4+
def create_and_visit_feed(story_title: nil)
5+
feed = create(:feed)
6+
create(:story, feed:, title: story_title) if story_title
7+
visit("/feed/#{feed.id}")
8+
feed
9+
end
10+
11+
it "displays the feed name" do
12+
login_as(default_user)
13+
14+
feed = create_and_visit_feed
15+
16+
expect(page).to have_content(feed.name)
17+
end
18+
19+
it "displays stories for the feed" do
20+
login_as(default_user)
21+
22+
create_and_visit_feed(story_title: "My Story")
23+
24+
expect(page).to have_content("My Story")
25+
end
26+
27+
it "marks all stories as read" do
28+
login_as(default_user)
29+
create_and_visit_feed(story_title: "My Story")
30+
31+
find_by_id("mark-all").click
32+
33+
expect(page).to have_content("You've reached RSS Zero")
34+
end
35+
end
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe "keyboard shortcuts" do
4+
after { visit(logout_path) }
5+
6+
def create_stories_and_visit
7+
create(:story, title: "First Story", body: "First Body")
8+
create(:story, title: "Second Story", body: "Second Body")
9+
visit(news_path)
10+
end
11+
12+
it "opens a story with j" do
13+
login_as(default_user)
14+
create_stories_and_visit
15+
16+
send_keys("j")
17+
18+
expect(page).to have_css("li.story.open")
19+
end
20+
21+
it "navigates up with k" do
22+
login_as(default_user)
23+
create_stories_and_visit
24+
25+
send_keys("j", "j", "k")
26+
27+
expect(page).to have_css("li.story.open", count: 1)
28+
end
29+
30+
it "moves cursor without opening with n" do
31+
login_as(default_user)
32+
create_stories_and_visit
33+
34+
send_keys("n")
35+
36+
expect(page).to have_css("li.story.cursor:not(.open)")
37+
end
38+
39+
it "moves cursor without opening with p" do
40+
login_as(default_user)
41+
create_stories_and_visit
42+
send_keys("n", "n")
43+
44+
send_keys("p")
45+
46+
expect(page).to have_css("li.story.cursor:not(.open)")
47+
end
48+
49+
it "toggles a story open and closed with o" do
50+
login_as(default_user)
51+
create_stories_and_visit
52+
send_keys("o")
53+
54+
send_keys("o")
55+
56+
expect(page).to have_no_css("li.story.open")
57+
end
58+
59+
def create_story_and_visit(title:)
60+
create(:story, title:)
61+
visit(news_path)
62+
end
63+
64+
it "stars the current story with s" do
65+
login_as(default_user)
66+
create_story_and_visit(title: "My Story")
67+
send_keys("j", "s")
68+
69+
visit(starred_path)
70+
71+
expect(page).to have_content("My Story")
72+
end
73+
end

spec/system/starred_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe "starred" do
4+
it "displays starred stories" do
5+
login_as(default_user)
6+
create(:story, :starred, title: "Fave Story")
7+
8+
visit(starred_path)
9+
10+
expect(page).to have_content("Fave Story")
11+
end
12+
13+
it "shows a message when no stories are starred" do
14+
login_as(default_user)
15+
16+
visit(starred_path)
17+
18+
expect(page).to have_content("you haven't starred any stories")
19+
end
20+
end

spec/system/tutorial_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe "tutorial" do
4+
def visit_tutorial
5+
expect(CallableJob).to receive(:perform_later)
6+
visit(setup_tutorial_path)
7+
end
8+
9+
it "displays the tutorial page" do
10+
login_as(default_user)
11+
12+
visit_tutorial
13+
14+
expect(page).to have_content("Stringer is simple")
15+
end
16+
17+
it "displays sample stories" do
18+
login_as(default_user)
19+
20+
visit_tutorial
21+
22+
expect(page).to have_content("Darin' Fireballs")
23+
end
24+
end

0 commit comments

Comments
 (0)