summaryrefslogtreecommitdiff
path: root/spec/support/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers')
-rw-r--r--spec/support/helpers/api_helpers.rb4
-rw-r--r--spec/support/helpers/features/invite_members_modal_helper.rb10
-rw-r--r--spec/support/helpers/gitaly_setup.rb16
-rw-r--r--spec/support/helpers/gpg_helpers.rb8
-rw-r--r--spec/support/helpers/graphql_helpers.rb9
-rw-r--r--spec/support/helpers/javascript_fixtures_helpers.rb6
-rw-r--r--spec/support/helpers/memory_usage_helper.rb2
-rw-r--r--spec/support/helpers/migrations_helpers/work_item_types_helper.rb27
-rw-r--r--spec/support/helpers/modal_helpers.rb27
-rw-r--r--spec/support/helpers/navbar_structure_helper.rb11
-rw-r--r--spec/support/helpers/session_helpers.rb4
-rw-r--r--spec/support/helpers/snowplow_helpers.rb14
-rw-r--r--spec/support/helpers/stub_gitlab_calls.rb2
-rw-r--r--spec/support/helpers/test_env.rb4
14 files changed, 112 insertions, 32 deletions
diff --git a/spec/support/helpers/api_helpers.rb b/spec/support/helpers/api_helpers.rb
index d3cc7367b6e..fd85071cca3 100644
--- a/spec/support/helpers/api_helpers.rb
+++ b/spec/support/helpers/api_helpers.rb
@@ -19,13 +19,15 @@ module ApiHelpers
# => "/api/v2/issues?foo=bar&private_token=..."
#
# Returns the relative path to the requested API resource
- def api(path, user = nil, version: API::API.version, personal_access_token: nil, oauth_access_token: nil)
+ def api(path, user = nil, version: API::API.version, personal_access_token: nil, oauth_access_token: nil, job_token: nil)
full_path = "/api/#{version}#{path}"
if oauth_access_token
query_string = "access_token=#{oauth_access_token.token}"
elsif personal_access_token
query_string = "private_token=#{personal_access_token.token}"
+ elsif job_token
+ query_string = "job_token=#{job_token}"
elsif user
personal_access_token = create(:personal_access_token, user: user)
query_string = "private_token=#{personal_access_token.token}"
diff --git a/spec/support/helpers/features/invite_members_modal_helper.rb b/spec/support/helpers/features/invite_members_modal_helper.rb
index 3502558b2c2..11040562b49 100644
--- a/spec/support/helpers/features/invite_members_modal_helper.rb
+++ b/spec/support/helpers/features/invite_members_modal_helper.rb
@@ -5,7 +5,7 @@ module Spec
module Helpers
module Features
module InviteMembersModalHelper
- def invite_member(name, role: 'Guest', expires_at: nil, area_of_focus: false)
+ def invite_member(name, role: 'Guest', expires_at: nil)
click_on 'Invite members'
page.within '[data-testid="invite-members-modal"]' do
@@ -14,7 +14,6 @@ module Spec
wait_for_requests
click_button name
choose_options(role, expires_at)
- choose_area_of_focus if area_of_focus
click_button 'Invite'
@@ -44,13 +43,6 @@ module Spec
fill_in 'YYYY-MM-DD', with: expires_at.strftime('%Y-%m-%d') if expires_at
end
-
- def choose_area_of_focus
- page.within '[data-testid="area-of-focus-checks"]' do
- check 'Contribute to the codebase'
- check 'Collaborate on open issues and merge requests'
- end
- end
end
end
end
diff --git a/spec/support/helpers/gitaly_setup.rb b/spec/support/helpers/gitaly_setup.rb
index 8a329c2f9dd..923051a2e04 100644
--- a/spec/support/helpers/gitaly_setup.rb
+++ b/spec/support/helpers/gitaly_setup.rb
@@ -18,8 +18,12 @@ module GitalySetup
Logger.new($stdout, level: level, formatter: ->(_, _, _, msg) { msg })
end
+ def expand_path(path)
+ File.expand_path(path, File.join(__dir__, '../../..'))
+ end
+
def tmp_tests_gitaly_dir
- File.expand_path('../../../tmp/tests/gitaly', __dir__)
+ expand_path('tmp/tests/gitaly')
end
def tmp_tests_gitaly_bin_dir
@@ -27,11 +31,11 @@ module GitalySetup
end
def tmp_tests_gitlab_shell_dir
- File.expand_path('../../../tmp/tests/gitlab-shell', __dir__)
+ expand_path('tmp/tests/gitlab-shell')
end
def rails_gitlab_shell_secret
- File.expand_path('../../../.gitlab_shell_secret', __dir__)
+ expand_path('.gitlab_shell_secret')
end
def gemfile
@@ -48,7 +52,7 @@ module GitalySetup
def env
{
- 'HOME' => File.expand_path('tmp/tests'),
+ 'HOME' => expand_path('tmp/tests'),
'GEM_PATH' => Gem.path.join(':'),
'BUNDLE_APP_CONFIG' => File.join(gemfile_dir, '.bundle'),
'BUNDLE_INSTALL_FLAGS' => nil,
@@ -67,7 +71,7 @@ module GitalySetup
system('bundle config set --local retry 3', chdir: gemfile_dir)
if ENV['CI']
- bundle_path = File.expand_path('../../../vendor/gitaly-ruby', __dir__)
+ bundle_path = expand_path('vendor/gitaly-ruby')
system('bundle', 'config', 'set', '--local', 'path', bundle_path, chdir: gemfile_dir)
end
end
@@ -154,7 +158,7 @@ module GitalySetup
LOGGER.debug "Checking gitaly-ruby bundle...\n"
out = ENV['CI'] ? $stdout : '/dev/null'
- abort 'bundle check failed' unless system(env, 'bundle', 'check', out: out, chdir: File.dirname(gemfile))
+ abort 'bundle check failed' unless system(env, 'bundle', 'check', out: out, chdir: gemfile_dir)
end
def read_socket_path(service)
diff --git a/spec/support/helpers/gpg_helpers.rb b/spec/support/helpers/gpg_helpers.rb
index 81e669aab57..7e78fd86de3 100644
--- a/spec/support/helpers/gpg_helpers.rb
+++ b/spec/support/helpers/gpg_helpers.rb
@@ -138,7 +138,7 @@ module GpgHelpers
end
def primary_keyid
- fingerprint[-16..-1]
+ fingerprint[-16..]
end
def fingerprint
@@ -281,7 +281,7 @@ module GpgHelpers
end
def primary_keyid2
- fingerprint2[-16..-1]
+ fingerprint2[-16..]
end
def fingerprint2
@@ -374,7 +374,7 @@ module GpgHelpers
end
def primary_keyid
- fingerprint[-16..-1]
+ fingerprint[-16..]
end
def fingerprint
@@ -776,7 +776,7 @@ module GpgHelpers
end
def primary_keyid
- fingerprint[-16..-1]
+ fingerprint[-16..]
end
def fingerprint
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb
index 1f0c9b658dc..8b7d1c753d5 100644
--- a/spec/support/helpers/graphql_helpers.rb
+++ b/spec/support/helpers/graphql_helpers.rb
@@ -515,8 +515,13 @@ module GraphqlHelpers
# Allows for array indexing, like this
# ['project', 'boards', 'edges', 0, 'node', 'lists']
keys.reduce(data) do |memo, key|
- if memo.is_a?(Array)
- key.is_a?(Integer) ? memo[key] : memo.flat_map { |e| Array.wrap(e[key]) }
+ if memo.is_a?(Array) && key.is_a?(Integer)
+ memo[key]
+ elsif memo.is_a?(Array)
+ memo.compact.flat_map do |e|
+ x = e[key]
+ x.nil? ? [x] : Array.wrap(x)
+ end
else
memo&.dig(key)
end
diff --git a/spec/support/helpers/javascript_fixtures_helpers.rb b/spec/support/helpers/javascript_fixtures_helpers.rb
index fb909008f12..84cd0181533 100644
--- a/spec/support/helpers/javascript_fixtures_helpers.rb
+++ b/spec/support/helpers/javascript_fixtures_helpers.rb
@@ -13,6 +13,12 @@ module JavaScriptFixturesHelpers
included do |base|
base.around do |example|
+ # Don't actually run the example when we're only interested in the `test file -> JSON frontend fixture` mapping
+ if ENV['GENERATE_FRONTEND_FIXTURES_MAPPING'] == 'true'
+ $fixtures_mapping[example.metadata[:file_path].delete_prefix('./')] << File.join(fixture_root_path, example.description) # rubocop:disable Style/GlobalVars
+ next
+ end
+
# pick an arbitrary date from the past, so tests are not time dependent
# Also see spec/frontend/__helpers__/fake_date/jest.js
Timecop.freeze(Time.utc(2015, 7, 3, 10)) { example.run }
diff --git a/spec/support/helpers/memory_usage_helper.rb b/spec/support/helpers/memory_usage_helper.rb
index aa7b3bae83a..02d1935921f 100644
--- a/spec/support/helpers/memory_usage_helper.rb
+++ b/spec/support/helpers/memory_usage_helper.rb
@@ -23,7 +23,7 @@ module MemoryUsageHelper
output, status = Gitlab::Popen.popen(%w(free -m))
abort "`free -m` return code is #{status}: #{output}" unless status == 0
- result = output.split("\n")[1].split(" ")[1..-1]
+ result = output.split("\n")[1].split(" ")[1..]
attrs = %i(m_total m_used m_free m_shared m_buffers_cache m_available).freeze
attrs.zip(result).to_h
diff --git a/spec/support/helpers/migrations_helpers/work_item_types_helper.rb b/spec/support/helpers/migrations_helpers/work_item_types_helper.rb
new file mode 100644
index 00000000000..59b1f1b1305
--- /dev/null
+++ b/spec/support/helpers/migrations_helpers/work_item_types_helper.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module MigrationHelpers
+ module WorkItemTypesHelper
+ DEFAULT_WORK_ITEM_TYPES = {
+ issue: { name: 'Issue', icon_name: 'issue-type-issue', enum_value: 0 },
+ incident: { name: 'Incident', icon_name: 'issue-type-incident', enum_value: 1 },
+ test_case: { name: 'Test Case', icon_name: 'issue-type-test-case', enum_value: 2 },
+ requirement: { name: 'Requirement', icon_name: 'issue-type-requirements', enum_value: 3 },
+ task: { name: 'Task', icon_name: 'issue-type-task', enum_value: 4 }
+ }.freeze
+
+ def reset_work_item_types
+ work_item_types_table.delete_all
+
+ DEFAULT_WORK_ITEM_TYPES.each do |type, attributes|
+ work_item_types_table.create!(base_type: attributes[:enum_value], **attributes.slice(:name, :icon_name))
+ end
+ end
+
+ private
+
+ def work_item_types_table
+ table(:work_item_types)
+ end
+ end
+end
diff --git a/spec/support/helpers/modal_helpers.rb b/spec/support/helpers/modal_helpers.rb
new file mode 100644
index 00000000000..a1f03cc0da5
--- /dev/null
+++ b/spec/support/helpers/modal_helpers.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module Spec
+ module Support
+ module Helpers
+ module ModalHelpers
+ def within_modal
+ page.within('[role="dialog"]') do
+ yield
+ end
+ end
+
+ def accept_gl_confirm(text = nil, button_text: 'OK')
+ yield if block_given?
+
+ within_modal do
+ unless text.nil?
+ expect(page).to have_content(text)
+ end
+
+ click_button button_text
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/support/helpers/navbar_structure_helper.rb b/spec/support/helpers/navbar_structure_helper.rb
index c2ec82155cd..6fa69cbd6ad 100644
--- a/spec/support/helpers/navbar_structure_helper.rb
+++ b/spec/support/helpers/navbar_structure_helper.rb
@@ -19,6 +19,17 @@ module NavbarStructureHelper
hash[:nav_sub_items].insert(index + 1, new_sub_nav_item_name)
end
+ def insert_before_sub_nav_item(after_sub_nav_item_name, within:, new_sub_nav_item_name:)
+ expect(structure).to include(a_hash_including(nav_item: within))
+ hash = structure.find { |h| h[:nav_item] == within if h }
+
+ expect(hash).to have_key(:nav_sub_items)
+ expect(hash[:nav_sub_items]).to include(after_sub_nav_item_name)
+
+ index = hash[:nav_sub_items].find_index(after_sub_nav_item_name)
+ hash[:nav_sub_items].insert(index, new_sub_nav_item_name)
+ end
+
def insert_package_nav(within)
insert_after_nav_item(
within,
diff --git a/spec/support/helpers/session_helpers.rb b/spec/support/helpers/session_helpers.rb
index 4ef099a393e..236585296e5 100644
--- a/spec/support/helpers/session_helpers.rb
+++ b/spec/support/helpers/session_helpers.rb
@@ -17,10 +17,10 @@ module SessionHelpers
end
def get_session_keys
- Gitlab::Redis::SharedState.with { |redis| redis.scan_each(match: 'session:gitlab:*').to_a }
+ Gitlab::Redis::Sessions.with { |redis| redis.scan_each(match: 'session:gitlab:*').to_a }
end
def get_ttl(key)
- Gitlab::Redis::SharedState.with { |redis| redis.ttl(key) }
+ Gitlab::Redis::Sessions.with { |redis| redis.ttl(key) }
end
end
diff --git a/spec/support/helpers/snowplow_helpers.rb b/spec/support/helpers/snowplow_helpers.rb
index 553739b5d30..c8b194919ed 100644
--- a/spec/support/helpers/snowplow_helpers.rb
+++ b/spec/support/helpers/snowplow_helpers.rb
@@ -48,11 +48,15 @@ module SnowplowHelpers
# )
def expect_snowplow_event(category:, action:, context: nil, **kwargs)
if context
- kwargs[:context] = []
- context.each do |c|
- expect(SnowplowTracker::SelfDescribingJson).to have_received(:new)
- .with(c[:schema], c[:data]).at_least(:once)
- kwargs[:context] << an_instance_of(SnowplowTracker::SelfDescribingJson)
+ if context.is_a?(Array)
+ kwargs[:context] = []
+ context.each do |c|
+ expect(SnowplowTracker::SelfDescribingJson).to have_received(:new)
+ .with(c[:schema], c[:data]).at_least(:once)
+ kwargs[:context] << an_instance_of(SnowplowTracker::SelfDescribingJson)
+ end
+ else
+ kwargs[:context] = context
end
end
diff --git a/spec/support/helpers/stub_gitlab_calls.rb b/spec/support/helpers/stub_gitlab_calls.rb
index ef3c39c83c2..ae031f58bd4 100644
--- a/spec/support/helpers/stub_gitlab_calls.rb
+++ b/spec/support/helpers/stub_gitlab_calls.rb
@@ -93,7 +93,7 @@ module StubGitlabCalls
def stub_commonmark_sourcepos_disabled
render_options =
- if Feature.enabled?(:use_cmark_renderer)
+ if Feature.enabled?(:use_cmark_renderer, default_enabled: :yaml)
Banzai::Filter::MarkdownEngines::CommonMark::RENDER_OPTIONS_C
else
Banzai::Filter::MarkdownEngines::CommonMark::RENDER_OPTIONS_RUBY
diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb
index acbc15f7b62..d36bc4e3cb4 100644
--- a/spec/support/helpers/test_env.rb
+++ b/spec/support/helpers/test_env.rb
@@ -53,7 +53,7 @@ module TestEnv
'wip' => 'b9238ee',
'csv' => '3dd0896',
'v1.1.0' => 'b83d6e3',
- 'add-ipython-files' => '2b5ef814',
+ 'add-ipython-files' => '532c837',
'add-pdf-file' => 'e774ebd',
'squash-large-files' => '54cec52',
'add-pdf-text-binary' => '79faa7b',
@@ -594,6 +594,8 @@ module TestEnv
# Not a git SHA, so return early
return false unless expected_version =~ ::Gitlab::Git::COMMIT_ID
+ return false unless Dir.exist?(component_folder)
+
sha, exit_status = Gitlab::Popen.popen(%W(#{Gitlab.config.git.bin_path} rev-parse HEAD), component_folder)
return false if exit_status != 0