diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-08 03:10:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-08 03:10:34 +0300 |
commit | 6aead03bb3056c7ee0104311236c2ae06f0e2d18 (patch) | |
tree | a468b3b3ae108c8d266f80490bd9ef2fa25af1da /spec | |
parent | c98df6ecba0c2a2026803d824ff67d26d6251374 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/members/components/modals/remove_group_link_modal_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/runner/components/cells/runner_actions_cell_spec.js | 92 | ||||
-rw-r--r-- | spec/helpers/nav/top_nav_helper_spec.rb | 30 | ||||
-rw-r--r-- | spec/lib/gitlab/cache_spec.rb | 12 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 57 | ||||
-rw-r--r-- | spec/services/issues/close_service_spec.rb | 2 |
6 files changed, 192 insertions, 3 deletions
diff --git a/spec/frontend/members/components/modals/remove_group_link_modal_spec.js b/spec/frontend/members/components/modals/remove_group_link_modal_spec.js index 01279581c55..313c237f51c 100644 --- a/spec/frontend/members/components/modals/remove_group_link_modal_spec.js +++ b/spec/frontend/members/components/modals/remove_group_link_modal_spec.js @@ -109,6 +109,6 @@ describe('RemoveGroupLinkModal', () => { it('modal does not show when `removeGroupLinkModalVisible` is `false`', () => { createComponent({ removeGroupLinkModalVisible: false }); - expect(findModal().vm.$attrs.visible).toBe(false); + expect(findModal().props().visible).toBe(false); }); }); diff --git a/spec/frontend/runner/components/cells/runner_actions_cell_spec.js b/spec/frontend/runner/components/cells/runner_actions_cell_spec.js index c2390d7b9c0..9bf47b7ee7a 100644 --- a/spec/frontend/runner/components/cells/runner_actions_cell_spec.js +++ b/spec/frontend/runner/components/cells/runner_actions_cell_spec.js @@ -2,16 +2,21 @@ import { shallowMount } from '@vue/test-utils'; import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import waitForPromises from 'helpers/wait_for_promises'; import RunnerActionCell from '~/runner/components/cells/runner_actions_cell.vue'; +import deleteRunnerMutation from '~/runner/graphql/delete_runner.mutation.graphql'; +import getRunnersQuery from '~/runner/graphql/get_runners.query.graphql'; import updateRunnerMutation from '~/runner/graphql/update_runner.mutation.graphql'; const mockId = '1'; +const getRunnersQueryName = getRunnersQuery.definitions[0].name.value; + describe('RunnerTypeCell', () => { let wrapper; let mutate; const findEditBtn = () => wrapper.findByTestId('edit-runner'); const findToggleActiveBtn = () => wrapper.findByTestId('toggle-active-runner'); + const findDeleteBtn = () => wrapper.findByTestId('delete-runner'); const createComponent = ({ active = true } = {}, options) => { wrapper = extendedWrapper( @@ -78,6 +83,11 @@ describe('RunnerTypeCell', () => { await findToggleActiveBtn().vm.$emit('click'); expect(findToggleActiveBtn().props('loading')).toBe(true); + }); + + it(`After the ${icon} button is clicked, stale tooltip is removed`, async () => { + await findToggleActiveBtn().vm.$emit('click'); + expect(findToggleActiveBtn().attributes('title')).toBe(''); expect(findToggleActiveBtn().attributes('aria-label')).toBe(''); }); @@ -106,4 +116,86 @@ describe('RunnerTypeCell', () => { }); }); }); + + describe('When the user clicks a runner', () => { + beforeEach(() => { + createComponent(); + + mutate.mockResolvedValue({ + data: { + runnerDelete: { + runner: { + id: `gid://gitlab/Ci::Runner/1`, + __typename: 'CiRunner', + }, + }, + }, + }); + + jest.spyOn(window, 'confirm'); + }); + + describe('When the user confirms deletion', () => { + beforeEach(async () => { + window.confirm.mockReturnValue(true); + await findDeleteBtn().vm.$emit('click'); + }); + + it('The user sees a confirmation alert', async () => { + expect(window.confirm).toHaveBeenCalledTimes(1); + expect(window.confirm).toHaveBeenCalledWith(expect.any(String)); + }); + + it('The delete mutation is called correctly', () => { + expect(mutate).toHaveBeenCalledTimes(1); + expect(mutate).toHaveBeenCalledWith({ + mutation: deleteRunnerMutation, + variables: { + input: { + id: `gid://gitlab/Ci::Runner/${mockId}`, + }, + }, + awaitRefetchQueries: true, + refetchQueries: [getRunnersQueryName], + }); + }); + + it('The delete button does not have a loading state', () => { + expect(findDeleteBtn().props('loading')).toBe(false); + expect(findDeleteBtn().attributes('title')).toBe('Remove'); + }); + + it('After the delete button is clicked, loading state is shown', async () => { + await findDeleteBtn().vm.$emit('click'); + + expect(findDeleteBtn().props('loading')).toBe(true); + }); + + it('After the delete button is clicked, stale tooltip is removed', async () => { + await findDeleteBtn().vm.$emit('click'); + + expect(findDeleteBtn().attributes('title')).toBe(''); + }); + }); + + describe('When the user does not confirm deletion', () => { + beforeEach(async () => { + window.confirm.mockReturnValue(false); + await findDeleteBtn().vm.$emit('click'); + }); + + it('The user sees a confirmation alert', () => { + expect(window.confirm).toHaveBeenCalledTimes(1); + }); + + it('The delete mutation is not called', () => { + expect(mutate).toHaveBeenCalledTimes(0); + }); + + it('The delete button does not have a loading state', () => { + expect(findDeleteBtn().props('loading')).toBe(false); + expect(findDeleteBtn().attributes('title')).toBe('Remove'); + }); + }); + }); }); diff --git a/spec/helpers/nav/top_nav_helper_spec.rb b/spec/helpers/nav/top_nav_helper_spec.rb index 91aedc5268c..9426f39cd80 100644 --- a/spec/helpers/nav/top_nav_helper_spec.rb +++ b/spec/helpers/nav/top_nav_helper_spec.rb @@ -106,6 +106,16 @@ RSpec.describe Nav::TopNavHelper do ] expect(subject[:secondary]).to eq(expected_secondary) end + + context 'with current nav as project' do + before do + helper.nav('project') + end + + it 'has expected :active' do + expect(subject[:primary].detect { |entry| entry[:id] == 'project' }[:active]).to eq(true) + end + end end context 'when current_user is non-admin' do @@ -190,6 +200,16 @@ RSpec.describe Nav::TopNavHelper do expect(projects_view[:linksSecondary]).to eq(expected_links_secondary) end + context 'with current nav as project' do + before do + helper.nav('project') + end + + it 'has expected :active' do + expect(subject[:primary].detect { |entry| entry[:id] == 'project' }[:active]).to eq(true) + end + end + context 'with persisted project' do let_it_be(:project) { build_stubbed(:project) } @@ -281,6 +301,16 @@ RSpec.describe Nav::TopNavHelper do expect(groups_view[:linksSecondary]).to eq(expected_links_secondary) end + context 'with current nav as group' do + before do + helper.nav('group') + end + + it 'has expected :active' do + expect(subject[:primary].detect { |entry| entry[:id] == 'groups' }[:active]).to eq(true) + end + end + context 'with persisted group' do let_it_be(:group) { build_stubbed(:group) } diff --git a/spec/lib/gitlab/cache_spec.rb b/spec/lib/gitlab/cache_spec.rb index 5b1034a77a3..67c70a77880 100644 --- a/spec/lib/gitlab/cache_spec.rb +++ b/spec/lib/gitlab/cache_spec.rb @@ -26,4 +26,16 @@ RSpec.describe Gitlab::Cache, :request_store do expect(subject.call).to eq("return value") end end + + describe '.delete' do + let(:key) { %w{a cache key} } + + subject(:delete) { described_class.delete(key) } + + it 'calls Rails.cache.delete' do + expect(Rails.cache).to receive(:delete).with(key) + + delete + end + end end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index d5694020b5f..d5a12ba6e6e 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2640,6 +2640,17 @@ RSpec.describe Ci::Build do it { is_expected.to be_instance_of(Gitlab::Ci::Variables::Collection) } it { expect(subject.to_runner_variables).to eq(predefined_variables) } + it 'excludes variables that require an environment or user' do + environment_based_variables_collection = subject.filter do |variable| + %w[ + YAML_VARIABLE CI_ENVIRONMENT_NAME CI_ENVIRONMENT_SLUG + CI_ENVIRONMENT_ACTION CI_ENVIRONMENT_URL + ].include?(variable[:key]) + end + + expect(environment_based_variables_collection).to be_empty + end + context 'when ci_job_jwt feature flag is disabled' do before do stub_feature_flags(ci_job_jwt: false) @@ -2709,7 +2720,7 @@ RSpec.describe Ci::Build do let(:expected_variables) do predefined_variables.map { |variable| variable.fetch(:key) } + %w[YAML_VARIABLE CI_ENVIRONMENT_NAME CI_ENVIRONMENT_SLUG - CI_ENVIRONMENT_URL] + CI_ENVIRONMENT_ACTION CI_ENVIRONMENT_URL] end before do @@ -2727,6 +2738,50 @@ RSpec.describe Ci::Build do expect(received_variables).to eq expected_variables end + + describe 'CI_ENVIRONMENT_ACTION' do + let(:enviroment_action_variable) { subject.find { |variable| variable[:key] == 'CI_ENVIRONMENT_ACTION' } } + + shared_examples 'defaults value' do + it 'value matches start' do + expect(enviroment_action_variable[:value]).to eq('start') + end + end + + it_behaves_like 'defaults value' + + context 'when options is set' do + before do + build.update!(options: options) + end + + context 'when options is empty' do + let(:options) { {} } + + it_behaves_like 'defaults value' + end + + context 'when options is nil' do + let(:options) { nil } + + it_behaves_like 'defaults value' + end + + context 'when options environment is specified' do + let(:options) { { environment: {} } } + + it_behaves_like 'defaults value' + end + + context 'when options environment action specified' do + let(:options) { { environment: { action: 'stop' } } } + + it 'matches the specified action' do + expect(enviroment_action_variable[:value]).to eq('stop') + end + end + end + end end end end diff --git a/spec/services/issues/close_service_spec.rb b/spec/services/issues/close_service_spec.rb index f18c72d3991..6fa239a58b8 100644 --- a/spec/services/issues/close_service_spec.rb +++ b/spec/services/issues/close_service_spec.rb @@ -222,7 +222,7 @@ RSpec.describe Issues::CloseService do it 'verifies the number of queries' do recorded = ActiveRecord::QueryRecorder.new { close_issue } - expected_queries = 23 + expected_queries = 24 expect(recorded.count).to be <= expected_queries expect(recorded.cached_count).to eq(0) |