diff options
Diffstat (limited to 'spec')
9 files changed, 222 insertions, 17 deletions
diff --git a/spec/features/groups/members/manage_members_spec.rb b/spec/features/groups/members/manage_members_spec.rb index 138031ffaac..dd64ddcede5 100644 --- a/spec/features/groups/members/manage_members_spec.rb +++ b/spec/features/groups/members/manage_members_spec.rb @@ -85,7 +85,7 @@ RSpec.describe 'Groups > Members > Manage members', feature_category: :groups_an end end - it_behaves_like 'inviting members', 'group-members-page' do + it_behaves_like 'inviting members', 'group_members_page' do let_it_be(:entity) { group } let_it_be(:members_page_path) { group_group_members_path(entity) } let_it_be(:subentity) { create(:group, parent: group) } diff --git a/spec/features/projects/members/manage_members_spec.rb b/spec/features/projects/members/manage_members_spec.rb index 0e3ac5ff3ac..76b2a73e170 100644 --- a/spec/features/projects/members/manage_members_spec.rb +++ b/spec/features/projects/members/manage_members_spec.rb @@ -173,7 +173,7 @@ RSpec.describe 'Projects > Members > Manage members', :js, feature_category: :on end end - it_behaves_like 'inviting members', 'project-members-page' do + it_behaves_like 'inviting members', 'project_members_page' do let_it_be(:entity) { project } let_it_be(:members_page_path) { project_project_members_path(entity) } let_it_be(:subentity) { project } diff --git a/spec/frontend/ci/ci_variable_list/components/ci_variable_drawer_spec.js b/spec/frontend/ci/ci_variable_list/components/ci_variable_drawer_spec.js index 762c9611dac..cb839503931 100644 --- a/spec/frontend/ci/ci_variable_list/components/ci_variable_drawer_spec.js +++ b/spec/frontend/ci/ci_variable_list/components/ci_variable_drawer_spec.js @@ -1,42 +1,73 @@ -import { GlDrawer, GlFormSelect } from '@gitlab/ui'; +import { GlDrawer, GlFormInput, GlFormSelect } from '@gitlab/ui'; import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; -import CiVariableDrawer from '~/ci/ci_variable_list/components/ci_variable_drawer.vue'; +import CiEnvironmentsDropdown from '~/ci/ci_variable_list/components/ci_environments_dropdown.vue'; +import CiVariableDrawer, { i18n } from '~/ci/ci_variable_list/components/ci_variable_drawer.vue'; import { ADD_VARIABLE_ACTION, + EDIT_VARIABLE_ACTION, variableOptions, + projectString, variableTypes, } from '~/ci/ci_variable_list/constants'; +import { mockVariablesWithScopes } from '../mocks'; describe('CI Variable Drawer', () => { let wrapper; + const mockProjectVariable = mockVariablesWithScopes(projectString)[0]; + const mockProjectVariableFileType = mockVariablesWithScopes(projectString)[1]; + const mockEnvScope = 'staging'; + const mockEnvironments = ['*', 'dev', 'staging', 'production']; + const defaultProps = { areEnvironmentsLoading: false, - hasEnvScopeQuery: true, + areScopedVariablesAvailable: true, + environments: mockEnvironments, + hideEnvironmentScope: false, + selectedVariable: {}, mode: ADD_VARIABLE_ACTION, }; - const createComponent = ({ mountFn = shallowMountExtended, props = {} } = {}) => { + const defaultProvide = { + isProtectedByDefault: true, + environmentScopeLink: '/help/environments', + }; + + const createComponent = ({ + mountFn = shallowMountExtended, + props = {}, + provide = {}, + stubs = {}, + } = {}) => { wrapper = mountFn(CiVariableDrawer, { propsData: { ...defaultProps, ...props, }, provide: { - environmentScopeLink: '/help/environments', + ...defaultProvide, + ...provide, }, + stubs, }); }; + const findConfirmBtn = () => wrapper.findByTestId('ci-variable-confirm-btn'); + const findDisabledEnvironmentScopeDropdown = () => wrapper.findComponent(GlFormInput); const findDrawer = () => wrapper.findComponent(GlDrawer); + const findEnvironmentScopeDropdown = () => wrapper.findComponent(CiEnvironmentsDropdown); + const findExpandedCheckbox = () => wrapper.findByTestId('ci-variable-expanded-checkbox'); + const findMaskedCheckbox = () => wrapper.findByTestId('ci-variable-masked-checkbox'); + const findProtectedCheckbox = () => wrapper.findByTestId('ci-variable-protected-checkbox'); + const findTitle = () => findDrawer().find('h2'); const findTypeDropdown = () => wrapper.findComponent(GlFormSelect); describe('validations', () => { - beforeEach(() => { - createComponent({ mountFn: mountExtended }); - }); - describe('type dropdown', () => { + beforeEach(() => { + createComponent({ mountFn: mountExtended }); + }); + it('adds each type option as a dropdown item', () => { expect(findTypeDropdown().findAll('option')).toHaveLength(variableOptions.length); @@ -50,20 +81,169 @@ describe('CI Variable Drawer', () => { variableTypes.envType, ); }); + + it('renders the selected variable type', () => { + createComponent({ + mountFn: mountExtended, + props: { + areEnvironmentsLoading: true, + selectedVariable: mockProjectVariableFileType, + }, + }); + + expect(findTypeDropdown().element.value).toBe(variableTypes.fileType); + }); + }); + + describe('environment scope dropdown', () => { + it('passes correct props to the dropdown', () => { + createComponent({ + props: { + areEnvironmentsLoading: true, + selectedVariable: { ...mockProjectVariable, environmentScope: mockEnvScope }, + }, + stubs: { CiEnvironmentsDropdown }, + }); + + expect(findEnvironmentScopeDropdown().props()).toMatchObject({ + areEnvironmentsLoading: true, + environments: mockEnvironments, + selectedEnvironmentScope: mockEnvScope, + }); + }); + + it('hides environment scope dropdown when hideEnvironmentScope is true', () => { + createComponent({ + props: { hideEnvironmentScope: true }, + stubs: { CiEnvironmentsDropdown }, + }); + + expect(findEnvironmentScopeDropdown().exists()).toBe(false); + }); + + it('disables the environment scope dropdown when areScopedVariablesAvailable is false', () => { + createComponent({ + mountFn: mountExtended, + props: { areScopedVariablesAvailable: false }, + }); + + expect(findEnvironmentScopeDropdown().exists()).toBe(false); + expect(findDisabledEnvironmentScopeDropdown().attributes('readonly')).toBe('readonly'); + }); + }); + + describe('protected flag', () => { + beforeEach(() => { + createComponent(); + }); + + it('is true by default when isProtectedByDefault is true', () => { + expect(findProtectedCheckbox().attributes('checked')).toBeDefined(); + }); + + it('is not checked when isProtectedByDefault is false', () => { + createComponent({ provide: { isProtectedByDefault: false } }); + + expect(findProtectedCheckbox().attributes('checked')).toBeUndefined(); + }); + + it('inherits value of selected variable when editing', () => { + createComponent({ + props: { + selectedVariable: mockProjectVariableFileType, + mode: EDIT_VARIABLE_ACTION, + }, + }); + + expect(findProtectedCheckbox().attributes('checked')).toBeUndefined(); + }); + }); + + describe('masked flag', () => { + beforeEach(() => { + createComponent(); + }); + + it('is false by default', () => { + expect(findMaskedCheckbox().attributes('checked')).toBeUndefined(); + }); + + it('inherits value of selected variable when editing', () => { + createComponent({ + props: { + selectedVariable: mockProjectVariableFileType, + mode: EDIT_VARIABLE_ACTION, + }, + }); + + expect(findMaskedCheckbox().attributes('checked')).toBeDefined(); + }); + }); + + describe('expanded flag', () => { + beforeEach(() => { + createComponent(); + }); + + it('is true by default when adding a variable', () => { + expect(findExpandedCheckbox().attributes('checked')).toBeDefined(); + }); + + it('inherits value of selected variable when editing', () => { + createComponent({ + props: { + selectedVariable: mockProjectVariableFileType, + mode: EDIT_VARIABLE_ACTION, + }, + }); + + expect(findExpandedCheckbox().attributes('checked')).toBeUndefined(); + }); + + it("sets the variable's raw value", async () => { + await findExpandedCheckbox().vm.$emit('change'); + await findConfirmBtn().vm.$emit('click'); + + const sentRawValue = wrapper.emitted('add-variable')[0][0].raw; + expect(sentRawValue).toBe(!defaultProps.raw); + }); }); }); describe('drawer events', () => { - beforeEach(() => { + it('emits `close-form` when closing the drawer', async () => { createComponent(); - }); - it('emits `close-form` when closing the drawer', async () => { expect(wrapper.emitted('close-form')).toBeUndefined(); await findDrawer().vm.$emit('close'); expect(wrapper.emitted('close-form')).toHaveLength(1); }); + + describe('when adding a variable', () => { + beforeEach(() => { + createComponent({ stubs: { GlDrawer } }); + }); + + it('title and confirm button renders the correct text', () => { + expect(findTitle().text()).toBe(i18n.addVariable); + expect(findConfirmBtn().text()).toBe(i18n.addVariable); + }); + }); + + describe('when editing a variable', () => { + beforeEach(() => { + createComponent({ + props: { mode: EDIT_VARIABLE_ACTION }, + stubs: { GlDrawer }, + }); + }); + + it('title and confirm button renders the correct text', () => { + expect(findTitle().text()).toBe(i18n.editVariable); + expect(findConfirmBtn().text()).toBe(i18n.editVariable); + }); + }); }); }); diff --git a/spec/frontend/ci/ci_variable_list/components/ci_variable_settings_spec.js b/spec/frontend/ci/ci_variable_list/components/ci_variable_settings_spec.js index f5737c61eea..79dd638e2bd 100644 --- a/spec/frontend/ci/ci_variable_list/components/ci_variable_settings_spec.js +++ b/spec/frontend/ci/ci_variable_list/components/ci_variable_settings_spec.js @@ -77,6 +77,21 @@ describe('Ci variable table', () => { selectedVariable: {}, }); }); + + it('passes props down correctly to the ci drawer', async () => { + createComponent({ featureFlags: { ciVariableDrawer: true } }); + + await findCiVariableTable().vm.$emit('set-selected-variable'); + + expect(findCiVariableDrawer().props()).toEqual({ + areEnvironmentsLoading: defaultProps.areEnvironmentsLoading, + areScopedVariablesAvailable: defaultProps.areScopedVariablesAvailable, + environments: defaultProps.environments, + hideEnvironmentScope: defaultProps.hideEnvironmentScope, + mode: ADD_VARIABLE_ACTION, + selectedVariable: {}, + }); + }); }); describe.each` diff --git a/spec/frontend/sidebar/components/assignees/sidebar_invite_members_spec.js b/spec/frontend/sidebar/components/assignees/sidebar_invite_members_spec.js index 501048bf056..8c42e61548f 100644 --- a/spec/frontend/sidebar/components/assignees/sidebar_invite_members_spec.js +++ b/spec/frontend/sidebar/components/assignees/sidebar_invite_members_spec.js @@ -26,7 +26,7 @@ describe('Sidebar invite members component', () => { }); it('has expected attributes on the trigger', () => { - expect(findDirectInviteLink().props('triggerSource')).toBe('issue-assignee-dropdown'); + expect(findDirectInviteLink().props('triggerSource')).toBe('issue_assignee_dropdown'); }); }); }); diff --git a/spec/helpers/nav/new_dropdown_helper_spec.rb b/spec/helpers/nav/new_dropdown_helper_spec.rb index 26dadd3b4f1..db394739b60 100644 --- a/spec/helpers/nav/new_dropdown_helper_spec.rb +++ b/spec/helpers/nav/new_dropdown_helper_spec.rb @@ -37,7 +37,7 @@ RSpec.describe Nav::NewDropdownHelper, feature_category: :navigation do partial: partial, component: 'invite_members', data: { - trigger_source: 'top-nav', + trigger_source: 'top_nav', trigger_element: 'text-emoji' } ) diff --git a/spec/lib/gitlab/data_builder/deployment_spec.rb b/spec/lib/gitlab/data_builder/deployment_spec.rb index bbcfa1973ea..bf97f40e97f 100644 --- a/spec/lib/gitlab/data_builder/deployment_spec.rb +++ b/spec/lib/gitlab/data_builder/deployment_spec.rb @@ -50,6 +50,15 @@ RSpec.describe Gitlab::DataBuilder::Deployment, feature_category: :continuous_de expect(data[:deployable_url]).to be_nil end + it 'does not include the deployable URL when deployable is bridge' do + project = create(:project, :repository) + bridge = create(:ci_bridge, project: project) + deployment = create(:deployment, status: :failed, project: project, deployable: bridge) + data = described_class.build(deployment, 'failed', Time.current) + + expect(data[:deployable_url]).to be_nil + end + context 'when commit does not exist in the repository' do let_it_be(:project) { create(:project, :repository) } let_it_be(:deployment) { create(:deployment, project: project) } diff --git a/spec/support/finder_collection_allowlist.yml b/spec/support/finder_collection_allowlist.yml index 5de8e8cdca2..e7dd9cea922 100644 --- a/spec/support/finder_collection_allowlist.yml +++ b/spec/support/finder_collection_allowlist.yml @@ -7,6 +7,7 @@ - Namespaces::FreeUserCap::UsersFinder # Reason: There is no need to have anything else besides the count - Groups::EnvironmentScopesFinder # Reason: There is no need to have anything else besides the simple strucutre with the scope name - Security::RelatedPipelinesFinder # Reason: There is no need to have anything else besides the IDs of pipelines +- Llm::ExtraResourceFinder # Reason: The finder does not deal with DB-backend resource for now. # Temporary excludes (aka TODOs) # For example: diff --git a/spec/views/projects/empty.html.haml_spec.rb b/spec/views/projects/empty.html.haml_spec.rb index 2b19b364365..c478b446864 100644 --- a/spec/views/projects/empty.html.haml_spec.rb +++ b/spec/views/projects/empty.html.haml_spec.rb @@ -73,7 +73,7 @@ RSpec.describe 'projects/empty' do expect(rendered).to have_content('Invite your team') expect(rendered).to have_content('Add members to this project and start collaborating with your team.') expect(rendered).to have_selector('.js-invite-members-trigger') - expect(rendered).to have_selector('[data-trigger-source=project-empty-page]') + expect(rendered).to have_selector('[data-trigger-source=project_empty_page]') end context 'when user does not have permissions to invite members' do |