Move system tests (#16077)

* Move browser based test for article feed into spec/system

* Move user subscription tag system tests to spec/system
This commit is contained in:
Daniel Uber 2022-01-18 08:08:41 -06:00 committed by GitHub
parent 19d6a26f7b
commit 71dcc7d53f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 180 additions and 145 deletions

View file

@ -31,140 +31,5 @@ RSpec.describe UserSubscriptionTag, type: :liquid_tag do
expect(liquid_tag).to include(CGI.escapeHTML(author.username))
expect(liquid_tag).to include(CGI.escapeHTML(author.profile_image_90))
end
it "displays signed out view by default", type: :system, js: true do
sign_in author
visit "/new" # Preview behaves differently - we don't load liquid tag scripts
fill_in "article_body_markdown", with: "{% user_subscription Some sweet CTA text %}"
page.execute_script("window.scrollTo(0, -100000)")
find("button", text: /\APreview\z/).click
expect(page).to have_css("#subscription-signed-in", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscription-signed-out", visible: :visible)
css_class = "img.ltag__user-subscription-tag__author-profile-image[src='#{author.profile_image_90}']"
expect(page).to have_css(css_class)
end
end
context "when signed in", type: :system, js: true do
before do
sign_in subscriber
visit article_with_user_subscription_tag.path
end
it "shows the signed in UX" do
expect(page).to have_css("#subscription-signed-out", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscription-signed-in", visible: :visible)
css_class = "img.ltag__user-subscription-tag__subscriber-profile-image[src='#{subscriber.profile_image_90}']"
expect(page).to have_css(css_class)
end
it "asks the user to confirm their subscription" do
expect(page).to have_css("#user-subscription-confirmation-modal", visible: :hidden)
click_button("Subscribe", id: "subscribe-btn")
expect(page).to have_css("#user-subscription-confirmation-modal", visible: :visible)
end
it "displays a success message when a subscription is created" do
expect(page).to have_css("#subscription-signed-out", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscription-signed-in", visible: :visible)
click_button("Subscribe", id: "subscribe-btn")
click_button("Confirm subscription", id: "confirmation-btn")
expect(page).to have_css("#subscription-signed-in", visible: :hidden)
expect(page).to have_css("#response-message.crayons-notice--success", visible: :visible)
within "#response-message" do
expect(page).to have_text("You are now subscribed")
end
end
# rubocop:disable RSpec/ExampleLength
it "displays errors when there's an error creating a subscription" do
# Create a subscription so it causes an error by already being subscribed
create(
:user_subscription,
subscriber_id: subscriber.id, subscriber_email: subscriber.email,
author_id: article_with_user_subscription_tag.user_id,
user_subscription_sourceable: article_with_user_subscription_tag
)
expect(page).to have_css("#subscription-signed-out", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscription-signed-in", visible: :visible)
click_button("Subscribe", id: "subscribe-btn")
click_button("Confirm subscription", id: "confirmation-btn")
# User should be able see the error and should be able to resubscribe.
expect(page).to have_css("#subscription-signed-in", visible: :visible)
expect(page).to have_css("#response-message.crayons-notice--danger", visible: :visible)
within "#response-message" do
expect(page).to have_text("Subscriber has already been taken")
end
end
# rubocop:enable RSpec/ExampleLength
it "tells the user they're already subscribed by default if they're already subscribed" do
create(
:user_subscription,
subscriber_id: subscriber.id, subscriber_email: subscriber.email,
author_id: article_with_user_subscription_tag.user_id,
user_subscription_sourceable: article_with_user_subscription_tag
)
visit article_with_user_subscription_tag.path
expect(page).to have_css("#subscription-signed-out", visible: :hidden)
expect(page).to have_css("#subscription-signed-in", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#response-message.crayons-notice--success", visible: :visible)
within "#response-message" do
expect(page).to have_text("You are already subscribed.")
end
end
end
context "when signed out", type: :system, js: true do
before { visit article_with_user_subscription_tag.path }
it "prompts a user to sign in when they're signed out", type: :system, js: true do
expect(page).to have_css("#subscription-signed-in", visible: :hidden)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#subscription-signed-out", visible: :visible)
end
it "allows a user to sign in", type: :system, js: true do
expect(page).not_to have_text("Log in to continue")
click_button("Sign In", id: "sign-in-btn")
expect(page).to have_text("Log in to continue")
end
end
# TODO: [@forem/delightful]: re-enable this once email confirmation
# is re-enabled and confirm it isn't flaky.
xcontext "when a user has an Apple private relay email address", type: :system, js: true do
it "prompts the user to update their email address" do
allow(subscriber).to receive(:email).and_return("test@privaterelay.appleid.com")
sign_in subscriber
visit article_with_user_subscription_tag.path
expect(page).to have_css("#subscription-signed-out", visible: :hidden)
expect(page).to have_css("#subscription-signed-in", visible: :hidden)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :visible)
within "#subscriber-apple-auth" do
expect(page).to have_button("Subscribe", disabled: true, visible: :visible)
end
end
end
end

View file

@ -44,16 +44,6 @@ RSpec.describe Articles::Feeds::LargeForemExperimental, type: :service do
create(:user_block, blocker: user, blocked: second_user, config: "default")
expect(result).not_to include(hot_story)
end
it "doesn't display blocked articles", type: :system, js: true do
selector = "article[data-content-user-id='#{hot_story.user_id}']"
sign_in user
visit root_path
expect(page).to have_selector(selector, visible: :visible)
create(:user_block, blocker: user, blocked: hot_story.user, config: "default")
visit root_path
expect(page).to have_selector(selector, visible: :hidden)
end
end
context "when ranking is true" do

View file

@ -0,0 +1,23 @@
require "rails_helper"
RSpec.describe Articles::Feeds::LargeForemExperimental, type: :system, js: true do
let(:user) { create(:user) }
let(:second_user) { create(:user) }
let!(:hot_story) do
create(:article, hotness_score: 1000, score: 1000, published_at: 3.hours.ago, user_id: second_user.id)
end
before do
create(:article)
end
it "doesn't display blocked articles" do
selector = "article[data-content-user-id='#{hot_story.user_id}']"
sign_in user
visit root_path
expect(page).to have_selector(selector, visible: :visible)
create(:user_block, blocker: user, blocked: hot_story.user, config: "default")
visit root_path
expect(page).to have_selector(selector, visible: :hidden)
end
end

View file

@ -0,0 +1,157 @@
require "rails_helper"
RSpec.describe UserSubscriptionTag, type: :system, js: true do
let(:subscriber) { create(:user) }
let(:author) { create(:user) }
let(:article_with_user_subscription_tag) do
create(:article, :with_user_subscription_tag_role_user, with_user_subscription_tag: true)
end
before do
Liquid::Template.register_tag("user_subscription", described_class)
end
context "when viewing the default view" do
before do
# Stub roles because adding them normally can cause flaky specs
allow(author).to receive(:has_role?).and_call_original
allow(author).to receive(:has_role?).with(:restricted_liquid_tag,
LiquidTags::UserSubscriptionTag).and_return(true)
end
it "displays signed out view by default" do
sign_in author
visit "/new" # Preview behaves differently - we don't load liquid tag scripts
fill_in "article_body_markdown", with: "{% user_subscription Some sweet CTA text %}"
page.execute_script("window.scrollTo(0, -100000)")
find("button", text: /\APreview\z/).click
expect(page).to have_css("#subscription-signed-in", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscription-signed-out", visible: :visible)
css_class = "img.ltag__user-subscription-tag__author-profile-image[src='#{author.profile_image_90}']"
expect(page).to have_css(css_class)
end
end
context "when signed in" do
before do
sign_in subscriber
visit article_with_user_subscription_tag.path
end
it "shows the signed in UX" do
expect(page).to have_css("#subscription-signed-out", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscription-signed-in", visible: :visible)
css_class = "img.ltag__user-subscription-tag__subscriber-profile-image[src='#{subscriber.profile_image_90}']"
expect(page).to have_css(css_class)
end
it "asks the user to confirm their subscription" do
expect(page).to have_css("#user-subscription-confirmation-modal", visible: :hidden)
click_button("Subscribe", id: "subscribe-btn")
expect(page).to have_css("#user-subscription-confirmation-modal", visible: :visible)
end
it "displays a success message when a subscription is created" do
expect(page).to have_css("#subscription-signed-out", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscription-signed-in", visible: :visible)
click_button("Subscribe", id: "subscribe-btn")
click_button("Confirm subscription", id: "confirmation-btn")
expect(page).to have_css("#subscription-signed-in", visible: :hidden)
expect(page).to have_css("#response-message.crayons-notice--success", visible: :visible)
within "#response-message" do
expect(page).to have_text("You are now subscribed")
end
end
# rubocop:disable RSpec/ExampleLength
it "displays errors when there's an error creating a subscription" do
# Create a subscription so it causes an error by already being subscribed
create(
:user_subscription,
subscriber_id: subscriber.id, subscriber_email: subscriber.email,
author_id: article_with_user_subscription_tag.user_id,
user_subscription_sourceable: article_with_user_subscription_tag
)
expect(page).to have_css("#subscription-signed-out", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscription-signed-in", visible: :visible)
click_button("Subscribe", id: "subscribe-btn")
click_button("Confirm subscription", id: "confirmation-btn")
# User should be able see the error and should be able to resubscribe.
expect(page).to have_css("#subscription-signed-in", visible: :visible)
expect(page).to have_css("#response-message.crayons-notice--danger", visible: :visible)
within "#response-message" do
expect(page).to have_text("Subscriber has already been taken")
end
end
# rubocop:enable RSpec/ExampleLength
it "tells the user they're already subscribed by default if they're already subscribed" do
create(
:user_subscription,
subscriber_id: subscriber.id, subscriber_email: subscriber.email,
author_id: article_with_user_subscription_tag.user_id,
user_subscription_sourceable: article_with_user_subscription_tag
)
visit article_with_user_subscription_tag.path
expect(page).to have_css("#subscription-signed-out", visible: :hidden)
expect(page).to have_css("#subscription-signed-in", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#response-message.crayons-notice--success", visible: :visible)
within "#response-message" do
expect(page).to have_text("You are already subscribed.")
end
end
end
context "when signed out" do
before { visit article_with_user_subscription_tag.path }
it "prompts a user to sign in when they're signed out", type: :system, js: true do
expect(page).to have_css("#subscription-signed-in", visible: :hidden)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
expect(page).to have_css("#subscription-signed-out", visible: :visible)
end
it "allows a user to sign in" do
expect(page).not_to have_text("Log in to continue")
click_button("Sign In", id: "sign-in-btn")
expect(page).to have_text("Log in to continue")
end
end
# TODO: [@forem/delightful]: re-enable this once email confirmation
# is re-enabled and confirm it isn't flaky.
xcontext "when a user has an Apple private relay email address" do
it "prompts the user to update their email address" do
allow(subscriber).to receive(:email).and_return("test@privaterelay.appleid.com")
sign_in subscriber
visit article_with_user_subscription_tag.path
expect(page).to have_css("#subscription-signed-out", visible: :hidden)
expect(page).to have_css("#subscription-signed-in", visible: :visible)
expect(page).to have_css("#response-message", visible: :hidden)
expect(page).to have_css("#subscriber-apple-auth", visible: :hidden)
within "#subscriber-apple-auth" do
expect(page).to have_button("Subscribe", disabled: true, visible: :visible)
end
end
end
end