Commit 2768706d authored by Sanad Liaquat's avatar Sanad Liaquat Committed by Mark Lapierre

Add e2e test for following user activity

Also create all requried page objects and
project_issue_note resource
parent eb8a3ed7
......@@ -3,7 +3,7 @@
%ul
%li.current-user
- if current_user_menu?(:profile)
= link_to current_user, class: 'gl-line-height-20!', data: { user: current_user.username, testid: 'user-profile-link' } do
= link_to current_user, class: 'gl-line-height-20!', data: { user: current_user.username, testid: 'user-profile-link', qa_selector: 'user_profile_link' } do
= render 'layouts/header/current_user_dropdown_item'
- else
.gl-py-3.gl-px-4
......
......@@ -7,7 +7,7 @@
.user-info
.block-truncated
= link_to user.name, user_path(user), class: 'user js-user-link', data: { user_id: user.id }
= link_to user.name, user_path(user), class: 'user js-user-link', data: { user_id: user.id, qa_selector: 'user_link', qa_username: user.username }
.block-truncated
%span.gl-text-gray-900= user.to_reference
......@@ -18,7 +18,7 @@
%h4.gl-flex-grow-1
= Feature.enabled?(:security_auto_fix) && @user.bot? ? s_('UserProfile|Bot activity') : s_('UserProfile|Activity')
= link_to s_('UserProfile|View all'), user_activity_path, class: "hide js-view-all"
.overview-content-list{ data: { href: user_activity_path } }
.overview-content-list{ data: { href: user_activity_path, qa_selector: 'user_activity_content' } }
.center.light.loading
.gl-spinner.gl-spinner-md
......
......@@ -39,7 +39,7 @@
= link_to user_unfollow_path(@user, :json) , class: link_classes + 'btn gl-button btn-default', method: :post do
= _('Unfollow')
- else
= link_to user_follow_path(@user, :json) , class: link_classes + 'btn gl-button btn-confirm', method: :post do
= link_to user_follow_path(@user, :json) , class: link_classes + 'btn gl-button btn-confirm', method: :post, data: { qa_selector: 'follow_user_link' } do
= _('Follow')
.profile-header{ class: [('with-no-profile-tabs' if profile_tabs.empty?)] }
......@@ -103,7 +103,7 @@
- count = @user.followers.count
= n_('1 follower', '%{count} followers', count) % { count: count }
.profile-link-holder.middle-dot-divider
= link_to user_following_path, class: 'text-link' do
= link_to user_following_path, class: 'text-link', data: { qa_selector: 'following_link' } do
= @user.followees.count
= _('following')
- if @user.bio.present?
......
......@@ -68,6 +68,7 @@ module QA
autoload :Sandbox, 'qa/resource/sandbox'
autoload :Group, 'qa/resource/group'
autoload :Issue, 'qa/resource/issue'
autoload :ProjectIssueNote, 'qa/resource/project_issue_note'
autoload :Project, 'qa/resource/project'
autoload :Label, 'qa/resource/label'
autoload :MergeRequest, 'qa/resource/merge_request'
......@@ -416,6 +417,10 @@ module QA
end
end
module User
autoload :Show, 'qa/page/user/show'
end
module Issuable
autoload :New, 'qa/page/issuable/new'
end
......
......@@ -125,6 +125,12 @@ module QA
end
end
def click_user_profile_link
within_user_menu do
click_element(:user_profile_link)
end
end
def search_for(term)
fill_element :search_term_field, "#{term}\n"
end
......
# frozen_string_literal: true
module QA
module Page
module User
class Show < Page::Base
view 'app/views/users/show.html.haml' do
element :follow_user_link
element :following_link
end
view 'app/views/shared/users/_user.html.haml' do
element :user_link
end
view 'app/views/users/_overview.html.haml' do
element :user_activity_content
end
def click_follow_user_link
click_element(:follow_user_link)
end
def click_following_link
click_element(:following_link)
end
def click_user_link(username)
click_element(:user_link, username: username)
end
def has_activity?(activity)
within_element(:user_activity_content) do
has_text?(activity)
end
end
end
end
end
end
# frozen_string_literal: true
require 'securerandom'
module QA
module Resource
class ProjectIssueNote < Base
attr_writer :body
attribute :project do
Project.fabricate! do |resource|
resource.name = 'project-for-issue-notes'
resource.description = 'project for adding notes to issues'
end
end
attribute :issue do
Issue.fabricate! do |resource|
resource.project = project
resource.title = 'Issue for adding notes.'
resource.description = 'Issue for adding notes.'
end
end
attribute :id
attribute :body
def initialize
@body = "Issue note body #{SecureRandom.hex(8)}"
end
def fabricate!
issue.visit!
Page::Project::Issue::Show.perform do |show|
show.comment(@body)
end
end
def resource_web_url(resource)
super
rescue ResourceURLMissingError
# this particular resource does not expose a web_url property
end
def api_get_path
"/projects/#{project.id}/issues/#{issue.iid}/notes/#{id}"
end
def api_post_path
"/projects/#{project.id}/issues/#{issue.iid}/notes"
end
def api_post_body
{
body: body
}
end
end
end
end
# frozen_string_literal: true
module QA
RSpec.describe 'Manage' do
describe 'User', :requires_admin do
let(:admin_api_client) { Runtime::API::Client.as_admin }
let(:user) do
Resource::User.fabricate_via_api! do |user|
user.api_client = admin_api_client
end
end
let(:user_api_client) do
Runtime::API::Client.new(:gitlab, user: user)
end
let(:group) do
group = QA::Resource::Group.fabricate_via_api! do |group|
group.path = "group_for_follow_user_activity_#{SecureRandom.hex(8)}"
end
group.add_member(user)
group
end
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'project-for-tags'
project.initialize_with_readme = true
project.api_client = user_api_client
project.group = group
end
end
let(:merge_request) do
Resource::MergeRequest.fabricate_via_api! do |mr|
mr.project = project
mr.api_client = user_api_client
end
end
let(:issue) do
Resource::Issue.fabricate_via_api! do |issue|
issue.project = project
issue.api_client = user_api_client
end
end
let(:comment) do
Resource::ProjectIssueNote.fabricate_via_api! do |project_issue_note|
project_issue_note.project = project
project_issue_note.issue = issue
project_issue_note.body = 'This is a comment'
project_issue_note.api_client = user_api_client
end
end
before do
# Create both tokens before logging in the first time so that we don't need to log out in the middle of the test
admin_api_client.personal_access_token
user_api_client.personal_access_token
end
it 'can be followed and their activity seen', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1773' do
Flow::Login.sign_in
page.visit Runtime::Scenario.gitlab_address + "/#{user.username}"
Page::User::Show.perform(&:click_follow_user_link)
expect(page).to have_text("No activities found")
project
merge_request
issue
comment
Page::Main::Menu.perform(&:click_user_profile_link)
Page::User::Show.perform do |show|
show.click_following_link
show.click_user_link(user.username)
aggregate_failures do
expect(show).to have_activity('created project')
expect(show).to have_activity('opened merge request')
expect(show).to have_activity('opened issue')
expect(show).to have_activity('commented on issue')
end
end
end
after do
project.api_client = admin_api_client
project.remove_via_api!
user.remove_via_api!
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment