diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-21 12:10:27 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-21 12:10:27 +0000 |
commit | 888264e6b732927699bc2c855a8184aa2a095fbb (patch) | |
tree | 8cc728e4b0d2efe86a3549b07574d0d2bbbf603f /spec | |
parent | 34ad6d995bcab9f88a236bfed15aebdad76df960 (diff) | |
download | gitlab-ce-888264e6b732927699bc2c855a8184aa2a095fbb.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
29 files changed, 273 insertions, 326 deletions
diff --git a/spec/features/alerts_settings/user_views_alerts_settings_spec.rb b/spec/features/alerts_settings/user_views_alerts_settings_spec.rb index 6675abd6b42..60f2f776595 100644 --- a/spec/features/alerts_settings/user_views_alerts_settings_spec.rb +++ b/spec/features/alerts_settings/user_views_alerts_settings_spec.rb @@ -25,7 +25,7 @@ RSpec.describe 'Alert integrations settings form', :js do it 'shows the alerts setting form title' do page.within('#js-alert-management-settings') do - expect(find('h4')).to have_content('Alert integrations') + expect(find('h4')).to have_content('Alerts') end end diff --git a/spec/features/projects/settings/user_searches_in_settings_spec.rb b/spec/features/projects/settings/user_searches_in_settings_spec.rb index 9b09958bae5..a60743f0e47 100644 --- a/spec/features/projects/settings/user_searches_in_settings_spec.rb +++ b/spec/features/projects/settings/user_searches_in_settings_spec.rb @@ -63,7 +63,7 @@ RSpec.describe 'User searches project settings', :js do visit project_settings_operations_path(project) end - it_behaves_like 'can search settings', 'Alert integrations', 'Error tracking' + it_behaves_like 'can search settings', 'Alerts', 'Error tracking' end context 'in Pages page' do diff --git a/spec/finders/concerns/packages/finder_helper_spec.rb b/spec/finders/concerns/packages/finder_helper_spec.rb index bad4c482bc6..e8648d131ff 100644 --- a/spec/finders/concerns/packages/finder_helper_spec.rb +++ b/spec/finders/concerns/packages/finder_helper_spec.rb @@ -113,41 +113,22 @@ RSpec.describe ::Packages::FinderHelper do let_it_be(:user) { create(:deploy_token, :group, read_package_registry: true) } let_it_be(:group_deploy_token) { create(:group_deploy_token, deploy_token: user, group: group) } - shared_examples 'handling all conditions' do - where(:group_visibility, :subgroup_visibility, :project2_visibility, :shared_example_name) do - 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | 'returning both packages' - 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | 'returning both packages' - 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | 'returning both packages' - 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | 'returning both packages' - end - - with_them do - before do - project2.update!(visibility_level: Gitlab::VisibilityLevel.const_get(project2_visibility, false)) - subgroup.update!(visibility_level: Gitlab::VisibilityLevel.const_get(subgroup_visibility, false)) - project1.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) - group.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) - end - - it_behaves_like params[:shared_example_name] - end - end - - context 'with packages_finder_helper_deploy_token enabled' do - before do - expect(group).not_to receive(:all_projects) - end - - it_behaves_like 'handling all conditions' + where(:group_visibility, :subgroup_visibility, :project2_visibility, :shared_example_name) do + 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | 'returning both packages' + 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | 'returning both packages' + 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | 'returning both packages' + 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | 'returning both packages' end - context 'with packages_finder_helper_deploy_token disabled' do + with_them do before do - stub_feature_flags(packages_finder_helper_deploy_token: false) - expect(group).to receive(:all_projects).and_call_original + project2.update!(visibility_level: Gitlab::VisibilityLevel.const_get(project2_visibility, false)) + subgroup.update!(visibility_level: Gitlab::VisibilityLevel.const_get(subgroup_visibility, false)) + project1.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) + group.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) end - it_behaves_like 'handling all conditions' + it_behaves_like params[:shared_example_name] end end end @@ -236,41 +217,22 @@ RSpec.describe ::Packages::FinderHelper do let_it_be(:user) { create(:deploy_token, :group, read_package_registry: true) } let_it_be(:group_deploy_token) { create(:group_deploy_token, deploy_token: user, group: group) } - shared_examples 'handling all conditions' do - where(:group_visibility, :subgroup_visibility, :project2_visibility, :shared_example_name) do - 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | 'returning both projects' - 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | 'returning both projects' - 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | 'returning both projects' - 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | 'returning both projects' - end - - with_them do - before do - project2.update!(visibility_level: Gitlab::VisibilityLevel.const_get(project2_visibility, false)) - subgroup.update!(visibility_level: Gitlab::VisibilityLevel.const_get(subgroup_visibility, false)) - project1.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) - group.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) - end - - it_behaves_like params[:shared_example_name] - end - end - - context 'with packages_finder_helper_deploy_token enabled' do - before do - expect(group).not_to receive(:all_projects) - end - - it_behaves_like 'handling all conditions' + where(:group_visibility, :subgroup_visibility, :project2_visibility, :shared_example_name) do + 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | 'returning both projects' + 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | 'returning both projects' + 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | 'returning both projects' + 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | 'returning both projects' end - context 'with packages_finder_helper_deploy_token disabled' do + with_them do before do - stub_feature_flags(packages_finder_helper_deploy_token: false) - expect(group).to receive(:all_projects).and_call_original + project2.update!(visibility_level: Gitlab::VisibilityLevel.const_get(project2_visibility, false)) + subgroup.update!(visibility_level: Gitlab::VisibilityLevel.const_get(subgroup_visibility, false)) + project1.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) + group.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) end - it_behaves_like 'handling all conditions' + it_behaves_like params[:shared_example_name] end end end diff --git a/spec/frontend/alerts_settings/components/alerts_integrations_list_spec.js b/spec/frontend/alerts_settings/components/alerts_integrations_list_spec.js index c43d78a1cf3..3ffbb7ab60a 100644 --- a/spec/frontend/alerts_settings/components/alerts_integrations_list_spec.js +++ b/spec/frontend/alerts_settings/components/alerts_integrations_list_spec.js @@ -80,7 +80,7 @@ describe('AlertIntegrationsList', () => { const cell = finsStatusCell().at(0); const activatedIcon = cell.find(GlIcon); expect(cell.text()).toBe(i18n.status.enabled.name); - expect(activatedIcon.attributes('name')).toBe('check-circle-filled'); + expect(activatedIcon.attributes('name')).toBe('check'); expect(activatedIcon.attributes('title')).toBe(i18n.status.enabled.tooltip); }); diff --git a/spec/frontend/blob/components/table_contents_spec.js b/spec/frontend/blob/components/table_contents_spec.js new file mode 100644 index 00000000000..09633dc5d5d --- /dev/null +++ b/spec/frontend/blob/components/table_contents_spec.js @@ -0,0 +1,67 @@ +import { GlDropdownItem } from '@gitlab/ui'; +import { shallowMount } from '@vue/test-utils'; +import { nextTick } from 'vue'; +import TableContents from '~/blob/components/table_contents.vue'; + +let wrapper; + +function createComponent() { + wrapper = shallowMount(TableContents); +} + +async function setLoaded(loaded) { + document.querySelector('.blob-viewer').setAttribute('data-loaded', loaded); + + await nextTick(); +} + +describe('Markdown table of contents component', () => { + beforeEach(() => { + setFixtures(` + <div class="blob-viewer" data-type="rich" data-loaded="false"> + <h1><a href="#1"></a>Hello</h1> + <h2><a href="#2"></a>World</h2> + <h3><a href="#3"></a>Testing</h3> + <h2><a href="#4"></a>GitLab</h2> + </div> + `); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + describe('not loaded', () => { + it('does not populate dropdown', () => { + createComponent(); + + expect(wrapper.findComponent(GlDropdownItem).exists()).toBe(false); + }); + }); + + describe('loaded', () => { + it('populates dropdown', async () => { + createComponent(); + + await setLoaded(true); + + const dropdownItems = wrapper.findAllComponents(GlDropdownItem); + + expect(dropdownItems.exists()).toBe(true); + expect(dropdownItems.length).toBe(4); + }); + + it('sets padding for dropdown items', async () => { + createComponent(); + + await setLoaded(true); + + const dropdownLinks = wrapper.findAll('[data-testid="tableContentsLink"]'); + + expect(dropdownLinks.at(0).element.style.paddingLeft).toBe('0px'); + expect(dropdownLinks.at(1).element.style.paddingLeft).toBe('8px'); + expect(dropdownLinks.at(2).element.style.paddingLeft).toBe('16px'); + expect(dropdownLinks.at(3).element.style.paddingLeft).toBe('8px'); + }); + }); +}); diff --git a/spec/frontend/grafana_integration/components/__snapshots__/grafana_integration_spec.js.snap b/spec/frontend/grafana_integration/components/__snapshots__/grafana_integration_spec.js.snap index 1d2a5d636bc..7082d652706 100644 --- a/spec/frontend/grafana_integration/components/__snapshots__/grafana_integration_spec.js.snap +++ b/spec/frontend/grafana_integration/components/__snapshots__/grafana_integration_spec.js.snap @@ -43,14 +43,18 @@ exports[`grafana integration component default state to match the default snapsh class="settings-content" > <form> - <gl-form-checkbox-stub - class="mb-4" - id="grafana-integration-enabled" + <gl-form-group-stub + label="Enable authentication" + label-for="grafana-integration-enabled" > + <gl-form-checkbox-stub + id="grafana-integration-enabled" + > + + Active - Active - - </gl-form-checkbox-stub> + </gl-form-checkbox-stub> + </gl-form-group-stub> <gl-form-group-stub description="Enter the base URL of the Grafana instance." @@ -76,32 +80,19 @@ exports[`grafana integration component default state to match the default snapsh <p class="form-text text-muted" > - - Enter the Grafana API token. - - <a - href="https://grafana.com/docs/http_api/auth/#create-api-token" - rel="noopener noreferrer" - target="_blank" - > - - More information. - - <gl-icon-stub - class="vertical-align-middle" - name="external-link" - size="16" - /> - </a> + <gl-sprintf-stub + message="Enter the %{docLinkStart}Grafana API token%{docLinkEnd}." + /> </p> </gl-form-group-stub> <gl-button-stub buttontextclasses="" category="primary" + data-testid="save-grafana-settings-button" icon="" size="medium" - variant="success" + variant="confirm" > Save changes diff --git a/spec/frontend/grafana_integration/components/grafana_integration_spec.js b/spec/frontend/grafana_integration/components/grafana_integration_spec.js index f1a8e6fe2dc..d894cc7cc75 100644 --- a/spec/frontend/grafana_integration/components/grafana_integration_spec.js +++ b/spec/frontend/grafana_integration/components/grafana_integration_spec.js @@ -1,6 +1,7 @@ import { GlButton } from '@gitlab/ui'; -import { mount, shallowMount } from '@vue/test-utils'; +import { shallowMount } from '@vue/test-utils'; import { TEST_HOST } from 'helpers/test_constants'; +import { mountExtended } from 'helpers/vue_test_utils_helper'; import { deprecatedCreateFlash as createFlash } from '~/flash'; import GrafanaIntegration from '~/grafana_integration/components/grafana_integration.vue'; import { createStore } from '~/grafana_integration/store'; @@ -51,8 +52,7 @@ describe('grafana integration component', () => { it('renders as an expand button by default', () => { wrapper = shallowMount(GrafanaIntegration, { store }); - const button = wrapper.find(GlButton); - + const button = wrapper.findComponent(GlButton); expect(button.text()).toBe('Expand'); }); }); @@ -70,6 +70,7 @@ describe('grafana integration component', () => { describe('form', () => { beforeEach(() => { jest.spyOn(axios, 'patch').mockImplementation(); + wrapper = mountExtended(GrafanaIntegration, { store }); }); afterEach(() => { @@ -77,7 +78,7 @@ describe('grafana integration component', () => { }); describe('submit button', () => { - const findSubmitButton = () => wrapper.find('.settings-content form').find(GlButton); + const findSubmitButton = () => wrapper.findByTestId('save-grafana-settings-button'); const endpointRequest = [ operationsSettingsEndpoint, @@ -93,9 +94,7 @@ describe('grafana integration component', () => { ]; it('submits form on click', () => { - wrapper = mount(GrafanaIntegration, { store }); axios.patch.mockResolvedValue(); - findSubmitButton(wrapper).trigger('click'); expect(axios.patch).toHaveBeenCalledWith(...endpointRequest); @@ -104,7 +103,6 @@ describe('grafana integration component', () => { it('creates flash banner on error', () => { const message = 'mockErrorMessage'; - wrapper = mount(GrafanaIntegration, { store }); axios.patch.mockRejectedValue({ response: { data: { message } } }); findSubmitButton().trigger('click'); diff --git a/spec/frontend/incidents_settings/components/__snapshots__/alerts_form_spec.js.snap b/spec/frontend/incidents_settings/components/__snapshots__/alerts_form_spec.js.snap index 85d21f231b1..3d32585a211 100644 --- a/spec/frontend/incidents_settings/components/__snapshots__/alerts_form_spec.js.snap +++ b/spec/frontend/incidents_settings/components/__snapshots__/alerts_form_spec.js.snap @@ -103,7 +103,7 @@ exports[`Alert integration settings form default state should match the default icon="" size="medium" type="submit" - variant="success" + variant="confirm" > Save changes diff --git a/spec/frontend/incidents_settings/components/__snapshots__/incidents_settings_tabs_spec.js.snap b/spec/frontend/incidents_settings/components/__snapshots__/incidents_settings_tabs_spec.js.snap index 07f90a12f0f..450b1236015 100644 --- a/spec/frontend/incidents_settings/components/__snapshots__/incidents_settings_tabs_spec.js.snap +++ b/spec/frontend/incidents_settings/components/__snapshots__/incidents_settings_tabs_spec.js.snap @@ -30,7 +30,7 @@ exports[`IncidentsSettingTabs should render the component 1`] = ` <p> - Set up integrations with external tools to help better manage incidents. + Fine-tune incident settings and set up integrations with external tools to help better manage incidents. </p> </div> diff --git a/spec/frontend/incidents_settings/components/__snapshots__/pagerduty_form_spec.js.snap b/spec/frontend/incidents_settings/components/__snapshots__/pagerduty_form_spec.js.snap index 79ad5ad1bb9..a374ac7e4f2 100644 --- a/spec/frontend/incidents_settings/components/__snapshots__/pagerduty_form_spec.js.snap +++ b/spec/frontend/incidents_settings/components/__snapshots__/pagerduty_form_spec.js.snap @@ -66,20 +66,6 @@ exports[`Alert integration settings form should match the default snapshot 1`] = </gl-modal-stub> </gl-form-group-stub> - - <gl-button-stub - buttontextclasses="" - category="primary" - class="js-no-auto-disable" - icon="" - size="medium" - type="submit" - variant="success" - > - - Save changes - - </gl-button-stub> </form> </div> `; diff --git a/spec/frontend/incidents_settings/components/pagerduty_form_spec.js b/spec/frontend/incidents_settings/components/pagerduty_form_spec.js index 2ffd1292ddc..d2b591d427d 100644 --- a/spec/frontend/incidents_settings/components/pagerduty_form_spec.js +++ b/spec/frontend/incidents_settings/components/pagerduty_form_spec.js @@ -1,5 +1,5 @@ -import { GlAlert, GlModal } from '@gitlab/ui'; -import { shallowMount } from '@vue/test-utils'; +import { GlAlert, GlModal, GlToggle } from '@gitlab/ui'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import waitForPromises from 'helpers/wait_for_promises'; import PagerDutySettingsForm from '~/incidents_settings/components/pagerduty_form.vue'; @@ -8,13 +8,13 @@ describe('Alert integration settings form', () => { const resetWebhookUrl = jest.fn(); const service = { updateSettings: jest.fn().mockResolvedValue(), resetWebhookUrl }; - const findForm = () => wrapper.find({ ref: 'settingsForm' }); - const findWebhookInput = () => wrapper.find('[data-testid="webhook-url"]'); - const findModal = () => wrapper.find(GlModal); - const findAlert = () => wrapper.find(GlAlert); + const findWebhookInput = () => wrapper.findByTestId('webhook-url'); + const findFormToggle = () => wrapper.findComponent(GlToggle); + const findModal = () => wrapper.findComponent(GlModal); + const findAlert = () => wrapper.findComponent(GlAlert); beforeEach(() => { - wrapper = shallowMount(PagerDutySettingsForm, { + wrapper = shallowMountExtended(PagerDutySettingsForm, { provide: { service, pagerDutySettings: { @@ -27,18 +27,15 @@ describe('Alert integration settings form', () => { }); afterEach(() => { - if (wrapper) { - wrapper.destroy(); - wrapper = null; - } + wrapper.destroy(); }); it('should match the default snapshot', () => { expect(wrapper.element).toMatchSnapshot(); }); - it('should call service `updateSettings` on form submit', () => { - findForm().trigger('submit'); + it('should call service `updateSettings` on toggle change', () => { + findFormToggle().vm.$emit('change', true); expect(service.updateSettings).toHaveBeenCalledWith( expect.objectContaining({ pagerduty_active: wrapper.vm.active }), ); diff --git a/spec/frontend/nav/components/top_nav_menu_item_spec.js b/spec/frontend/nav/components/top_nav_menu_item_spec.js index 579af13d08a..e2cacba1a68 100644 --- a/spec/frontend/nav/components/top_nav_menu_item_spec.js +++ b/spec/frontend/nav/components/top_nav_menu_item_spec.js @@ -7,6 +7,8 @@ const TEST_MENU_ITEM = { icon: 'search', href: '/pretty/good/burger', view: 'burger-view', + css_class: 'test-super-crazy test-class', + data: { qa_selector: 'not-a-real-selector', method: 'post', testFoo: 'test' }, }; describe('~/nav/components/top_nav_menu_item.vue', () => { @@ -47,6 +49,22 @@ describe('~/nav/components/top_nav_menu_item.vue', () => { expect(button.text()).toBe(TEST_MENU_ITEM.title); }); + it('renders button classes', () => { + const button = findButton(); + + expect(button.classes()).toEqual(expect.arrayContaining(TEST_MENU_ITEM.css_class.split(' '))); + }); + + it('renders button data attributes', () => { + const button = findButton(); + + expect(button.attributes()).toMatchObject({ + 'data-qa-selector': TEST_MENU_ITEM.data.qa_selector, + 'data-method': TEST_MENU_ITEM.data.method, + 'data-test-foo': TEST_MENU_ITEM.data.testFoo, + }); + }); + it('passes listeners to button', () => { expect(listener).not.toHaveBeenCalled(); diff --git a/spec/frontend/operation_settings/components/metrics_settings_spec.js b/spec/frontend/operation_settings/components/metrics_settings_spec.js index 272e9b71f67..9d2530ded1e 100644 --- a/spec/frontend/operation_settings/components/metrics_settings_spec.js +++ b/spec/frontend/operation_settings/components/metrics_settings_spec.js @@ -56,7 +56,7 @@ describe('operation settings external dashboard component', () => { it('renders header text', () => { mountComponent(); - expect(wrapper.find('.js-section-header').text()).toBe('Metrics dashboard'); + expect(wrapper.find('.js-section-header').text()).toBe('Metrics'); }); describe('expand/collapse button', () => { @@ -77,13 +77,13 @@ describe('operation settings external dashboard component', () => { }); it('renders descriptive text', () => { - expect(subHeader.text()).toContain('Manage Metrics Dashboard settings.'); + expect(subHeader.text()).toContain('Manage metrics dashboard settings.'); }); it('renders help page link', () => { const link = subHeader.find(GlLink); - expect(link.text()).toBe('Learn more'); + expect(link.text()).toBe('Learn more.'); expect(link.attributes().href).toBe(helpPage); }); }); diff --git a/spec/graphql/mutations/issues/set_subscription_spec.rb b/spec/graphql/mutations/issues/set_subscription_spec.rb index 9e05a136c0b..7e2c3d93c51 100644 --- a/spec/graphql/mutations/issues/set_subscription_spec.rb +++ b/spec/graphql/mutations/issues/set_subscription_spec.rb @@ -3,8 +3,38 @@ require 'spec_helper' RSpec.describe Mutations::Issues::SetSubscription do - it_behaves_like 'a subscribeable graphql resource' do - let_it_be(:resource) { create(:issue) } - let(:permission_name) { :update_issue } + let_it_be_with_reload(:project) { create(:project) } + let_it_be_with_reload(:resource) { create(:issue, project: project) } + let_it_be(:user) { create(:user) } + + specify { expect(described_class).to require_graphql_authorizations(:update_subscription) } + + context 'when user does not have access to the project' do + it_behaves_like 'a subscribeable not accessible graphql resource' + end + + context 'when user is developer member of the project' do + before do + project.add_developer(user) + end + + it_behaves_like 'a subscribeable graphql resource' + end + + context 'when the project is public' do + before do + project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + end + + it_behaves_like 'a subscribeable graphql resource' + end + + context 'when the project is public but the issue is confidential' do + before do + project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + resource.update!(confidential: true) + end + + it_behaves_like 'a subscribeable not accessible graphql resource' end end diff --git a/spec/graphql/mutations/merge_requests/set_subscription_spec.rb b/spec/graphql/mutations/merge_requests/set_subscription_spec.rb index 600053637c9..377042f068c 100644 --- a/spec/graphql/mutations/merge_requests/set_subscription_spec.rb +++ b/spec/graphql/mutations/merge_requests/set_subscription_spec.rb @@ -3,8 +3,30 @@ require 'spec_helper' RSpec.describe Mutations::MergeRequests::SetSubscription do - it_behaves_like 'a subscribeable graphql resource' do - let_it_be(:resource) { create(:merge_request) } - let(:permission_name) { :update_merge_request } + let_it_be_with_reload(:project) { create(:project) } + let_it_be(:user) { create(:user) } + + let(:resource) { create(:merge_request, source_project: project, target_project: project) } + + specify { expect(described_class).to require_graphql_authorizations(:update_subscription) } + + context 'when user does not have access to the project' do + it_behaves_like 'a subscribeable not accessible graphql resource' + end + + context 'when user is developer member of the project' do + before do + project.add_developer(user) + end + + it_behaves_like 'a subscribeable graphql resource' + end + + context 'when the project is public' do + before do + project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + end + + it_behaves_like 'a subscribeable graphql resource' end end diff --git a/spec/helpers/nav/top_nav_helper_spec.rb b/spec/helpers/nav/top_nav_helper_spec.rb index b73d77a4ea9..b9912171a73 100644 --- a/spec/helpers/nav/top_nav_helper_spec.rb +++ b/spec/helpers/nav/top_nav_helper_spec.rb @@ -424,7 +424,7 @@ RSpec.describe Nav::TopNavHelper do title: 'Leave Admin Mode', icon: 'lock-open', href: '/admin/session/destroy', - method: :post + data: { method: 'post' } ) expect(subject[:secondary].last).to eq(expected_leave_admin_mode_item) end diff --git a/spec/lib/gitlab/instrumentation/redis_base_spec.rb b/spec/lib/gitlab/instrumentation/redis_base_spec.rb index 07be0ccf6e9..a7e08b5a9bd 100644 --- a/spec/lib/gitlab/instrumentation/redis_base_spec.rb +++ b/spec/lib/gitlab/instrumentation/redis_base_spec.rb @@ -18,24 +18,6 @@ RSpec.describe Gitlab::Instrumentation::RedisBase, :request_store do end end - describe '.known_payload_keys' do - it 'returns generated payload keys' do - expect(instrumentation_class_a.known_payload_keys).to eq([:redis_instance_a_calls, - :redis_instance_a_duration_s, - :redis_instance_a_read_bytes, - :redis_instance_a_write_bytes]) - end - - it 'does not call calculation methods' do - expect(instrumentation_class_a).not_to receive(:get_request_count) - expect(instrumentation_class_a).not_to receive(:query_time) - expect(instrumentation_class_a).not_to receive(:read_bytes) - expect(instrumentation_class_a).not_to receive(:write_bytes) - - instrumentation_class_a.known_payload_keys - end - end - describe '.payload' do it 'returns values that are higher than 0' do allow(instrumentation_class_a).to receive(:get_request_count) { 1 } diff --git a/spec/lib/gitlab/instrumentation/redis_spec.rb b/spec/lib/gitlab/instrumentation/redis_spec.rb index e927f39cae2..d712d09bdd8 100644 --- a/spec/lib/gitlab/instrumentation/redis_spec.rb +++ b/spec/lib/gitlab/instrumentation/redis_spec.rb @@ -26,46 +26,6 @@ RSpec.describe Gitlab::Instrumentation::Redis do it_behaves_like 'aggregation of redis storage data', :read_bytes it_behaves_like 'aggregation of redis storage data', :write_bytes - describe '.known_payload_keys' do - it 'returns all known payload keys' do - expected_keys = [ - :redis_calls, - :redis_duration_s, - :redis_read_bytes, - :redis_write_bytes, - :redis_action_cable_calls, - :redis_action_cable_duration_s, - :redis_action_cable_read_bytes, - :redis_action_cable_write_bytes, - :redis_cache_calls, - :redis_cache_duration_s, - :redis_cache_read_bytes, - :redis_cache_write_bytes, - :redis_queues_calls, - :redis_queues_duration_s, - :redis_queues_read_bytes, - :redis_queues_write_bytes, - :redis_shared_state_calls, - :redis_shared_state_duration_s, - :redis_shared_state_read_bytes, - :redis_shared_state_write_bytes - ] - - expect(described_class.known_payload_keys).to eq(expected_keys) - end - - it 'does not call storage calculation methods' do - described_class::STORAGES.each do |storage| - expect(storage).not_to receive(:get_request_count) - expect(storage).not_to receive(:query_time) - expect(storage).not_to receive(:read_bytes) - expect(storage).not_to receive(:write_bytes) - end - - described_class.known_payload_keys - end - end - describe '.payload', :request_store do before do Gitlab::Redis::Cache.with { |redis| redis.set('cache-test', 321) } diff --git a/spec/lib/gitlab/nav/top_nav_menu_item_spec.rb b/spec/lib/gitlab/nav/top_nav_menu_item_spec.rb index 26f9ea3a637..c96bed2284b 100644 --- a/spec/lib/gitlab/nav/top_nav_menu_item_spec.rb +++ b/spec/lib/gitlab/nav/top_nav_menu_item_spec.rb @@ -11,7 +11,6 @@ RSpec.describe ::Gitlab::Nav::TopNavMenuItem do active: true, icon: 'icon', href: 'href', - method: 'method', view: 'view', css_class: 'css_class', data: {} diff --git a/spec/lib/gitlab/sidekiq_middleware/instrumentation_logger_spec.rb b/spec/lib/gitlab/sidekiq_middleware/instrumentation_logger_spec.rb index eb9ba50cdcd..8cf65e1be5b 100644 --- a/spec/lib/gitlab/sidekiq_middleware/instrumentation_logger_spec.rb +++ b/spec/lib/gitlab/sidekiq_middleware/instrumentation_logger_spec.rb @@ -24,58 +24,10 @@ RSpec.describe Gitlab::SidekiqMiddleware::InstrumentationLogger do stub_const('TestWorker', worker) end - describe '.keys' do - it 'returns all available payload keys' do - expected_keys = [ - :cpu_s, - :gitaly_calls, - :gitaly_duration_s, - :rugged_calls, - :rugged_duration_s, - :elasticsearch_calls, - :elasticsearch_duration_s, - :elasticsearch_timed_out_count, - :mem_objects, - :mem_bytes, - :mem_mallocs, - :redis_calls, - :redis_duration_s, - :redis_read_bytes, - :redis_write_bytes, - :redis_action_cable_calls, - :redis_action_cable_duration_s, - :redis_action_cable_read_bytes, - :redis_action_cable_write_bytes, - :redis_cache_calls, - :redis_cache_duration_s, - :redis_cache_read_bytes, - :redis_cache_write_bytes, - :redis_queues_calls, - :redis_queues_duration_s, - :redis_queues_read_bytes, - :redis_queues_write_bytes, - :redis_shared_state_calls, - :redis_shared_state_duration_s, - :redis_shared_state_read_bytes, - :redis_shared_state_write_bytes, - :db_count, - :db_write_count, - :db_cached_count, - :external_http_count, - :external_http_duration_s, - :rack_attack_redis_count, - :rack_attack_redis_duration_s - ] - - expect(described_class.keys).to include(*expected_keys) - end - end - describe '#call', :request_store do let(:instrumentation_values) do { cpu_s: 10, - unknown_attribute: 123, db_count: 0, db_cached_count: 0, db_write_count: 0, @@ -90,12 +42,10 @@ RSpec.describe Gitlab::SidekiqMiddleware::InstrumentationLogger do end end - it 'merges correct instrumentation data in the job' do + it 'merges all instrumentation data in the job' do expect { |b| subject.call(worker, job, queue, &b) }.to yield_control - expected_values = instrumentation_values.except(:unknown_attribute) - - expect(job[:instrumentation]).to eq(expected_values) + expect(job[:instrumentation]).to eq(instrumentation_values) end end end diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 72cd028b0b9..b0575b63c8a 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -594,6 +594,18 @@ RSpec.describe Member do end end + context 'when called with a known user secondary email' do + let(:secondary_email) { create(:email, email: 'secondary@example.com', user: user) } + + it 'adds the user as a member' do + expect(source.users).not_to include(user) + + described_class.add_user(source, secondary_email.email, :maintainer) + + expect(source.users.reload).to include(user) + end + end + context 'when called with an unknown user email' do it 'creates an invited member' do expect(source.users).not_to include(user) diff --git a/spec/policies/issue_policy_spec.rb b/spec/policies/issue_policy_spec.rb index 76788ae2cb7..ed0050e8224 100644 --- a/spec/policies/issue_policy_spec.rb +++ b/spec/policies/issue_policy_spec.rb @@ -139,13 +139,14 @@ RSpec.describe IssuePolicy do create(:project_group_link, group: group, project: project) end - it 'does not allow guest to create todos' do + it 'does not allow anonymous user to create todos' do expect(permissions(nil, issue)).to be_allowed(:read_issue) expect(permissions(nil, issue)).to be_disallowed(:create_todo) + expect(permissions(nil, issue)).to be_disallowed(:update_subscription) end it 'allows guests to read issues' do - expect(permissions(guest, issue)).to be_allowed(:read_issue, :read_issue_iid, :create_todo) + expect(permissions(guest, issue)).to be_allowed(:read_issue, :read_issue_iid, :create_todo, :update_subscription) expect(permissions(guest, issue)).to be_disallowed(:update_issue, :admin_issue, :reopen_issue) expect(permissions(guest, issue_no_assignee)).to be_allowed(:read_issue, :read_issue_iid) @@ -205,12 +206,18 @@ RSpec.describe IssuePolicy do it 'forbids visitors from commenting' do expect(permissions(visitor, issue)).to be_disallowed(:create_note) end + it 'forbids visitors from subscribing' do + expect(permissions(visitor, issue)).to be_disallowed(:update_subscription) + end it 'allows guests to view' do expect(permissions(guest, issue)).to be_allowed(:read_issue) end it 'allows guests to comment' do expect(permissions(guest, issue)).to be_allowed(:create_note) end + it 'allows guests to subscribe' do + expect(permissions(guest, issue)).to be_allowed(:update_subscription) + end context 'when admin mode is enabled', :enable_admin_mode do it 'allows admins to view' do diff --git a/spec/policies/merge_request_policy_spec.rb b/spec/policies/merge_request_policy_spec.rb index 744822f58d1..b94df4d4374 100644 --- a/spec/policies/merge_request_policy_spec.rb +++ b/spec/policies/merge_request_policy_spec.rb @@ -26,7 +26,8 @@ RSpec.describe MergeRequestPolicy do read_merge_request create_todo approve_merge_request - create_note].freeze + create_note + update_subscription].freeze shared_examples_for 'a denied user' do let(:perms) { permissions(subject, merge_request) } @@ -55,7 +56,7 @@ RSpec.describe MergeRequestPolicy do subject { permissions(nil, merge_request) } it do - is_expected.to be_disallowed(:create_todo) + is_expected.to be_disallowed(:create_todo, :update_subscription) end end end diff --git a/spec/services/members/invite_service_spec.rb b/spec/services/members/invite_service_spec.rb index d7fd7d5b2ca..7007d37ad8d 100644 --- a/spec/services/members/invite_service_spec.rb +++ b/spec/services/members/invite_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Members::InviteService, :aggregate_failures, :clean_gitlab_redis_shared_state, :sidekiq_inline do - let_it_be(:project) { create(:project) } + let_it_be(:project, reload: true) { create(:project) } let_it_be(:user) { project.owner } let_it_be(:project_user) { create(:user) } let_it_be(:namespace) { project.namespace } @@ -23,6 +23,18 @@ RSpec.describe Members::InviteService, :aggregate_failures, :clean_gitlab_redis_ it_behaves_like 'records an onboarding progress action', :user_added end + context 'when email belongs to an existing user as a secondary email' do + let(:secondary_email) { create(:email, email: 'secondary@example.com', user: project_user) } + let(:params) { { email: secondary_email.email } } + + it 'adds an existing user to members', :aggregate_failures do + expect_to_create_members(count: 1) + expect(result[:status]).to eq(:success) + expect(project.users).to include project_user + expect(project.members.last).not_to be_invite + end + end + context 'when email is not a valid email' do let(:params) { { email: '_bogus_' } } diff --git a/spec/services/merge_requests/create_service_spec.rb b/spec/services/merge_requests/create_service_spec.rb index b2351ab53bd..da547716e1e 100644 --- a/spec/services/merge_requests/create_service_spec.rb +++ b/spec/services/merge_requests/create_service_spec.rb @@ -82,7 +82,7 @@ RSpec.describe MergeRequests::CreateService, :clean_gitlab_redis_shared_state do let(:opts) do { title: 'Awesome merge_request', - description: "well this is not done yet\n/wip", + description: "well this is not done yet\n/draft", source_branch: 'feature', target_branch: 'master', assignees: [user2] diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index 31263feb947..5b4d6188b66 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -307,7 +307,7 @@ RSpec.describe Notes::CreateService do ), # Set WIP status QuickAction.new( - action_text: "/wip", + action_text: "/draft", before_action: -> { issuable.reload.update!(title: "title") }, @@ -317,7 +317,7 @@ RSpec.describe Notes::CreateService do ), # Remove WIP status QuickAction.new( - action_text: "/wip", + action_text: "/draft", before_action: -> { issuable.reload.update!(title: "WIP: title") }, diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index f3ad69bae13..4af76bc65ab 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -1202,16 +1202,6 @@ RSpec.describe QuickActions::InterpretService do end it_behaves_like 'draft command' do - let(:content) { '/wip' } - let(:issuable) { merge_request } - end - - it_behaves_like 'undraft command' do - let(:content) { '/wip' } - let(:issuable) { merge_request } - end - - it_behaves_like 'draft command' do let(:content) { '/draft' } let(:issuable) { merge_request } end diff --git a/spec/support/shared_examples/graphql/mutations/resolves_subscription_shared_examples.rb b/spec/support/shared_examples/graphql/mutations/resolves_subscription_shared_examples.rb index ebba312e895..678bb908343 100644 --- a/spec/support/shared_examples/graphql/mutations/resolves_subscription_shared_examples.rb +++ b/spec/support/shared_examples/graphql/mutations/resolves_subscription_shared_examples.rb @@ -2,44 +2,37 @@ require 'spec_helper' -RSpec.shared_examples 'a subscribeable graphql resource' do - let(:project) { resource.project } - let_it_be(:user) { create(:user) } - - subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } +RSpec.shared_examples 'a subscribeable not accessible graphql resource' do + let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } - specify { expect(described_class).to require_graphql_authorizations(permission_name) } + subject { mutation.resolve(project_path: resource.project.full_path, iid: resource.iid, subscribed_state: true) } - describe '#resolve' do - let(:subscribe) { true } - let(:mutated_resource) { subject[resource.class.name.underscore.to_sym] } - - subject { mutation.resolve(project_path: resource.project.full_path, iid: resource.iid, subscribed_state: subscribe) } + it 'raises an error if the resource is not accessible to the user' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end +end - it 'raises an error if the resource is not accessible to the user' do - expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - end +RSpec.shared_examples 'a subscribeable graphql resource' do + let(:mutated_resource) { subject[resource.class.name.underscore.to_sym] } + let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + let(:subscribe) { true } - context 'when the user can update the resource' do - before do - resource.project.add_developer(user) - end + subject { mutation.resolve(project_path: resource.project.full_path, iid: resource.iid, subscribed_state: subscribe) } - it 'subscribes to the resource' do - expect(mutated_resource).to eq(resource) - expect(mutated_resource.subscribed?(user, project)).to eq(true) - expect(subject[:errors]).to be_empty - end + it 'subscribes to the resource' do + expect(mutated_resource).to eq(resource) + expect(mutated_resource.subscribed?(user, project)).to eq(true) + expect(subject[:errors]).to be_empty + end - context 'when passing subscribe as false' do - let(:subscribe) { false } + context 'when passing subscribe as false' do + let(:subscribe) { false } - it 'unsubscribes from the discussion' do - resource.subscribe(user, project) + it 'unsubscribes from the discussion' do + resource.subscribe(user, project) - expect(mutated_resource.subscribed?(user, project)).to eq(false) - end - end + expect(mutated_resource.subscribed?(user, project)).to eq(false) + expect(subject[:errors]).to be_empty end end end diff --git a/spec/views/projects/settings/operations/show.html.haml_spec.rb b/spec/views/projects/settings/operations/show.html.haml_spec.rb index ab868eb78b8..5cf3e6d849c 100644 --- a/spec/views/projects/settings/operations/show.html.haml_spec.rb +++ b/spec/views/projects/settings/operations/show.html.haml_spec.rb @@ -36,7 +36,7 @@ RSpec.describe 'projects/settings/operations/show' do it 'renders the Operations Settings page' do render - expect(rendered).to have_content _('Alert integrations') + expect(rendered).to have_content _('Alerts') expect(rendered).to have_content _('Display alerts from all configured monitoring tools.') end end @@ -77,41 +77,11 @@ RSpec.describe 'projects/settings/operations/show' do end describe 'Operations > Tracing' do - context 'with project.tracing_external_url' do - it 'links to project.tracing_external_url' do - render - - expect(rendered).to have_link('Tracing', href: tracing_setting.external_url) - end - - context 'with malicious external_url' do - let(:malicious_tracing_url) { "https://replaceme.com/'><script>alert(document.cookie)</script>" } - let(:cleaned_url) { "https://replaceme.com/'>" } - - before do - tracing_setting.update_column(:external_url, malicious_tracing_url) - end - - it 'sanitizes external_url' do - render - - expect(tracing_setting.external_url).to eq(malicious_tracing_url) - expect(rendered).to have_link('Tracing', href: cleaned_url) - end - end - end - - context 'without project.tracing_external_url' do - let(:tracing_setting) { build(:project_tracing_setting, project: project) } - - before do - tracing_setting.external_url = nil - end - - it 'links to Tracing page' do + context 'Settings page ' do + it 'renders the Tracing Settings page' do render - expect(rendered).to have_link('Tracing', href: project_tracing_path(project)) + expect(rendered).to have_content _('Embed an image of your existing Jaeger server in GitLab.') end end end |