diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-25 03:09:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-25 03:09:46 +0300 |
commit | b48f85e16dcdda9fa2f96b7d2fe16e0a6ba28403 (patch) | |
tree | d9384e2775056f42722cbe10648193d2a381217d /spec | |
parent | e09f6bdfd191f0cf8e54f0bc272e4e0635990ed9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/components/pajamas/card_component_spec.rb | 80 | ||||
-rw-r--r-- | spec/features/projects/container_registry_spec.rb | 2 | ||||
-rw-r--r-- | spec/frontend/pipelines/pipeline_tabs_spec.js | 91 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/clusters/agent_spec.rb | 20 | ||||
-rw-r--r-- | spec/models/work_item_spec.rb | 22 | ||||
-rw-r--r-- | spec/models/work_items/parent_link_spec.rb | 10 |
7 files changed, 205 insertions, 21 deletions
diff --git a/spec/components/pajamas/card_component_spec.rb b/spec/components/pajamas/card_component_spec.rb new file mode 100644 index 00000000000..65522a9023f --- /dev/null +++ b/spec/components/pajamas/card_component_spec.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true +require "spec_helper" + +RSpec.describe Pajamas::CardComponent, :aggregate_failures, type: :component do + let(:header) { 'Card header' } + let(:body) { 'Card body' } + let(:footer) { 'Card footer' } + + context 'slots' do + before do + render_inline described_class.new do |c| + c.header { header } + c.body { body } + c.footer { footer } + end + end + + it 'renders card header' do + expect(rendered_component).to have_content(header) + end + + it 'renders card body' do + expect(rendered_component).to have_content(body) + end + + it 'renders footer' do + expect(rendered_component).to have_content(footer) + end + end + + context 'with defaults' do + before do + render_inline described_class.new + end + + it 'does not have a header or footer' do + expect(rendered_component).not_to have_selector('.gl-card-header') + expect(rendered_component).not_to have_selector('.gl-card-footer') + end + + it 'renders the card and body' do + expect(rendered_component).to have_selector('.gl-card') + expect(rendered_component).to have_selector('.gl-card-body') + end + end + + context 'with custom options' do + before do + render_inline described_class.new( + card_options: { class: '_card_class_', data: { testid: '_card_testid_' } }, + header_options: { class: '_header_class_', data: { testid: '_header_testid_' } }, + body_options: { class: '_body_class_', data: { testid: '_body_testid_' } }, + footer_options: { class: '_footer_class_', data: { testid: '_footer_testid_' } }) do |c| + c.header { header } + c.body { body } + c.footer { footer } + end + end + + it 'renders card options' do + expect(rendered_component).to have_selector('._card_class_') + expect(rendered_component).to have_selector('[data-testid="_card_testid_"]') + end + + it 'renders header options' do + expect(rendered_component).to have_selector('._header_class_') + expect(rendered_component).to have_selector('[data-testid="_header_testid_"]') + end + + it 'renders body options' do + expect(rendered_component).to have_selector('._body_class_') + expect(rendered_component).to have_selector('[data-testid="_body_testid_"]') + end + + it 'renders footer options' do + expect(rendered_component).to have_selector('._footer_class_') + expect(rendered_component).to have_selector('[data-testid="_footer_testid_"]') + end + end +end diff --git a/spec/features/projects/container_registry_spec.rb b/spec/features/projects/container_registry_spec.rb index 17eb421191f..54685441300 100644 --- a/spec/features/projects/container_registry_spec.rb +++ b/spec/features/projects/container_registry_spec.rb @@ -122,7 +122,7 @@ RSpec.describe 'Container Registry', :js do it 'renders the tags list correctly' do expect(page).to have_content('latest') expect(page).to have_content('stable') - expect(page).to have_content('Digest: N/A') + expect(page).to have_content('Digest: Not applicable.') end end diff --git a/spec/frontend/pipelines/pipeline_tabs_spec.js b/spec/frontend/pipelines/pipeline_tabs_spec.js new file mode 100644 index 00000000000..2c58780aa1c --- /dev/null +++ b/spec/frontend/pipelines/pipeline_tabs_spec.js @@ -0,0 +1,91 @@ +import { createAppOptions, createPipelineTabs } from '~/pipelines/pipeline_tabs'; +import { updateHistory } from '~/lib/utils/url_utility'; + +jest.mock('~/lib/utils/url_utility', () => ({ + removeParams: () => 'gitlab.com', + updateHistory: jest.fn(), + joinPaths: () => {}, + setUrlFragment: () => {}, +})); + +jest.mock('~/pipelines/utils', () => ({ + getPipelineDefaultTab: () => '', +})); + +describe('~/pipelines/pipeline_tabs.js', () => { + describe('createAppOptions', () => { + const SELECTOR = 'SELECTOR'; + + let el; + + const createElement = () => { + el = document.createElement('div'); + el.id = SELECTOR; + el.dataset.canGenerateCodequalityReports = 'true'; + el.dataset.codequalityReportDownloadPath = 'codequalityReportDownloadPath'; + el.dataset.downloadablePathForReportType = 'downloadablePathForReportType'; + el.dataset.exposeSecurityDashboard = 'true'; + el.dataset.exposeLicenseScanningData = 'true'; + el.dataset.graphqlResourceEtag = 'graphqlResourceEtag'; + el.dataset.pipelineIid = '123'; + el.dataset.pipelineProjectPath = 'pipelineProjectPath'; + + document.body.appendChild(el); + }; + + afterEach(() => { + el = null; + }); + + it("extracts the properties from the element's dataset", () => { + createElement(); + const options = createAppOptions(`#${SELECTOR}`, null); + + expect(options).toMatchObject({ + el, + provide: { + canGenerateCodequalityReports: true, + codequalityReportDownloadPath: 'codequalityReportDownloadPath', + downloadablePathForReportType: 'downloadablePathForReportType', + exposeSecurityDashboard: true, + exposeLicenseScanningData: true, + graphqlResourceEtag: 'graphqlResourceEtag', + pipelineIid: '123', + pipelineProjectPath: 'pipelineProjectPath', + }, + }); + }); + + it('returns `null` if el does not exist', () => { + expect(createAppOptions('foo', null)).toBe(null); + }); + }); + + describe('createPipelineTabs', () => { + const title = 'Pipeline Tabs'; + + beforeAll(() => { + document.title = title; + }); + + afterAll(() => { + document.title = ''; + }); + + it('calls `updateHistory` with correct params', () => { + createPipelineTabs({}); + + expect(updateHistory).toHaveBeenCalledWith({ + title, + url: 'gitlab.com', + replace: true, + }); + }); + + it("returns early if options aren't provided", () => { + createPipelineTabs(); + + expect(updateHistory).not.toHaveBeenCalled(); + }); + }); +}); diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 7edec6d13f4..cf65f1e7d30 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -723,7 +723,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do expect(counts_monthly[:projects_with_alerts_created]).to eq(1) expect(counts_monthly[:projects]).to eq(1) expect(counts_monthly[:packages]).to eq(1) - expect(counts_monthly[:promoted_issues]).to eq(Gitlab::UsageData::DEPRECATED_VALUE) end end diff --git a/spec/models/clusters/agent_spec.rb b/spec/models/clusters/agent_spec.rb index f10e0cc8fa7..f97e89912c6 100644 --- a/spec/models/clusters/agent_spec.rb +++ b/spec/models/clusters/agent_spec.rb @@ -7,8 +7,7 @@ RSpec.describe Clusters::Agent do it { is_expected.to belong_to(:created_by_user).class_name('User').optional } it { is_expected.to belong_to(:project).class_name('::Project') } - it { is_expected.to have_many(:agent_tokens).class_name('Clusters::AgentToken') } - it { is_expected.to have_many(:last_used_agent_tokens).class_name('Clusters::AgentToken') } + it { is_expected.to have_many(:agent_tokens).class_name('Clusters::AgentToken').order(Clusters::AgentToken.arel_table[:last_used_at].desc.nulls_last) } it { is_expected.to have_many(:group_authorizations).class_name('Clusters::Agents::GroupAuthorization') } it { is_expected.to have_many(:authorized_groups).through(:group_authorizations) } it { is_expected.to have_many(:project_authorizations).class_name('Clusters::Agents::ProjectAuthorization') } @@ -117,23 +116,6 @@ RSpec.describe Clusters::Agent do end end - describe '#last_used_agent_tokens' do - let_it_be(:agent) { create(:cluster_agent) } - - subject { agent.last_used_agent_tokens } - - context 'agent has no tokens' do - it { is_expected.to be_empty } - end - - context 'agent has active and inactive tokens' do - let!(:active_token) { create(:cluster_agent_token, agent: agent, last_used_at: 1.minute.ago) } - let!(:inactive_token) { create(:cluster_agent_token, agent: agent, last_used_at: 2.hours.ago) } - - it { is_expected.to contain_exactly(active_token, inactive_token) } - end - end - describe '#activity_event_deletion_cutoff' do let_it_be(:agent) { create(:cluster_agent) } let_it_be(:event1) { create(:agent_activity_event, agent: agent, recorded_at: 1.hour.ago) } diff --git a/spec/models/work_item_spec.rb b/spec/models/work_item_spec.rb index e92ae746911..d126e81f1cd 100644 --- a/spec/models/work_item_spec.rb +++ b/spec/models/work_item_spec.rb @@ -3,6 +3,28 @@ require 'spec_helper' RSpec.describe WorkItem do + describe 'associations' do + it { is_expected.to have_one(:work_item_parent).class_name('WorkItem') } + + it 'has one `parent_link`' do + is_expected.to have_one(:parent_link) + .class_name('::WorkItems::ParentLink') + .with_foreign_key('work_item_id') + end + + it 'has many `work_item_children`' do + is_expected.to have_many(:work_item_children) + .class_name('WorkItem') + .with_foreign_key('work_item_id') + end + + it 'has many `child_links`' do + is_expected.to have_many(:child_links) + .class_name('::WorkItems::ParentLink') + .with_foreign_key('work_item_parent_id') + end + end + describe '#noteable_target_type_name' do it 'returns `issue` as the target name' do work_item = build(:work_item) diff --git a/spec/models/work_items/parent_link_spec.rb b/spec/models/work_items/parent_link_spec.rb new file mode 100644 index 00000000000..a66f6e54734 --- /dev/null +++ b/spec/models/work_items/parent_link_spec.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe WorkItems::ParentLink do + describe 'associations' do + it { is_expected.to belong_to(:work_item) } + it { is_expected.to belong_to(:work_item_parent).class_name('WorkItem') } + end +end |