diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-16 09:08:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-16 09:08:48 +0300 |
commit | b394e58cc2e52e17e7991e3d7b705aa383c362ee (patch) | |
tree | c8fd512f3b9018ff2d007161b825ff22463370d4 /spec | |
parent | e5aec0ddbc6e3122f5e2425e92b30c4cd2184c90 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
4 files changed, 128 insertions, 2 deletions
diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb index 5f0d697b1e0..3e08d2277c1 100644 --- a/spec/features/admin/admin_settings_spec.rb +++ b/spec/features/admin/admin_settings_spec.rb @@ -984,7 +984,17 @@ RSpec.describe 'Admin updates settings', feature_category: :shared do end context 'when service data cached', :use_clean_rails_memory_store_caching do + let(:usage_data) { { uuid: "1111", hostname: "localhost", counts: { issue: 0 } }.deep_stringify_keys } + before do + # We are mocking Gitlab::Usage::ServicePingReport because this dataset generation + # takes a very long time, and is not what we're testing in this context. + # + # See https://gitlab.com/gitlab-org/gitlab/-/issues/414929 + allow(Gitlab::UsageData).to receive(:data).and_return(usage_data) + allow(Gitlab::Usage::ServicePingReport).to receive(:with_instrumentation_classes) + .with(usage_data, :with_value).and_return(usage_data) + visit usage_data_admin_application_settings_path visit service_usage_data_admin_application_settings_path end diff --git a/spec/frontend/analytics/shared/components/projects_dropdown_filter_spec.js b/spec/frontend/analytics/shared/components/projects_dropdown_filter_spec.js index 364f0a2e372..4e0b546b3d2 100644 --- a/spec/frontend/analytics/shared/components/projects_dropdown_filter_spec.js +++ b/spec/frontend/analytics/shared/components/projects_dropdown_filter_spec.js @@ -153,6 +153,7 @@ describe('ProjectsDropdownFilter component', () => { beforeEach(() => { createComponent({ mountFn: mountExtended, + props: blockDefaultProps, }); }); @@ -168,14 +169,16 @@ describe('ProjectsDropdownFilter component', () => { expect(findSelectedProjectsLabel().text()).toBe(projects[0].name); }); - it('renders the clear all button', () => { + it('renders the clear all button', async () => { + await selectDropdownItemAtIndex([0], false); + expect(findClearAllButton().exists()).toBe(true); }); it('clears all selected items when the clear all button is clicked', async () => { createComponent({ mountFn: mountExtended, - props: { multiSelect: true }, + props: blockDefaultProps, }); await waitForPromises(); diff --git a/spec/frontend/lib/utils/listbox_helpers_spec.js b/spec/frontend/lib/utils/listbox_helpers_spec.js new file mode 100644 index 00000000000..189aad41ceb --- /dev/null +++ b/spec/frontend/lib/utils/listbox_helpers_spec.js @@ -0,0 +1,89 @@ +import { getSelectedOptionsText } from '~/lib/utils/listbox_helpers'; + +describe('getSelectedOptionsText', () => { + it('returns an empty string per default when no options are selected', () => { + const options = [ + { id: 1, text: 'first' }, + { id: 2, text: 'second' }, + ]; + const selected = []; + + expect(getSelectedOptionsText({ options, selected })).toBe(''); + }); + + it('returns the provided placeholder when no options are selected', () => { + const options = [ + { id: 1, text: 'first' }, + { id: 2, text: 'second' }, + ]; + const selected = []; + const placeholder = 'placeholder'; + + expect(getSelectedOptionsText({ options, selected, placeholder })).toBe(placeholder); + }); + + describe('maxOptionsShown is not provided', () => { + it('returns the text of the first selected option when only one option is selected', () => { + const options = [{ id: 1, text: 'first' }]; + const selected = [options[0].id]; + + expect(getSelectedOptionsText({ options, selected })).toBe('first'); + }); + + it('should also work with the value property', () => { + const options = [{ value: 1, text: 'first' }]; + const selected = [options[0].value]; + + expect(getSelectedOptionsText({ options, selected })).toBe('first'); + }); + + it.each` + options | expectedText + ${[{ id: 1, text: 'first' }, { id: 2, text: 'second' }]} | ${'first +1 more'} + ${[{ id: 1, text: 'first' }, { id: 2, text: 'second' }, { id: 3, text: 'third' }]} | ${'first +2 more'} + `( + 'returns "$expectedText" when more than one option is selected', + ({ options, expectedText }) => { + const selected = options.map(({ id }) => id); + + expect(getSelectedOptionsText({ options, selected })).toBe(expectedText); + }, + ); + }); + + describe('maxOptionsShown > 1', () => { + const options = [ + { id: 1, text: 'first' }, + { id: 2, text: 'second' }, + { id: 3, text: 'third' }, + { id: 4, text: 'fourth' }, + { id: 5, text: 'fifth' }, + ]; + + it.each` + selected | maxOptionsShown | expectedText + ${[1]} | ${2} | ${'first'} + ${[1, 2]} | ${2} | ${'first, second'} + ${[1, 2, 3]} | ${2} | ${'first, second +1 more'} + ${[1, 2, 3]} | ${3} | ${'first, second, third'} + ${[1, 2, 3, 4]} | ${3} | ${'first, second, third +1 more'} + ${[1, 2, 3, 4, 5]} | ${3} | ${'first, second, third +2 more'} + `( + 'returns "$expectedText" when "$selected.length" options are selected and maxOptionsShown is "$maxOptionsShown"', + ({ selected, maxOptionsShown, expectedText }) => { + expect(getSelectedOptionsText({ options, selected, maxOptionsShown })).toBe(expectedText); + }, + ); + }); + + it('ignores selected options that are not in the options array', () => { + const options = [ + { id: 1, text: 'first' }, + { id: 2, text: 'second' }, + ]; + const invalidOption = { id: 3, text: 'third' }; + const selected = [options[0].id, options[1].id, invalidOption.id]; + + expect(getSelectedOptionsText({ options, selected })).toBe('first +1 more'); + }); +}); diff --git a/spec/lib/gitlab/audit/type/definition_spec.rb b/spec/lib/gitlab/audit/type/definition_spec.rb index d1d6b0d7a78..9c311677883 100644 --- a/spec/lib/gitlab/audit/type/definition_spec.rb +++ b/spec/lib/gitlab/audit/type/definition_spec.rb @@ -281,6 +281,30 @@ RSpec.describe Gitlab::Audit::Type::Definition do end end + describe '.names_with_category' do + let(:store1) { Dir.mktmpdir('path1') } + + before do + allow(described_class).to receive(:paths).and_return( + [ + File.join(store1, '**', '*.yml') + ] + ) + end + + subject { described_class.names_with_category } + + after do + FileUtils.rm_rf(store1) + end + + it "returns an array with just the event name and feature category" do + write_audit_event_type(store1, path, yaml_content) + + expect(subject).to eq([{ event_name: :group_deploy_token_destroyed, feature_category: 'continuous_delivery' }]) + end + end + def write_audit_event_type(store, path, content) path = File.join(store, path) dir = File.dirname(path) |