Basic feature specs for the stories (#1269)
* Added stories feature specs * Structure feature specs * Spec for the articles by tag page * Disable example length for feature specs * Spec for clicking "week" button on the tag page
This commit is contained in:
parent
fbe586497b
commit
7b1c4084a8
17 changed files with 311 additions and 12 deletions
|
|
@ -7,13 +7,17 @@ require: rubocop-rspec
|
|||
RSpec/MultipleExpectations:
|
||||
# Max: 1
|
||||
Exclude:
|
||||
- "spec/features/*"
|
||||
- "spec/features/**/*"
|
||||
|
||||
RSpec/DescribeClass:
|
||||
Exclude:
|
||||
- spec/features/*
|
||||
- spec/features/**/*
|
||||
- spec/requests/*
|
||||
|
||||
RSpec/ExampleLength:
|
||||
Exclude:
|
||||
- spec/features/**/*
|
||||
|
||||
# TODO: Uncomment it after fix rubocop-todo Metrics/LineLength
|
||||
# Metrics/LineLength:
|
||||
# Description: 'Limit lines to 100 characters.'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Deleting Article", js: true do
|
||||
RSpec.describe "Deleting Article", js: true, type: :feature do
|
||||
let(:author) { create(:user) }
|
||||
let(:article) { create(:article, user_id: author.id) }
|
||||
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe "Editing with an editor" do
|
||||
describe "Editing with an editor", type: :feature do
|
||||
let(:user) { create(:user) }
|
||||
let(:dir) { "../support/fixtures/sample_article.txt" }
|
||||
let(:dir) { "../../support/fixtures/sample_article.txt" }
|
||||
let(:template) { File.read(File.join(File.dirname(__FILE__), dir)) }
|
||||
let(:article) do
|
||||
create(:article,
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe "Views an article" do
|
||||
describe "Views an article", type: :feature do
|
||||
let(:user) { create(:user) }
|
||||
let(:dir) { "../support/fixtures/sample_article.txt" }
|
||||
let(:dir) { "../../support/fixtures/sample_article.txt" }
|
||||
let(:template) { File.read(File.join(File.dirname(__FILE__), dir)) }
|
||||
let(:article) do
|
||||
let!(:article) do
|
||||
create(:article,
|
||||
user_id: user.id,
|
||||
body_markdown: template.gsub("false", "true"),
|
||||
67
spec/features/articles/user_visits_articles_by_tag_spec.rb
Normal file
67
spec/features/articles/user_visits_articles_by_tag_spec.rb
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe "User visits articles by tag", type: :feature do
|
||||
let(:js_tag) { create(:tag, name: "javascript") }
|
||||
let(:iot_tag) { create(:tag, name: "IoT") }
|
||||
let!(:func_tag) { create(:tag, name: "functional") }
|
||||
|
||||
let(:author) { create(:user) }
|
||||
let!(:article) { create(:article, tags: "javascript, IoT", user: author, published_at: Time.now - 2.days) }
|
||||
let!(:article2) { create(:article, tags: "functional", user: author, published_at: Time.now) }
|
||||
let!(:article3) { create(:article, tags: "functional, javascript", user: author, published_at: Time.now - 2.weeks) }
|
||||
|
||||
context "when user hasn't logged in" do
|
||||
before { visit "/t/javascript" }
|
||||
|
||||
it "shows the header", js: true do
|
||||
within("h1") { expect(page).to have_text("javascript") }
|
||||
end
|
||||
|
||||
it "shows the follow button", js: true do
|
||||
within("h1") { expect(page).to have_button("+ FOLLOW") }
|
||||
end
|
||||
|
||||
it "shows time buttons" do
|
||||
within("#on-page-nav-controls") do
|
||||
expect(page).to have_link("WEEK", href: "/t/javascript/top/week")
|
||||
expect(page).to have_link("INFINITY", href: "/t/javascript/top/infinity")
|
||||
expect(page).to have_link("LATEST", href: "/t/javascript/latest")
|
||||
end
|
||||
end
|
||||
|
||||
it "shows correct articles count", js: true do
|
||||
expect(page).to have_selector(".single-article", count: 2)
|
||||
end
|
||||
|
||||
it "shows the correct articles" do
|
||||
within("#articles-list") do
|
||||
expect(page).to have_text(article.title)
|
||||
expect(page).to have_text(article3.title)
|
||||
expect(page).not_to have_text(article2.title)
|
||||
end
|
||||
end
|
||||
|
||||
it "when user clicks 'week'" do
|
||||
click_on "WEEK"
|
||||
within("#articles-list") do
|
||||
expect(page).to have_text(article.title)
|
||||
expect(page).not_to have_text(article3.title)
|
||||
expect(page).not_to have_text(article2.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when user has logged in" do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
user.follows.create(followable: func_tag)
|
||||
sign_in user
|
||||
visit "/t/functional"
|
||||
end
|
||||
|
||||
it "shows the following button", js: true do
|
||||
within("h1") { expect(page).to have_button("✓ FOLLOWING") }
|
||||
end
|
||||
end
|
||||
end
|
||||
22
spec/features/homepage/user_visits_homepage_articles_spec.rb
Normal file
22
spec/features/homepage/user_visits_homepage_articles_spec.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe "User visits a homepage", type: :feature do
|
||||
let!(:article) { create(:article, reactions_count: 12, featured: true) }
|
||||
let!(:article2) { create(:article, reactions_count: 20) }
|
||||
let!(:bad_article) { create(:article, reactions_count: 0) }
|
||||
|
||||
context "when no options specified" do
|
||||
before { visit "/" }
|
||||
|
||||
it "shows the main article" do
|
||||
expect(page).to have_selector(".big-article", visible: true)
|
||||
end
|
||||
|
||||
it "shows correct articles", js: true do
|
||||
expect(page).to have_selector(".single-article", count: 2)
|
||||
expect(page).to have_text(article.title)
|
||||
expect(page).to have_text(article2.title)
|
||||
expect(page).not_to have_text(bad_article.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
71
spec/features/homepage/user_visits_homepage_spec.rb
Normal file
71
spec/features/homepage/user_visits_homepage_spec.rb
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe "User visits a homepage", type: :feature do
|
||||
let!(:ruby_tag) { create(:tag, name: "ruby") }
|
||||
|
||||
before { create(:tag, name: "webdev") }
|
||||
|
||||
context "when user hasn't logged in" do
|
||||
before { visit "/" }
|
||||
|
||||
it "shows the sign-in block" do
|
||||
within ".signin-cta-widget" do
|
||||
expect(page).to have_text("SIGN IN VIA TWITTER")
|
||||
expect(page).to have_text("SIGN IN VIA GITHUB")
|
||||
end
|
||||
end
|
||||
|
||||
it "shows the tags block" do
|
||||
within("#sidebar-nav-default-tags") do
|
||||
expect(page).to have_link("#ruby", href: "/t/ruby")
|
||||
expect(page).to have_link("#webdev", href: "/t/webdev")
|
||||
end
|
||||
expect(page).to have_text("design your experience")
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in user" do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
login_as(user)
|
||||
end
|
||||
|
||||
it "shows profile content", js: true do
|
||||
visit "/"
|
||||
within("div#sidebar-profile-username") do
|
||||
expect(page).to have_text(user.username)
|
||||
end
|
||||
expect(page).not_to have_text("SIGN IN VIA")
|
||||
end
|
||||
|
||||
it "offers to follow tags", js: true do
|
||||
visit "/"
|
||||
within("#sidebar-nav-default-tags") do
|
||||
expect(page).to have_text("Follow tags to improve your feed")
|
||||
end
|
||||
end
|
||||
|
||||
context "when user follows tags" do
|
||||
before do
|
||||
user.follows.create!(followable: ruby_tag)
|
||||
visit "/"
|
||||
end
|
||||
|
||||
it "shows the followed tags", js: true do
|
||||
expect(page).to have_text("my tags")
|
||||
within("#sidebar-nav-followed-tags") do
|
||||
expect(page).to have_link("#ruby", href: "/t/ruby")
|
||||
end
|
||||
end
|
||||
|
||||
it "shows other tags", js: true do
|
||||
expect(page).to have_text("Other Popular Tags")
|
||||
within("#sidebar-nav-default-tags") do
|
||||
expect(page).to have_link("#webdev", href: "/t/webdev")
|
||||
expect(page).not_to have_link("#ruby", href: "/t/ruby")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe "Organization index", type: :feature do
|
||||
let!(:organization) { create(:organization) }
|
||||
let!(:org_user) { create(:user, organization: organization) }
|
||||
|
||||
before do
|
||||
create_list(:article, 2, organization: organization)
|
||||
end
|
||||
|
||||
context "when user is unauthorized" do
|
||||
before { visit "/#{organization.slug}" }
|
||||
|
||||
it "shows the header", js: true do
|
||||
within("h1") { expect(page).to have_content(organization.name) }
|
||||
within("div.profile-details") do
|
||||
expect(page).to have_button("+ FOLLOW")
|
||||
end
|
||||
end
|
||||
|
||||
it "shows articles" do
|
||||
expect(page).to have_selector("div.single-article", count: 2)
|
||||
end
|
||||
|
||||
it "shows the sidebar" do
|
||||
within("div.sidebar-additional") do
|
||||
expect(page).to have_content("meet the team")
|
||||
expect(page).to have_link(nil, href: org_user.path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when user follows an organization" do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
user.follows.create(followable: organization)
|
||||
end
|
||||
|
||||
it "shows the correct button", js: true do
|
||||
visit "/#{organization.slug}"
|
||||
within(".profile-details") do
|
||||
expect(page).to have_button("✓ FOLLOWING")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe "User visits podcast show page" do
|
||||
describe "User visits podcast show page", type: :feature do
|
||||
let(:podcast) { create(:podcast) }
|
||||
let(:podcast_episode) { create(:podcast_episode, podcast_id: podcast.id) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
it "they see the content of the hero" do
|
||||
visit podcast_episode.path.to_s
|
||||
|
|
@ -19,6 +18,7 @@ describe "User visits podcast show page" do
|
|||
end
|
||||
|
||||
context "when there're existing comments" do
|
||||
let(:user) { create(:user) }
|
||||
let(:comment) { create(:comment, user_id: user.id, commentable: podcast_episode) }
|
||||
let!(:comment2) { create(:comment, user_id: user.id, commentable: podcast_episode, parent: comment) }
|
||||
|
||||
27
spec/features/podcasts/user_visits_podcast_page_spec.rb
Normal file
27
spec/features/podcasts/user_visits_podcast_page_spec.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe "User visits a podcast page", type: :feature do
|
||||
let(:podcast) { create(:podcast) }
|
||||
let!(:podcast_episode) { create(:podcast_episode, podcast_id: podcast.id) }
|
||||
let!(:podcast_episode2) { create(:podcast_episode, podcast_id: podcast.id) }
|
||||
let(:another_episode) { create(:podcast_episode, podcast: create(:podcast)) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before { visit podcast.path }
|
||||
|
||||
it "displays the header" do
|
||||
within "div.podcast-header" do
|
||||
expect(page).to have_text(podcast.title)
|
||||
end
|
||||
end
|
||||
|
||||
it "displays podcast episodes" do
|
||||
expect(page).to have_selector("div.single-article", visible: true, count: 2)
|
||||
end
|
||||
|
||||
it "displays correct episodes" do
|
||||
expect(page).to have_link(nil, href: podcast_episode.path)
|
||||
expect(page).to have_link(nil, href: podcast_episode2.path)
|
||||
expect(page).not_to have_link(nil, href: another_episode.path)
|
||||
end
|
||||
end
|
||||
61
spec/features/user/view_user_index_spec.rb
Normal file
61
spec/features/user/view_user_index_spec.rb
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe "User index", type: :feature do
|
||||
let!(:user) { create(:user, username: "user3000") }
|
||||
let!(:article) { create(:article, user: user) }
|
||||
let!(:other_article) { create(:article) }
|
||||
let!(:comment) { create(:comment, user: user, commentable: other_article) }
|
||||
|
||||
context "when user is unauthorized" do
|
||||
before { visit "/user3000" }
|
||||
|
||||
it "shows the header", js: true do
|
||||
within("h1") { expect(page).to have_content(user.name) }
|
||||
within(".profile-details") do
|
||||
expect(page).to have_button("+ FOLLOW")
|
||||
end
|
||||
end
|
||||
|
||||
it "shows user's articles" do
|
||||
within(".single-article") do
|
||||
expect(page).to have_content(article.title)
|
||||
expect(page).not_to have_content(other_article.title)
|
||||
end
|
||||
end
|
||||
|
||||
it "shows user's comments" do
|
||||
within("#substories div.index-comments") do
|
||||
expect(page).to have_content("Recent Comments")
|
||||
expect(page).to have_link(nil, href: comment.path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when visiting own profile" do
|
||||
before do
|
||||
sign_in user
|
||||
visit "/user3000"
|
||||
end
|
||||
|
||||
it "shows the header", js: true do
|
||||
within("h1") { expect(page).to have_content(user.name) }
|
||||
within(".profile-details") do
|
||||
expect(page).to have_button("EDIT PROFILE")
|
||||
end
|
||||
end
|
||||
|
||||
it "shows user's articles" do
|
||||
within(".single-article") do
|
||||
expect(page).to have_content(article.title)
|
||||
expect(page).not_to have_content(other_article.title)
|
||||
end
|
||||
end
|
||||
|
||||
it "shows user's comments" do
|
||||
within("#substories div.index-comments") do
|
||||
expect(page).to have_content("Recent Comments")
|
||||
expect(page).to have_link(nil, href: comment.path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -2,7 +2,7 @@ require "rails_helper"
|
|||
|
||||
RSpec.describe "Editing A Comment", type: :feature, js: true do
|
||||
let(:user) { create(:user) }
|
||||
let(:article) { create(:article, show_comments: true) }
|
||||
let!(:article) { create(:article, show_comments: true) }
|
||||
let(:new_comment_text) { Faker::Lorem.paragraph }
|
||||
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ RSpec.describe "Creating Comment", type: :feature, js: true do
|
|||
it "User fills out comment box normally" do
|
||||
visit article.path.to_s
|
||||
fill_in "text-area", with: raw_comment
|
||||
find(".checkbox").click
|
||||
click_button("SUBMIT")
|
||||
expect(page).to have_text(raw_comment)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue