Commit a42ec0c2 authored by Mark Lapierre's avatar Mark Lapierre Committed by Ramya Authappan

Add new Elasticsearch E2E tests

Adds coverage for global search and advanced search syntax.
Includes a new page object component and QA selectors.
Updates the existing ES E2E test to indicate that it requires admin.
Adds class method Runtime::API::Client.as_admin to make it easier
to use the API as an admin.
Adds the ability to use PUT via the API.
parent 3bdc7844
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
= search_filter_link 'snippet_blobs', _("Snippet Contents"), search: { snippets: true, group_id: nil, project_id: nil } = search_filter_link 'snippet_blobs', _("Snippet Contents"), search: { snippets: true, group_id: nil, project_id: nil }
= search_filter_link 'snippet_titles', _("Titles and Filenames"), search: { snippets: true, group_id: nil, project_id: nil } = search_filter_link 'snippet_titles', _("Titles and Filenames"), search: { snippets: true, group_id: nil, project_id: nil }
- else - else
= search_filter_link 'projects', _("Projects") = search_filter_link 'projects', _("Projects"), data: { qa_selector: 'projects_tab' }
= search_filter_link 'issues', _("Issues") = search_filter_link 'issues', _("Issues")
= search_filter_link 'merge_requests', _("Merge requests") = search_filter_link 'merge_requests', _("Merge requests")
= search_filter_link 'milestones', _("Milestones") = search_filter_link 'milestones', _("Milestones")
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
= image_tag avatar_icon_for_user(project.creator, 48), class: "avatar s48", alt:'' = image_tag avatar_icon_for_user(project.creator, 48), class: "avatar s48", alt:''
- else - else
= project_icon(project, alt: '', class: 'avatar project-avatar s48', width: 48, height: 48) = project_icon(project, alt: '', class: 'avatar project-avatar s48', width: 48, height: 48)
.project-details.d-sm-flex.flex-sm-fill.align-items-center .project-details.d-sm-flex.flex-sm-fill.align-items-center{ data: { qa_selector: 'project', qa_project_name: project.name } }
.flex-wrapper .flex-wrapper
.d-flex.align-items-center.flex-wrap.project-title .d-flex.align-items-center.flex-wrap.project-title
%h2.d-flex.prepend-top-8 %h2.d-flex.prepend-top-8
......
...@@ -29,7 +29,7 @@ module QA ...@@ -29,7 +29,7 @@ module QA
end end
def fabricate_via_api! def fabricate_via_api!
@es_enabled ? api_post : resource_web_url(api_get) @es_enabled ? api_put : resource_web_url(api_get)
end end
def resource_web_url(resource) def resource_web_url(resource)
...@@ -42,11 +42,11 @@ module QA ...@@ -42,11 +42,11 @@ module QA
"/application/settings" "/application/settings"
end end
def api_post_path def api_put_path
"/application/settings" "/application/settings"
end end
def api_post_body def api_put_body
{ {
elasticsearch_search: @es_enabled, elasticsearch_search: @es_enabled,
elasticsearch_indexing: @es_indexing, elasticsearch_indexing: @es_indexing,
......
...@@ -5,6 +5,7 @@ module QA::Page ...@@ -5,6 +5,7 @@ module QA::Page
class Results < QA::Page::Base class Results < QA::Page::Base
view 'app/views/search/_category.html.haml' do view 'app/views/search/_category.html.haml' do
element :code_tab element :code_tab
element :projects_tab
end end
view 'app/views/search/results/_blob_data.html.haml' do view 'app/views/search/results/_blob_data.html.haml' do
...@@ -13,21 +14,33 @@ module QA::Page ...@@ -13,21 +14,33 @@ module QA::Page
element :file_text_content element :file_text_content
end end
view 'app/views/shared/projects/_project.html.haml' do
element :project
end
def switch_to_code def switch_to_code
click_element(:code_tab) click_element(:code_tab)
end end
def switch_to_projects
click_element(:projects_tab)
end
def has_file_in_project?(file_name, project_name) def has_file_in_project?(file_name, project_name)
has_element? :result_item_content, text: "#{project_name}: #{file_name}" has_element?(:result_item_content, text: "#{project_name}: #{file_name}")
end end
def has_file_with_content?(file_name, file_text) def has_file_with_content?(file_name, file_text)
within_element_by_index :result_item_content, 0 do within_element_by_index(:result_item_content, 0) do
false unless has_element? :file_title_content, text: file_name false unless has_element?(:file_title_content, text: file_name)
has_element? :file_text_content, text: file_text has_element?(:file_text_content, text: file_text)
end end
end end
def has_project?(project_name)
has_element?(:project, project_name: project_name)
end
end end
end end
end end
...@@ -19,8 +19,8 @@ module QA ...@@ -19,8 +19,8 @@ module QA
def api_support? def api_support?
respond_to?(:api_get_path) && respond_to?(:api_get_path) &&
respond_to?(:api_post_path) && (respond_to?(:api_post_path) && respond_to?(:api_post_body)) ||
respond_to?(:api_post_body) (respond_to?(:api_put_path) && respond_to?(:api_put_body))
end end
def fabricate_via_api! def fabricate_via_api!
...@@ -84,6 +84,18 @@ module QA ...@@ -84,6 +84,18 @@ module QA
process_api_response(parse_body(response)) process_api_response(parse_body(response))
end end
def api_put
response = put(
Runtime::API::Request.new(api_client, api_put_path).url,
api_put_body)
unless response.code == HTTP_STATUS_OK
raise ResourceFabricationFailedError, "Updating #{self.class.name} using the API failed (#{response.code}) with `#{response}`."
end
process_api_response(parse_body(response))
end
def api_delete def api_delete
url = Runtime::API::Request.new(api_client, api_delete_path).url url = Runtime::API::Request.new(api_client, api_delete_path).url
response = delete(url) response = delete(url)
......
...@@ -25,6 +25,23 @@ module QA ...@@ -25,6 +25,23 @@ module QA
end end
end end
def self.as_admin
if Runtime::Env.admin_personal_access_token
Runtime::API::Client.new(:gitlab, personal_access_token: Runtime::Env.admin_personal_access_token)
else
user = Resource::User.fabricate_via_api! do |user|
user.username = Runtime::User.admin_username
user.password = Runtime::User.admin_password
end
unless user.admin?
raise AuthorizationError, "User '#{user.username}' is not an administrator."
end
Runtime::API::Client.new(:gitlab, user: user)
end
end
private private
def enable_ip_limits def enable_ip_limits
......
# frozen_string_literal: true
module QA
context 'Create' do
describe 'Elasticsearch advanced global search with advanced syntax', :orchestrated, :elasticsearch, :requires_admin do
let(:project_name_suffix) { SecureRandom.hex(8) }
before do
@project_file_name = 'elasticsearch.rb'
@project_file_content = "elasticsearch: #{SecureRandom.hex(8)}"
QA::EE::Resource::Settings::Elasticsearch.fabricate_via_api! do |es|
es.user = QA::Resource::User.new.tap do |user|
user.username = QA::Runtime::User.admin_username
user.password = QA::Runtime::User.admin_password
end
es.api_client = Runtime::API::Client.as_admin
end
@project = Resource::Project.fabricate_via_api! do |project|
project.add_name_uuid = false
project.name = "es-adv-global-search-#{project_name_suffix}1"
project.description = "This is a unique project description #{project_name_suffix}2"
end
Resource::Repository::ProjectPush.fabricate! do |push|
push.project = @project
push.file_name = @project_file_name
push.file_content = @project_file_content
end
Flow::Login.sign_in
end
context 'when searching for projects using advanced syntax' do
it 'searches in the project name' do
expect_search_to_find_project("es-adv-*#{project_name_suffix}1")
end
it 'searches in the project description' do
expect_search_to_find_project("unique +#{project_name_suffix}2")
end
end
def expect_search_to_find_project(search_term)
Page::Main::Menu.perform do |menu|
menu.search_for(search_term)
end
Page::Search::Results.perform do |results|
results.switch_to_projects
expect(results).to have_project(@project.name)
end
end
end
end
end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module QA module QA
context 'Create' do context 'Create' do
describe 'Search using Elasticsearch', :orchestrated, :elasticsearch do describe 'Search using Elasticsearch', :orchestrated, :elasticsearch, :requires_admin do
include Runtime::Fixtures include Runtime::Fixtures
before do before do
...@@ -10,14 +10,16 @@ module QA ...@@ -10,14 +10,16 @@ module QA
@project_file_name = 'elasticsearch.rb' @project_file_name = 'elasticsearch.rb'
@project_file_content = 'elasticsearch: true' @project_file_content = 'elasticsearch: true'
Flow::Login.sign_in Flow::Login.while_signed_in_as_admin do
QA::EE::Resource::Settings::Elasticsearch.fabricate_via_browser_ui!
QA::EE::Resource::Settings::Elasticsearch.fabricate_via_browser_ui! end
@project = Resource::Project.fabricate_via_api! do |project| @project = Resource::Project.fabricate_via_api! do |project|
project.name = project_name project.name = project_name
end end
Flow::Login.sign_in
Resource::Repository::ProjectPush.fabricate! do |push| Resource::Repository::ProjectPush.fabricate! do |push|
push.project = @project push.project = @project
push.file_name = @project_file_name push.file_name = @project_file_name
......
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