diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-05 09:09:37 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-05 09:09:37 +0000 |
commit | b42bf2a6d3a1a4bc8d4bc9533055eff6bd644560 (patch) | |
tree | 7114b706d054aa31e91f3aa975a7ea15cb746bae /spec | |
parent | 1d799ea925e4aad04bdc390c299fafb20bb4e4ae (diff) | |
download | gitlab-ce-b42bf2a6d3a1a4bc8d4bc9533055eff6bd644560.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
7 files changed, 154 insertions, 1 deletions
diff --git a/spec/features/dashboard/snippets_spec.rb b/spec/features/dashboard/snippets_spec.rb index b44deaa3174..94aef03e093 100644 --- a/spec/features/dashboard/snippets_spec.rb +++ b/spec/features/dashboard/snippets_spec.rb @@ -35,7 +35,7 @@ describe 'Dashboard snippets' do element = page.find('.row.empty-state') expect(element).to have_content("Code snippets") - expect(element.find('.svg-content img')['src']).to have_content('illustrations/snippets_empty') + expect(element.find('.svg-content img.js-lazy-loaded')['src']).to have_content('illustrations/snippets_empty') end it 'shows new snippet button in main content area' do diff --git a/spec/features/merge_request/user_sees_notes_from_forked_project_spec.rb b/spec/features/merge_request/user_sees_notes_from_forked_project_spec.rb index 9c9e0dacb87..029f55c2cd6 100644 --- a/spec/features/merge_request/user_sees_notes_from_forked_project_spec.rb +++ b/spec/features/merge_request/user_sees_notes_from_forked_project_spec.rb @@ -28,6 +28,7 @@ describe 'Merge request > User sees notes from forked project', :js do page.within('.discussion-notes') do find('.btn-text-field').click + scroll_to(page.find('#note_note', visible: false)) find('#note_note').send_keys('A reply comment') find('.js-comment-button').click end diff --git a/spec/frontend/vue_mr_widget/components/mr_widget_terraform_plan_spec.js b/spec/frontend/vue_mr_widget/components/mr_widget_terraform_plan_spec.js index 1951b56587a..91e95b2bdb1 100644 --- a/spec/frontend/vue_mr_widget/components/mr_widget_terraform_plan_spec.js +++ b/spec/frontend/vue_mr_widget/components/mr_widget_terraform_plan_spec.js @@ -3,6 +3,7 @@ import { shallowMount } from '@vue/test-utils'; import axios from '~/lib/utils/axios_utils'; import MockAdapter from 'axios-mock-adapter'; import MrWidgetTerraformPlan from '~/vue_merge_request_widget/components/mr_widget_terraform_plan.vue'; +import Poll from '~/lib/utils/poll'; const plan = { create: 10, @@ -57,11 +58,23 @@ describe('MrWidgetTerraformPlan', () => { }); describe('successful poll', () => { + let pollRequest; + let pollStop; + beforeEach(() => { + pollRequest = jest.spyOn(Poll.prototype, 'makeRequest'); + pollStop = jest.spyOn(Poll.prototype, 'stop'); + mockPollingApi(200, { 'tfplan.json': plan }, {}); + return mountWrapper(); }); + afterEach(() => { + pollRequest.mockRestore(); + pollStop.mockRestore(); + }); + it('content change text', () => { expect(wrapper.find(GlSprintf).exists()).toBe(true); }); @@ -69,6 +82,11 @@ describe('MrWidgetTerraformPlan', () => { it('renders button when url is found', () => { expect(wrapper.find('a').text()).toContain('View full log'); }); + + it('does not make additional requests after poll is successful', () => { + expect(pollRequest).toHaveBeenCalledTimes(1); + expect(pollStop).toHaveBeenCalledTimes(1); + }); }); describe('polling fails', () => { diff --git a/spec/graphql/mutations/branches/create_spec.rb b/spec/graphql/mutations/branches/create_spec.rb new file mode 100644 index 00000000000..744f8f1f2bc --- /dev/null +++ b/spec/graphql/mutations/branches/create_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Mutations::Branches::Create do + subject(:mutation) { described_class.new(object: nil, context: context, field: nil) } + + let_it_be(:project) { create(:project, :public, :repository) } + let_it_be(:user) { create(:user) } + let_it_be(:context) do + GraphQL::Query::Context.new( + query: OpenStruct.new(schema: nil), + values: { current_user: user }, + object: nil + ) + end + + describe '#resolve' do + subject { mutation.resolve(project_path: project.full_path, name: branch, ref: ref) } + + let(:branch) { 'new_branch' } + let(:ref) { 'master' } + let(:mutated_branch) { subject[:branch] } + + it 'raises an error if the resource is not accessible to the user' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + + context 'when the user can create a branch' do + before do + project.add_developer(user) + + allow_next_instance_of(::Branches::CreateService, project, user) do |create_service| + allow(create_service).to receive(:execute).with(branch, ref) { service_result } + end + end + + context 'when service successfully creates a new branch' do + let(:service_result) { { status: :success, branch: double(name: branch) } } + + it 'returns a new branch' do + expect(mutated_branch.name).to eq(branch) + expect(subject[:errors]).to be_empty + end + end + + context 'when service fails to create a new branch' do + let(:service_result) { { status: :error, message: 'Branch already exists' } } + + it { expect(mutated_branch).to be_nil } + it { expect(subject[:errors]).to eq(['Branch already exists']) } + end + end + end +end diff --git a/spec/graphql/resolvers/branch_commit_resolver_spec.rb b/spec/graphql/resolvers/branch_commit_resolver_spec.rb new file mode 100644 index 00000000000..22e1de8f375 --- /dev/null +++ b/spec/graphql/resolvers/branch_commit_resolver_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Resolvers::BranchCommitResolver do + include GraphqlHelpers + + subject(:commit) { resolve(described_class, obj: branch) } + + let_it_be(:repository) { create(:project, :repository).repository } + let(:branch) { repository.find_branch('master') } + + describe '#resolve' do + it 'resolves commit' do + is_expected.to eq(repository.commits('master', limit: 1).last) + end + + context 'when branch does not exist' do + let(:branch) { nil } + + it 'returns nil' do + is_expected.to be_nil + end + end + end +end diff --git a/spec/graphql/types/branch_type_spec.rb b/spec/graphql/types/branch_type_spec.rb new file mode 100644 index 00000000000..f58b514116d --- /dev/null +++ b/spec/graphql/types/branch_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['Branch'] do + it { expect(described_class.graphql_name).to eq('Branch') } + + it { expect(described_class).to have_graphql_fields(:name, :commit) } +end diff --git a/spec/requests/api/graphql/mutations/branches/create_spec.rb b/spec/requests/api/graphql/mutations/branches/create_spec.rb new file mode 100644 index 00000000000..406ab8959a2 --- /dev/null +++ b/spec/requests/api/graphql/mutations/branches/create_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Creation of a new branch' do + include GraphqlHelpers + + let_it_be(:current_user) { create(:user) } + let(:project) { create(:project, :public, :repository) } + let(:input) { { project_path: project.full_path, name: new_branch, ref: ref } } + let(:new_branch) { 'new_branch' } + let(:ref) { 'master' } + + let(:mutation) { graphql_mutation(:create_branch, input) } + let(:mutation_response) { graphql_mutation_response(:create_branch) } + + context 'the user is not allowed to create a branch' do + it_behaves_like 'a mutation that returns top-level errors', + errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action'] + end + + context 'when user has permissions to create a branch' do + before do + project.add_developer(current_user) + end + + it 'creates a new branch' do + post_graphql_mutation(mutation, current_user: current_user) + + expect(response).to have_gitlab_http_status(:success) + expect(mutation_response['branch']).to include( + 'name' => new_branch, + 'commit' => a_hash_including('id') + ) + end + + context 'when ref is not correct' do + let(:ref) { 'unknown' } + + it_behaves_like 'a mutation that returns errors in the response', + errors: ['Invalid reference name: new_branch'] + end + end +end |