diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-25 15:07:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-25 15:07:15 +0300 |
commit | df65129ab40540728d4b391fc1a21d5a1de87b9c (patch) | |
tree | 70537d61226dcb2b330e76cbdf2b3c6f77fd6c62 /spec | |
parent | ef62043981093451b8ad3113d57c227251646f9f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
11 files changed, 139 insertions, 97 deletions
diff --git a/spec/factories/ai/service_access_tokens.rb b/spec/factories/ai/service_access_tokens.rb index 61abf4e1144..0598eed52c4 100644 --- a/spec/factories/ai/service_access_tokens.rb +++ b/spec/factories/ai/service_access_tokens.rb @@ -4,7 +4,6 @@ FactoryBot.define do factory :service_access_token, class: 'Ai::ServiceAccessToken' do token { SecureRandom.alphanumeric(10) } expires_at { Time.current + 1.day } - category { :code_suggestions } trait :active do expires_at { Time.current + 1.day } @@ -13,9 +12,5 @@ FactoryBot.define do trait :expired do expires_at { Time.current - 1.day } end - - trait :code_suggestions do - category { :code_suggestions } - end end end diff --git a/spec/features/admin/admin_runners_spec.rb b/spec/features/admin/admin_runners_spec.rb index 9edd970532e..676e5e7ad0e 100644 --- a/spec/features/admin/admin_runners_spec.rb +++ b/spec/features/admin/admin_runners_spec.rb @@ -591,7 +591,7 @@ RSpec.describe "Admin Runners", feature_category: :runner_fleet do describe 'runner header', :js do it 'contains the runner status, type and id' do expect(page).to have_content( - "##{project_runner.id} (#{project_runner.short_sha}) #{s_('Runners|Never contacted')} Project created" + "##{project_runner.id} (#{project_runner.short_sha}) #{s_('Runners|Never contacted')} Project Created" ) end end diff --git a/spec/frontend/ci/runner/components/cells/runner_summary_cell_spec.js b/spec/frontend/ci/runner/components/cells/runner_summary_cell_spec.js index bc77b7b89dd..27fb288c462 100644 --- a/spec/frontend/ci/runner/components/cells/runner_summary_cell_spec.js +++ b/spec/frontend/ci/runner/components/cells/runner_summary_cell_spec.js @@ -1,21 +1,15 @@ import { GlSprintf } from '@gitlab/ui'; -import { __, sprintf } from '~/locale'; +import { __ } from '~/locale'; import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; -import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue'; import RunnerSummaryCell from '~/ci/runner/components/cells/runner_summary_cell.vue'; import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue'; +import RunnerCreatedAt from '~/ci/runner/components/runner_created_at.vue'; import RunnerManagersBadge from '~/ci/runner/components/runner_managers_badge.vue'; import RunnerTags from '~/ci/runner/components/runner_tags.vue'; import RunnerSummaryField from '~/ci/runner/components/cells/runner_summary_field.vue'; import { getIdFromGraphQLId } from '~/graphql_shared/utils'; -import { - INSTANCE_TYPE, - I18N_INSTANCE_TYPE, - PROJECT_TYPE, - I18N_CREATED_AT_LABEL, - I18N_CREATED_AT_BY_LABEL, -} from '~/ci/runner/constants'; +import { INSTANCE_TYPE, I18N_INSTANCE_TYPE, PROJECT_TYPE } from '~/ci/runner/constants'; import { allRunnersWithCreatorData } from '../../mock_data'; @@ -182,45 +176,11 @@ describe('RunnerTypeCell', () => { expect(findRunnerSummaryField('pipeline').text()).toContain('1,000+'); }); - describe('Displays creation info', () => { - const findCreatedTime = () => findRunnerSummaryField('calendar').findComponent(TimeAgo); - - it('Displays created at ...', () => { - createComponent({ - runner: { createdBy: null }, - }); - - expect(findRunnerSummaryField('calendar').text()).toMatchInterpolatedText( - sprintf(I18N_CREATED_AT_LABEL, { - timeAgo: findCreatedTime().text(), - }), - ); - expect(findCreatedTime().props('time')).toBe(mockRunner.createdAt); - }); - - it('Displays created at ... by ...', () => { - createComponent({ mountFn: mountExtended }); - - expect(findRunnerSummaryField('calendar').text()).toMatchInterpolatedText( - sprintf(I18N_CREATED_AT_BY_LABEL, { - timeAgo: findCreatedTime().text(), - avatar: mockRunner.createdBy.username, - }), - ); - - expect(findCreatedTime().props('time')).toBe(mockRunner.createdAt); - }); - - it('Displays creator avatar', () => { - const { name, avatarUrl, webUrl, username } = mockRunner.createdBy; + it('Displays creation info', () => { + createComponent(); - expect(wrapper.findComponent(UserAvatarLink).props()).toMatchObject({ - imgAlt: expect.stringContaining(name), - imgSrc: avatarUrl, - linkHref: webUrl, - tooltipText: username, - }); - }); + const createdAt = findRunnerSummaryField('calendar').findComponent(RunnerCreatedAt); + expect(createdAt.props('runner')).toEqual(mockRunner); }); it('Displays tag list', () => { diff --git a/spec/frontend/ci/runner/components/runner_created_at_spec.js b/spec/frontend/ci/runner/components/runner_created_at_spec.js new file mode 100644 index 00000000000..19d1e55c72d --- /dev/null +++ b/spec/frontend/ci/runner/components/runner_created_at_spec.js @@ -0,0 +1,97 @@ +import { GlSprintf, GlLink } from '@gitlab/ui'; +import { getIdFromGraphQLId } from '~/graphql_shared/utils'; +import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue'; +import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue'; +import { mountExtended } from 'helpers/vue_test_utils_helper'; + +import RunnerCreatedAt from '~/ci/runner/components/runner_created_at.vue'; + +import { runnerData } from '../mock_data'; + +const mockRunner = runnerData.data.runner; + +describe('RunnerCreatedAt', () => { + let wrapper; + + const createWrapper = ({ runner = {} } = {}) => { + wrapper = mountExtended(RunnerCreatedAt, { + propsData: { + runner: { + ...mockRunner, + ...runner, + }, + }, + stubs: { + GlSprintf, + TimeAgo, + UserAvatarLink, + }, + }); + }; + + const findTimeAgo = () => wrapper.findComponent(TimeAgo); + const findLink = () => wrapper.findComponent(GlLink); + + const expectUserLink = (createdBy) => { + const { id, name, avatarUrl, webUrl, username } = createdBy; + + expect(findLink().text()).toBe(name); + expect(findLink().attributes('href')).toBe(webUrl); + expect({ ...findLink().element.dataset }).toEqual({ + avatarUrl, + name, + userId: `${getIdFromGraphQLId(id)}`, + username, + }); + }; + + beforeEach(() => { + createWrapper(); + }); + + it('shows creation time and creator', () => { + expect(wrapper.text()).toMatchInterpolatedText( + `Created by ${mockRunner.createdBy.name} ${findTimeAgo().text()}`, + ); + + expectUserLink(mockRunner.createdBy); + expect(findTimeAgo().props('time')).toBe(mockRunner.createdAt); + }); + + it('shows creation time with no creator', () => { + createWrapper({ + runner: { + createdBy: null, + }, + }); + + expect(wrapper.text()).toMatchInterpolatedText(`Created ${findTimeAgo().text()}`); + + expect(findLink().exists()).toBe(false); + expect(findTimeAgo().props('time')).toBe(mockRunner.createdAt); + }); + + it('shows creator with no creation time', () => { + createWrapper({ + runner: { + createdAt: null, + }, + }); + + expect(wrapper.text()).toMatchInterpolatedText(`Created by ${mockRunner.createdBy.name}`); + + expectUserLink(mockRunner.createdBy); + expect(findTimeAgo().exists()).toBe(false); + }); + + it('shows no creation information', () => { + createWrapper({ + runner: { + createdBy: null, + createdAt: null, + }, + }); + + expect(wrapper.html()).toBe(''); + }); +}); diff --git a/spec/frontend/ci/runner/components/runner_header_spec.js b/spec/frontend/ci/runner/components/runner_header_spec.js index f5091226eaa..c7d95c49d81 100644 --- a/spec/frontend/ci/runner/components/runner_header_spec.js +++ b/spec/frontend/ci/runner/components/runner_header_spec.js @@ -11,6 +11,7 @@ import { convertToGraphQLId } from '~/graphql_shared/utils'; import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue'; import RunnerHeader from '~/ci/runner/components/runner_header.vue'; +import RunnerCreatedAt from '~/ci/runner/components/runner_created_at.vue'; import RunnerTypeBadge from '~/ci/runner/components/runner_type_badge.vue'; import RunnerStatusBadge from '~/ci/runner/components/runner_status_badge.vue'; @@ -25,7 +26,6 @@ describe('RunnerHeader', () => { const findRunnerTypeBadge = () => wrapper.findComponent(RunnerTypeBadge); const findRunnerStatusBadge = () => wrapper.findComponent(RunnerStatusBadge); const findRunnerLockedIcon = () => wrapper.findByTestId('lock-icon'); - const findTimeAgo = () => wrapper.findComponent(TimeAgo); const createComponent = ({ runner = {}, options = {}, mountFn = shallowMountExtended } = {}) => { wrapper = mountFn(RunnerHeader, { @@ -86,24 +86,10 @@ describe('RunnerHeader', () => { expect(findRunnerLockedIcon().exists()).toBe(true); }); - it('displays the runner creation time', () => { + it('displays the runner creation data', () => { createComponent(); - expect(wrapper.text()).toMatch(/created .+/); - expect(findTimeAgo().props('time')).toBe(mockRunner.createdAt); - }); - - it('does not display runner creation time if "createdAt" is missing', () => { - createComponent({ - runner: { - id: convertToGraphQLId(TYPENAME_CI_RUNNER, 99), - createdAt: null, - }, - }); - - expect(wrapper.text()).toContain(`#99 (${mockRunnerSha})`); - expect(wrapper.text()).not.toMatch(/created .+/); - expect(findTimeAgo().exists()).toBe(false); + expect(wrapper.findComponent(RunnerCreatedAt).props('runner')).toEqual(mockRunner); }); it('displays actions in a slot', () => { diff --git a/spec/frontend/ci/runner/components/runner_update_form_spec.js b/spec/frontend/ci/runner/components/runner_update_form_spec.js index 2ba1c31fe52..a1ecedc6846 100644 --- a/spec/frontend/ci/runner/components/runner_update_form_spec.js +++ b/spec/frontend/ci/runner/components/runner_update_form_spec.js @@ -137,7 +137,15 @@ describe('RunnerUpdateForm', () => { await submitFormAndWait(); // Some read-only fields are not submitted - const { __typename, shortSha, runnerType, createdAt, status, ...submitted } = mockRunner; + const { + __typename, + shortSha, + runnerType, + createdAt, + createdBy, + status, + ...submitted + } = mockRunner; expectToHaveSubmittedRunnerContaining(submitted); }); diff --git a/spec/frontend/ci/runner/runner_edit/runner_edit_app_spec.js b/spec/frontend/ci/runner/runner_edit/runner_edit_app_spec.js index ee4bd9ccc92..6ceecd79163 100644 --- a/spec/frontend/ci/runner/runner_edit/runner_edit_app_spec.js +++ b/spec/frontend/ci/runner/runner_edit/runner_edit_app_spec.js @@ -64,7 +64,7 @@ describe('RunnerEditApp', () => { await createComponentWithApollo({ mountFn: mount }); expect(findRunnerHeader().text()).toContain(`#${mockRunnerId} (${mockRunnerSha})`); - expect(findRunnerHeader().text()).toContain('created'); + expect(findRunnerHeader().text()).toContain('Created'); }); it('displays the runner type and status', async () => { diff --git a/spec/frontend/search/sidebar/components/app_spec.js b/spec/frontend/search/sidebar/components/app_spec.js index d8d2492209e..af6621d5193 100644 --- a/spec/frontend/search/sidebar/components/app_spec.js +++ b/spec/frontend/search/sidebar/components/app_spec.js @@ -44,13 +44,6 @@ describe('GlobalSearchSidebar', () => { wrapper = shallowMount(GlobalSearchSidebar, { store, - provide: { - glFeatures: { - searchNotesHideArchivedProjects: true, - searchCommitsHideArchivedProjects: true, - searchMilestonesHideArchivedProjects: true, - }, - }, }); }; diff --git a/spec/frontend/sentry/init_sentry_spec.js b/spec/frontend/sentry/init_sentry_spec.js index fb0dba35759..118a48cc1de 100644 --- a/spec/frontend/sentry/init_sentry_spec.js +++ b/spec/frontend/sentry/init_sentry_spec.js @@ -87,7 +87,7 @@ describe('SentryConfig', () => { expect(mockBrowserClient).toHaveBeenCalledWith( expect.objectContaining({ dsn: mockDsn, - release: mockVersion, + release: mockRevision, allowUrls: [mockGitlabUrl, 'webpack-internal://'], environment: mockEnvironment, tracesSampleRate: mockSentryClientsideTracesSampleRate, @@ -115,7 +115,7 @@ describe('SentryConfig', () => { expect(mockSetTags).toHaveBeenCalledTimes(1); expect(mockSetTags).toHaveBeenCalledWith({ page: mockPage, - revision: mockRevision, + version: mockVersion, feature_category: mockFeatureCategory, }); }); diff --git a/spec/frontend/snippets/components/snippet_header_spec.js b/spec/frontend/snippets/components/snippet_header_spec.js index 3932675aa52..1eb5de70e4b 100644 --- a/spec/frontend/snippets/components/snippet_header_spec.js +++ b/spec/frontend/snippets/components/snippet_header_spec.js @@ -80,6 +80,7 @@ describe('Snippet header component', () => { const findAuthorEmoji = () => wrapper.findComponent(GlEmoji); const findAuthoredMessage = () => wrapper.find('[data-testid="authored-message"]').text(); + const findAuthorUsername = () => wrapper.find('[data-testid="authored-username"]'); const findButtons = () => wrapper.findAllComponents(GlButton); const findButtonsAsModel = () => findButtons().wrappers.map((x) => ({ @@ -116,6 +117,7 @@ describe('Snippet header component', () => { project: null, author: { name: 'Thor Odinson', + username: null, status: null, }, blobs: [Blob], @@ -135,12 +137,24 @@ describe('Snippet header component', () => { expect(wrapper.find('.detail-page-header').exists()).toBe(true); }); - it('renders a message showing snippet creation date and author', () => { + it('renders a message showing snippet creation date and author full name, without username when not available', () => { createComponent(); const text = findAuthoredMessage(); expect(text).toContain('Authored 1 month ago by'); expect(text).toContain('Thor Odinson'); + expect(findAuthorUsername().exists()).toBe(false); + }); + + it('renders a message showing snippet creation date, author full name and username', () => { + snippet.author.username = 'todinson'; + createComponent(); + + const text = findAuthoredMessage(); + expect(text).toContain('Authored 1 month ago by'); + expect(text).toContain('Thor Odinson'); + expect(text).toContain('@todinson'); + expect(findAuthorUsername().exists()).toBe(true); }); describe('author status', () => { diff --git a/spec/models/ai/service_access_token_spec.rb b/spec/models/ai/service_access_token_spec.rb index d979db4b3d6..919492803cb 100644 --- a/spec/models/ai/service_access_token_spec.rb +++ b/spec/models/ai/service_access_token_spec.rb @@ -4,8 +4,8 @@ require 'spec_helper' RSpec.describe Ai::ServiceAccessToken, type: :model, feature_category: :application_performance do describe '.expired', :freeze_time do - let_it_be(:expired_token) { create(:service_access_token, :code_suggestions, :expired) } - let_it_be(:active_token) { create(:service_access_token, :code_suggestions, :active) } + let_it_be(:expired_token) { create(:service_access_token, :expired) } + let_it_be(:active_token) { create(:service_access_token, :active) } it 'selects all expired tokens' do expect(described_class.expired).to match_array([expired_token]) @@ -13,24 +13,14 @@ RSpec.describe Ai::ServiceAccessToken, type: :model, feature_category: :applicat end describe '.active', :freeze_time do - let_it_be(:expired_token) { create(:service_access_token, :code_suggestions, :expired) } - let_it_be(:active_token) { create(:service_access_token, :code_suggestions, :active) } + let_it_be(:expired_token) { create(:service_access_token, :expired) } + let_it_be(:active_token) { create(:service_access_token, :active) } it 'selects all active tokens' do expect(described_class.active).to match_array([active_token]) end end - # There is currently only one category, please expand this test when a new category is added. - describe '.for_category' do - let(:code_suggestions_token) { create(:service_access_token, :code_suggestions) } - let(:category) { :code_suggestions } - - it 'only selects tokens from the selected category' do - expect(described_class.for_category(category)).to match_array([code_suggestions_token]) - end - end - describe '#token' do let(:token_value) { 'Abc' } @@ -47,7 +37,6 @@ RSpec.describe Ai::ServiceAccessToken, type: :model, feature_category: :applicat describe 'validations' do it { is_expected.to validate_presence_of(:token) } - it { is_expected.to validate_presence_of(:category) } it { is_expected.to validate_presence_of(:expires_at) } end end |