Skip to content
Snippets Groups Projects
Commit 6c1ba513 authored by Bèr Kessels's avatar Bèr Kessels Committed by Eugen Rochko
Browse files

Add feature test that tests behaviour of profile name and bio (#12658)


* Add feature test that tests behaviour of profile name and bio

* Fix rubocop style errors in Login Spec.

* DRY log_in_spec by reusing the stories helper

Co-authored-by: default avatarEugen Rochko <eugen@zeonfederated.com>
parent 9cbbc50f
No related branches found
No related tags found
No related merge requests found
require "rails_helper"
# frozen_string_literal: true
require 'rails_helper'
feature 'Log in' do
include ProfileStories
feature "Log in" do
given(:email) { "test@example.com" }
given(:password) { "password" }
given(:confirmed_at) { Time.zone.now }
background do
Fabricate(:user, email: email, password: password, confirmed_at: confirmed_at)
as_a_registered_user
visit new_user_session_path
end
subject { page }
scenario "A valid email and password user is able to log in" do
fill_in "user_email", with: email
fill_in "user_password", with: password
scenario 'A valid email and password user is able to log in' do
fill_in 'user_email', with: email
fill_in 'user_password', with: password
click_on I18n.t('auth.login')
is_expected.to have_css("div.app-holder")
is_expected.to have_css('div.app-holder')
end
scenario "A invalid email and password user is not able to log in" do
fill_in "user_email", with: "invalid_email"
fill_in "user_password", with: "invalid_password"
scenario 'A invalid email and password user is not able to log in' do
fill_in 'user_email', with: 'invalid_email'
fill_in 'user_password', with: 'invalid_password'
click_on I18n.t('auth.login')
is_expected.to have_css(".flash-message", text: failure_message("invalid"))
is_expected.to have_css('.flash-message', text: failure_message('invalid'))
end
context do
given(:confirmed_at) { nil }
scenario "A unconfirmed user is able to log in" do
fill_in "user_email", with: email
fill_in "user_password", with: password
scenario 'A unconfirmed user is able to log in' do
fill_in 'user_email', with: email
fill_in 'user_password', with: password
click_on I18n.t('auth.login')
is_expected.to have_css("div.admin-wrapper")
is_expected.to have_css('div.admin-wrapper')
end
end
def failure_message(message)
keys = User.authentication_keys.map { |key| User.human_attribute_name(key) }
I18n.t("devise.failure.#{message}", authentication_keys: keys.join("support.array.words_connector"))
I18n.t("devise.failure.#{message}", authentication_keys: keys.join('support.array.words_connector'))
end
end
# frozen_string_literal: true
require 'rails_helper'
feature 'Profile' do
include ProfileStories
given(:local_domain) { ENV['LOCAL_DOMAIN'] }
background do
as_a_logged_in_user
with_alice_as_local_user
end
subject { page }
scenario 'I can view Annes public account' do
visit account_path('alice')
is_expected.to have_title("alice (@alice@#{local_domain})")
within('.public-account-header h1') do
is_expected.to have_content("alice @alice@#{local_domain}")
end
bio_elem = first('.public-account-bio')
expect(bio_elem).to have_content(alice_bio)
# The bio has hashtags made clickable
expect(bio_elem).to have_link('cryptology')
expect(bio_elem).to have_link('science')
# Nicknames are make clickable
expect(bio_elem).to have_link('@alice')
expect(bio_elem).to have_link('@bob')
# Nicknames not on server are not clickable
expect(bio_elem).not_to have_link('@pepe')
end
scenario 'I can change my account' do
visit settings_profile_path
fill_in 'Display name', with: 'Bob'
fill_in 'Bio', with: 'Bob is silent'
click_on 'Save changes'
is_expected.to have_content 'Changes successfully saved!'
# View my own public profile and see the changes
click_link "Bob @bob@#{local_domain}"
within('.public-account-header h1') do
is_expected.to have_content("Bob @bob@#{local_domain}")
end
expect(first('.public-account-bio')).to have_content('Bob is silent')
end
end
# frozen_string_literal: true
module ProfileStories
attr_reader :bob, :alice, :alice_bio
def as_a_registered_user
@bob = Fabricate(
:user,
email: email, password: password, confirmed_at: confirmed_at,
account: Fabricate(:account, username: 'bob')
)
end
def as_a_logged_in_user
as_a_registered_user
visit new_user_session_path
fill_in 'user_email', with: email
fill_in 'user_password', with: password
click_on I18n.t('auth.login')
end
def with_alice_as_local_user
@alice_bio = '@alice and @bob are fictional characters commonly used as'\
'placeholder names in #cryptology, as well as #science and'\
'engineering 📖 literature. Not affilated with @pepe.'
@alice = Fabricate(
:user,
email: 'alice@example.com', password: password, confirmed_at: confirmed_at,
account: Fabricate(:account, username: 'alice', note: @alice_bio)
)
end
def confirmed_at
@confirmed_at ||= Time.zone.now
end
def email
@email ||= 'test@example.com'
end
def password
@password ||= 'password'
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment