diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-03 00:16:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-03 00:16:54 +0300 |
commit | a1ee5ac49b801535223f7498762f0c0820165a1a (patch) | |
tree | 8bfde6b9f8ac7872aa368a2f8d6c657583ec809d /spec | |
parent | 05cde74f482201ed19d89c3c01ebf9b5d26cd4fd (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/experiments/application_experiment_spec.rb | 6 | ||||
-rw-r--r-- | spec/frontend/lib/utils/table_utility_spec.js | 29 | ||||
-rw-r--r-- | spec/frontend/settings_panels_spec.js | 14 | ||||
-rw-r--r-- | spec/helpers/projects/cluster_agents_helper_spec.rb | 29 | ||||
-rw-r--r-- | spec/support/gitlab_experiment.rb | 14 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb | 8 |
6 files changed, 83 insertions, 17 deletions
diff --git a/spec/experiments/application_experiment_spec.rb b/spec/experiments/application_experiment_spec.rb index 5146fe3e752..7c2b5382c42 100644 --- a/spec/experiments/application_experiment_spec.rb +++ b/spec/experiments/application_experiment_spec.rb @@ -117,7 +117,7 @@ RSpec.describe ApplicationExperiment, :experiment do describe '#publish_to_database' do using RSpec::Parameterized::TableSyntax - let(:publish_to_database) { application_experiment.publish_to_database } + let(:publish_to_database) { ActiveSupport::Deprecation.silence { application_experiment.publish_to_database } } shared_examples 'does not record to the database' do it 'does not create an experiment record' do @@ -358,11 +358,11 @@ RSpec.describe ApplicationExperiment, :experiment do stub_feature_flags(namespaced_stub: true) end - it "returns the first variant name" do + it "returns an assigned name" do application_experiment.try(:variant1) {} application_experiment.try(:variant2) {} - expect(application_experiment.variant.name).to eq('variant1') + expect(application_experiment.variant.name).to eq('variant2') end end end diff --git a/spec/frontend/lib/utils/table_utility_spec.js b/spec/frontend/lib/utils/table_utility_spec.js index 75b9252aa40..a67adac5efb 100644 --- a/spec/frontend/lib/utils/table_utility_spec.js +++ b/spec/frontend/lib/utils/table_utility_spec.js @@ -8,4 +8,33 @@ describe('table_utility', () => { expect(tableUtils.thWidthClass(width)).toBe(`gl-w-${width}p ${DEFAULT_TH_CLASSES}`); }); }); + + describe('sortObjectToString', () => { + it('returns the expected sorting string ending in "DESC" when sortDesc is true', () => { + expect(tableUtils.sortObjectToString({ sortBy: 'mergedAt', sortDesc: true })).toBe( + 'MERGED_AT_DESC', + ); + }); + + it('returns the expected sorting string ending in "ASC" when sortDesc is false', () => { + expect(tableUtils.sortObjectToString({ sortBy: 'mergedAt', sortDesc: false })).toBe( + 'MERGED_AT_ASC', + ); + }); + }); + + describe('sortStringToObject', () => { + it.each` + sortBy | sortDesc | sortString + ${'mergedAt'} | ${true} | ${'MERGED_AT_DESC'} + ${'mergedAt'} | ${false} | ${'MERGED_AT_ASC'} + ${'severity'} | ${true} | ${'SEVERITY_DESC'} + ${'severity'} | ${false} | ${'SEVERITY_ASC'} + `( + 'returns $sortString when sortBy = "$sortBy" and sortDesc = "sortDesc"', + ({ sortBy, sortDesc, sortString }) => { + expect(tableUtils.sortStringToObject(sortString)).toStrictEqual({ sortBy, sortDesc }); + }, + ); + }); }); diff --git a/spec/frontend/settings_panels_spec.js b/spec/frontend/settings_panels_spec.js index 6b739617b97..3a62cd703ab 100644 --- a/spec/frontend/settings_panels_spec.js +++ b/spec/frontend/settings_panels_spec.js @@ -24,6 +24,20 @@ describe('Settings Panels', () => { expect(isExpanded(panel)).toBe(true); }); + + it('should expand panel containing linked hash', () => { + window.location.hash = '#group_description'; + + const panel = document.querySelector('#js-general-settings'); + // Our test environment automatically expands everything so we need to clear that out first + panel.classList.remove('expanded'); + + expect(isExpanded(panel)).toBe(false); + + initSettingsPanels(); + + expect(isExpanded(panel)).toBe(true); + }); }); it('does not change the text content of triggers', () => { diff --git a/spec/helpers/projects/cluster_agents_helper_spec.rb b/spec/helpers/projects/cluster_agents_helper_spec.rb index 632544797ee..d94a5fa9f8a 100644 --- a/spec/helpers/projects/cluster_agents_helper_spec.rb +++ b/spec/helpers/projects/cluster_agents_helper_spec.rb @@ -5,22 +5,29 @@ require 'spec_helper' RSpec.describe Projects::ClusterAgentsHelper do describe '#js_cluster_agent_details_data' do let_it_be(:project) { create(:project) } + let_it_be(:current_user) { create(:user) } + let(:user_can_admin_vulerability) { true } let(:agent_name) { 'agent-name' } - subject { helper.js_cluster_agent_details_data(agent_name, project) } - - it 'returns name' do - expect(subject[:agent_name]).to eq(agent_name) + before do + allow(helper).to receive(:current_user).and_return(current_user) + allow(helper) + .to receive(:can?) + .with(current_user, :admin_vulnerability, project) + .and_return(user_can_admin_vulerability) end - it 'returns project path' do - expect(subject[:project_path]).to eq(project.full_path) - end + subject { helper.js_cluster_agent_details_data(agent_name, project) } - it 'returns string contants' do - expect(subject[:activity_empty_state_image]).to be_kind_of(String) - expect(subject[:empty_state_svg_path]).to be_kind_of(String) - end + it { + is_expected.to match({ + agent_name: agent_name, + project_path: project.full_path, + activity_empty_state_image: kind_of(String), + empty_state_svg_path: kind_of(String), + can_admin_vulnerability: "true" + }) + } end end diff --git a/spec/support/gitlab_experiment.rb b/spec/support/gitlab_experiment.rb index 3d099dc689c..cb5a4385e6b 100644 --- a/spec/support/gitlab_experiment.rb +++ b/spec/support/gitlab_experiment.rb @@ -10,9 +10,23 @@ RSpec.configure do |config| # Disable all caching for experiments in tests. config.before do allow(Gitlab::Experiment::Configuration).to receive(:cache).and_return(nil) + + # Disable all deprecation warnings in the test environment, which can be + # resolved one by one and tracked in: + # + # https://gitlab.com/gitlab-org/gitlab/-/issues/350944 + allow(Gitlab::Experiment::Configuration).to receive(:deprecator).and_wrap_original do |method, version| + method.call(version).tap do |deprecator| + deprecator.silenced = true + end + end end config.before(:each, :experiment) do stub_snowplow end end + +# Once you've resolved a given deprecation, you can disallow it here, which +# will raise an exception if it's used anywhere. +ActiveSupport::Deprecation.disallowed_warnings << "`experiment_group?` is deprecated" diff --git a/spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb index 5baa6478225..fdca326dbea 100644 --- a/spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true RSpec.shared_examples 'tracks assignment and records the subject' do |experiment, subject_type| + before do + stub_experiments(experiment => true) + end + it 'tracks the assignment', :experiment do expect(experiment(experiment)) .to track(:assignment) @@ -11,9 +15,7 @@ RSpec.shared_examples 'tracks assignment and records the subject' do |experiment end it 'records the subject' do - stub_experiments(experiment => :candidate) - - expect(Experiment).to receive(:add_subject).with(experiment.to_s, variant: :experimental, subject: subject) + expect(Experiment).to receive(:add_subject).with(experiment.to_s, variant: anything, subject: subject) action end |