diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-15 12:07:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-15 12:07:30 +0300 |
commit | 50e177d19bdeeb0fcc7b129b9c30841454df240b (patch) | |
tree | 11b30123cfec778cfa469bc23e17f40a45d43880 /spec | |
parent | 9cf113df885ac8959b9fab3aab5e50e2532fef75 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
11 files changed, 154 insertions, 17 deletions
diff --git a/spec/frontend/ci/runner/components/runner_platforms_radio_group_spec.js b/spec/frontend/ci/runner/components/runner_platforms_radio_group_spec.js index 12c9afe9758..db6fd2c369b 100644 --- a/spec/frontend/ci/runner/components/runner_platforms_radio_group_spec.js +++ b/spec/frontend/ci/runner/components/runner_platforms_radio_group_spec.js @@ -51,9 +51,9 @@ describe('RunnerPlatformsRadioGroup', () => { ['Linux', null], ['macOS', null], ['Windows', null], - ['AWS', mockProvide.awsImgPath], - ['Docker', mockProvide.dockerImgPath], - ['Kubernetes', mockProvide.kubernetesImgPath], + ['AWS', expect.any(String)], + ['Docker', expect.any(String)], + ['Kubernetes', expect.any(String)], ]); }); diff --git a/spec/frontend/helpers/init_simple_app_helper_spec.js b/spec/frontend/helpers/init_simple_app_helper_spec.js new file mode 100644 index 00000000000..8dd3745e0ac --- /dev/null +++ b/spec/frontend/helpers/init_simple_app_helper_spec.js @@ -0,0 +1,61 @@ +import { createWrapper } from '@vue/test-utils'; +import Vue from 'vue'; +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; +import { initSimpleApp } from '~/helpers/init_simple_app_helper'; + +const MockComponent = Vue.component('MockComponent', { + props: { + someKey: { + type: String, + required: false, + default: '', + }, + count: { + type: Number, + required: false, + default: 0, + }, + }, + render: (createElement) => createElement('span'), +}); + +let wrapper; + +const findMock = () => wrapper.findComponent(MockComponent); + +const didCreateApp = () => wrapper !== undefined; + +const initMock = (html, props = {}) => { + setHTMLFixture(html); + + const app = initSimpleApp('#mount-here', MockComponent, { props }); + + wrapper = app ? createWrapper(app) : undefined; +}; + +describe('helpers/init_simple_app_helper/initSimpleApp', () => { + afterEach(() => { + resetHTMLFixture(); + }); + + it('mounts the component if the selector exists', async () => { + initMock('<div id="mount-here"></div>'); + + expect(findMock().exists()).toBe(true); + }); + + it('does not mount the component if selector does not exist', async () => { + initMock('<div id="do-not-mount-here"></div>'); + + expect(didCreateApp()).toBe(false); + }); + + it('passes the prop to the component if the prop exists', async () => { + initMock(`<div id="mount-here" data-view-model={"someKey":"thing","count":123}></div>`); + + expect(findMock().props()).toEqual({ + someKey: 'thing', + count: 123, + }); + }); +}); diff --git a/spec/frontend/ide/init_gitlab_web_ide_spec.js b/spec/frontend/ide/init_gitlab_web_ide_spec.js index b5ad38addbd..bfc87f17092 100644 --- a/spec/frontend/ide/init_gitlab_web_ide_spec.js +++ b/spec/frontend/ide/init_gitlab_web_ide_spec.js @@ -3,6 +3,7 @@ import { GITLAB_WEB_IDE_FEEDBACK_ISSUE } from '~/ide/constants'; import { initGitlabWebIDE } from '~/ide/init_gitlab_web_ide'; import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_action'; import { createAndSubmitForm } from '~/lib/utils/create_and_submit_form'; +import { handleTracking } from '~/ide/lib/gitlab_web_ide/handle_tracking_event'; import { TEST_HOST } from 'helpers/test_constants'; import setWindowLocation from 'helpers/set_window_location_helper'; import waitForPromises from 'helpers/wait_for_promises'; @@ -115,6 +116,7 @@ describe('ide/init_gitlab_web_ide', () => { format: TEST_EDITOR_FONT_FORMAT, }, handleStartRemote: expect.any(Function), + handleTracking, }); }); diff --git a/spec/frontend/ide/lib/gitlab_web_ide/handle_tracking_event_spec.js b/spec/frontend/ide/lib/gitlab_web_ide/handle_tracking_event_spec.js new file mode 100644 index 00000000000..5dff9b6f118 --- /dev/null +++ b/spec/frontend/ide/lib/gitlab_web_ide/handle_tracking_event_spec.js @@ -0,0 +1,32 @@ +import { snakeCase } from 'lodash'; +import { handleTracking } from '~/ide/lib/gitlab_web_ide/handle_tracking_event'; +import { convertObjectPropsToSnakeCase } from '~/lib/utils/common_utils'; +import { mockTracking } from 'helpers/tracking_helper'; + +describe('ide/handle_tracking_event', () => { + let trackingSpy; + + beforeEach(() => { + trackingSpy = mockTracking(undefined, null, jest.spyOn); + }); + + describe('when the event does not contain data', () => { + it('does not send extra property to snowplow', () => { + const event = { name: 'event-name' }; + + handleTracking(event); + expect(trackingSpy).toHaveBeenCalledWith(undefined, snakeCase(event.name)); + }); + }); + + describe('when the event contains data', () => { + it('sends extra property to snowplow', () => { + const event = { name: 'event-name', data: { 'extra-details': 'details' } }; + + handleTracking(event); + expect(trackingSpy).toHaveBeenCalledWith(undefined, snakeCase(event.name), { + extra: convertObjectPropsToSnakeCase(event.data), + }); + }); + }); +}); diff --git a/spec/frontend/ide/remote/index_spec.js b/spec/frontend/ide/remote/index_spec.js index 0f23b0a4e45..413e7b2e4b7 100644 --- a/spec/frontend/ide/remote/index_spec.js +++ b/spec/frontend/ide/remote/index_spec.js @@ -3,6 +3,7 @@ import { getBaseConfig, setupRootElement } from '~/ide/lib/gitlab_web_ide'; import { mountRemoteIDE } from '~/ide/remote'; import { TEST_HOST } from 'helpers/test_constants'; import { useMockLocationHelper } from 'helpers/mock_window_location_helper'; +import { handleTracking } from '~/ide/lib/gitlab_web_ide/handle_tracking_event'; jest.mock('@gitlab/web-ide'); jest.mock('~/ide/lib/gitlab_web_ide'); @@ -24,7 +25,6 @@ const TEST_RETURN_URL_SAME_ORIGIN = `${TEST_HOST}/foo/example`; describe('~/ide/remote/index', () => { useMockLocationHelper(); const originalHref = window.location.href; - let el; let rootEl; @@ -56,6 +56,7 @@ describe('~/ide/remote/index', () => { hostPath: `/${TEST_DATA.remotePath}`, handleError: expect.any(Function), handleClose: expect.any(Function), + handleTracking, }); }); }); diff --git a/spec/frontend/issuable/related_issues/components/add_issuable_form_spec.js b/spec/frontend/issuable/related_issues/components/add_issuable_form_spec.js index 16d4459f597..e1546f74a59 100644 --- a/spec/frontend/issuable/related_issues/components/add_issuable_form_spec.js +++ b/spec/frontend/issuable/related_issues/components/add_issuable_form_spec.js @@ -1,6 +1,7 @@ import { GlFormGroup } from '@gitlab/ui'; import { mount, shallowMount } from '@vue/test-utils'; import { nextTick } from 'vue'; +import { TYPE_ISSUE } from '~/issues/constants'; import AddIssuableForm from '~/related_issues/components/add_issuable_form.vue'; import IssueToken from '~/related_issues/components/issue_token.vue'; import { issuableTypesMap, linkedIssueTypesMap, PathIdSeparator } from '~/related_issues/constants'; @@ -125,7 +126,7 @@ describe('AddIssuableForm', () => { wrapper = mount(AddIssuableForm, { propsData: { inputValue: '', - issuableType: issuableTypesMap.ISSUE, + issuableType: TYPE_ISSUE, pathIdSeparator, pendingReferences: [], }, @@ -156,9 +157,9 @@ describe('AddIssuableForm', () => { describe('categorized issuables', () => { it.each` - issuableType | pathIdSeparator | contextHeader | contextFooter - ${issuableTypesMap.ISSUE} | ${PathIdSeparator.Issue} | ${'The current issue'} | ${'the following issues'} - ${issuableTypesMap.EPIC} | ${PathIdSeparator.Epic} | ${'The current epic'} | ${'the following epics'} + issuableType | pathIdSeparator | contextHeader | contextFooter + ${TYPE_ISSUE} | ${PathIdSeparator.Issue} | ${'The current issue'} | ${'the following issues'} + ${issuableTypesMap.EPIC} | ${PathIdSeparator.Epic} | ${'The current epic'} | ${'the following epics'} `( 'show header text as "$contextHeader" and footer text as "$contextFooter" issuableType is set to $issuableType', ({ issuableType, contextHeader, contextFooter }) => { @@ -184,7 +185,7 @@ describe('AddIssuableForm', () => { propsData: { inputValue: '', showCategorizedIssues: true, - issuableType: issuableTypesMap.ISSUE, + issuableType: TYPE_ISSUE, pathIdSeparator, pendingReferences: [], }, diff --git a/spec/frontend/issuable/related_issues/components/related_issues_block_spec.js b/spec/frontend/issuable/related_issues/components/related_issues_block_spec.js index 996b2406240..ff8d5073005 100644 --- a/spec/frontend/issuable/related_issues/components/related_issues_block_spec.js +++ b/spec/frontend/issuable/related_issues/components/related_issues_block_spec.js @@ -6,10 +6,10 @@ import { issuable2, issuable3, } from 'jest/issuable/components/related_issuable_mock_data'; +import { TYPE_ISSUE } from '~/issues/constants'; import RelatedIssuesBlock from '~/related_issues/components/related_issues_block.vue'; import AddIssuableForm from '~/related_issues/components/add_issuable_form.vue'; import { - issuableTypesMap, linkedIssueTypesMap, linkedIssueTypesTextMap, PathIdSeparator, @@ -34,7 +34,7 @@ describe('RelatedIssuesBlock', () => { wrapper = mountExtended(RelatedIssuesBlock, { propsData: { pathIdSeparator: PathIdSeparator.Issue, - issuableType: issuableTypesMap.ISSUE, + issuableType: TYPE_ISSUE, }, }); }); @@ -237,7 +237,7 @@ describe('RelatedIssuesBlock', () => { propsData: { pathIdSeparator: PathIdSeparator.Issue, relatedIssues: [issuable1, issuable2, issuable3], - issuableType: issuableTypesMap.ISSUE, + issuableType: TYPE_ISSUE, }, }); }); diff --git a/spec/frontend/ml/experiment_tracking/components/ml_candidate_spec.js b/spec/frontend/ml/experiment_tracking/components/ml_candidate_spec.js index fb45c4b07a4..483e454d7d7 100644 --- a/spec/frontend/ml/experiment_tracking/components/ml_candidate_spec.js +++ b/spec/frontend/ml/experiment_tracking/components/ml_candidate_spec.js @@ -28,7 +28,7 @@ describe('MlCandidate', () => { }, }; - return mountExtended(MlCandidate, { provide: { candidate } }); + return mountExtended(MlCandidate, { propsData: { candidate } }); }; const findAlert = () => wrapper.findComponent(GlAlert); diff --git a/spec/frontend/related_issues/components/related_issuable_input_spec.js b/spec/frontend/related_issues/components/related_issuable_input_spec.js index f6a13856042..f7333bf6893 100644 --- a/spec/frontend/related_issues/components/related_issuable_input_spec.js +++ b/spec/frontend/related_issues/components/related_issuable_input_spec.js @@ -1,8 +1,9 @@ import { shallowMount } from '@vue/test-utils'; import { nextTick } from 'vue'; import { TEST_HOST } from 'helpers/test_constants'; +import { TYPE_ISSUE } from '~/issues/constants'; import RelatedIssuableInput from '~/related_issues/components/related_issuable_input.vue'; -import { issuableTypesMap, PathIdSeparator } from '~/related_issues/constants'; +import { PathIdSeparator } from '~/related_issues/constants'; jest.mock('ee_else_ce/gfm_auto_complete', () => { return function gfmAutoComplete() { @@ -21,7 +22,7 @@ describe('RelatedIssuableInput', () => { inputValue: '', references: [], pathIdSeparator: PathIdSeparator.Issue, - issuableType: issuableTypesMap.issue, + issuableType: TYPE_ISSUE, autoCompleteSources: { issues: `${TEST_HOST}/h5bp/html5-boilerplate/-/autocomplete_sources/issues`, }, diff --git a/spec/helpers/projects/ml/experiments_helper_spec.rb b/spec/helpers/projects/ml/experiments_helper_spec.rb index 6f6a5bceb2e..8ef81c49fa7 100644 --- a/spec/helpers/projects/ml/experiments_helper_spec.rb +++ b/spec/helpers/projects/ml/experiments_helper_spec.rb @@ -77,10 +77,10 @@ RSpec.describe Projects::Ml::ExperimentsHelper, feature_category: :mlops do end end - describe '#candidate_as_data' do + describe '#show_candidate_view_model' do let(:candidate) { candidate0 } - subject { Gitlab::Json.parse(helper.candidate_as_data(candidate)) } + subject { Gitlab::Json.parse(helper.show_candidate_view_model(candidate))['candidate'] } it 'generates the correct params' do expect(subject['params']).to include( diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/jira_active_integrations_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/jira_active_integrations_metric_spec.rb new file mode 100644 index 00000000000..104fd18ba2d --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/jira_active_integrations_metric_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::JiraActiveIntegrationsMetric, + feature_category: :integrations do + let(:options) { { deployment_type: 'cloud', series: 0 } } + let(:integration_attributes) { { active: true, deployment_type: 'cloud' } } + let(:expected_value) { 3 } + let(:expected_query) do + 'SELECT COUNT("integrations"."id") FROM "integrations" ' \ + 'INNER JOIN "jira_tracker_data" ON "jira_tracker_data"."integration_id" = "integrations"."id" ' \ + 'WHERE "integrations"."type_new" = \'Integrations::Jira\' AND "integrations"."active" = TRUE ' \ + 'AND "jira_tracker_data"."deployment_type" = 2' + end + + before do + create_list :jira_integration, 3, integration_attributes + + create :jira_integration, integration_attributes.merge(active: false) + create :jira_integration, integration_attributes.merge(deployment_type: 'server') + end + + it_behaves_like 'a correct instrumented metric value and query', + { options: { deployment_type: 'cloud' }, time_frame: 'all' } + + it "raises an exception if option is not present" do + expect do + described_class.new(options: options.except(:deployment_type), time_frame: 'all') + end.to raise_error(ArgumentError, %r{deployment_type .* must be one of}) + end + + it "raises an exception if option has invalid value" do + expect do + options[:deployment_type] = 'cloood' + described_class.new(options: options, time_frame: 'all') + end.to raise_error(ArgumentError, %r{deployment_type .* must be one of}) + end +end |