diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-04 15:06:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-04 15:06:14 +0300 |
commit | 0d46bf06388d485824bc2f1e736b92b2a8a397e4 (patch) | |
tree | 626a835841722463da4def7905b95e874eb77578 /spec | |
parent | 1f1bdf54e1974f89f3a6ba734ec2c42552e90639 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
5 files changed, 157 insertions, 34 deletions
diff --git a/spec/features/projects/issuable_templates_spec.rb b/spec/features/projects/issuable_templates_spec.rb index 18eadb7c4a3..c06fee92d09 100644 --- a/spec/features/projects/issuable_templates_spec.rb +++ b/spec/features/projects/issuable_templates_spec.rb @@ -92,6 +92,9 @@ describe 'issuable templates', :js do context 'user creates a merge request using templates' do let(:template_content) { 'this is a test "feature-proposal" template' } + let(:bug_template_content) { 'this is merge request bug template' } + let(:template_override_warning) { 'Applying a template will replace the existing issue description.' } + let(:updated_description) { 'updated merge request description' } let(:merge_request) { create(:merge_request, :with_diffs, source_project: project) } before do @@ -101,6 +104,12 @@ describe 'issuable templates', :js do template_content, message: 'added merge request template', branch_name: 'master') + project.repository.create_file( + user, + '.gitlab/merge_request_templates/bug.md', + bug_template_content, + message: 'added merge request bug template', + branch_name: 'master') visit edit_project_merge_request_path project, merge_request fill_in :'merge_request[title]', with: 'test merge request title' end @@ -111,6 +120,27 @@ describe 'issuable templates', :js do assert_template save_changes end + + context 'changes template' do + before do + select_template 'bug' + wait_for_requests + fill_in :'merge_request[description]', with: updated_description + select_template 'feature-proposal' + expect(page).to have_content template_override_warning + end + + it 'user selects "bug" template, then updates description, then selects "feature-proposal" template, then cancels template change' do + page.find('.js-template-warning .js-cancel-btn').click + expect(find('textarea')['value']).to eq(updated_description) + end + + it 'user selects "bug" template, then updates description, then selects "feature-proposal" template, then applies template change' do + page.find('.js-template-warning .js-override-template').click + wait_for_requests + assert_template + end + end end context 'user creates a merge request from a forked project using templates' do diff --git a/spec/frontend/releases/components/release_block_spec.js b/spec/frontend/releases/components/release_block_spec.js index 5ce85a37121..1f5da093902 100644 --- a/spec/frontend/releases/components/release_block_spec.js +++ b/spec/frontend/releases/components/release_block_spec.js @@ -4,6 +4,18 @@ import timeagoMixin from '~/vue_shared/mixins/timeago'; import { first } from 'underscore'; import { release } from '../mock_data'; import Icon from '~/vue_shared/components/icon.vue'; +import { scrollToElement } from '~/lib/utils/common_utils'; + +let mockLocationHash; +jest.mock('~/lib/utils/url_utility', () => ({ + __esModule: true, + getLocationHash: jest.fn().mockImplementation(() => mockLocationHash), +})); + +jest.mock('~/lib/utils/common_utils', () => ({ + __esModule: true, + scrollToElement: jest.fn(), +})); describe('Release block', () => { let wrapper; @@ -159,4 +171,61 @@ describe('Release block', () => { expect(wrapper.text()).toContain('Upcoming Release'); }); + + it('slugifies the tag_name before setting it as the elements ID', () => { + const releaseClone = JSON.parse(JSON.stringify(release)); + releaseClone.tag_name = 'a dangerous tag name <script>alert("hello")</script>'; + + factory(releaseClone); + + expect(wrapper.attributes().id).toBe('a-dangerous-tag-name-script-alert-hello-script-'); + }); + + describe('anchor scrolling', () => { + beforeEach(() => { + scrollToElement.mockClear(); + }); + + const hasTargetBlueBackground = () => wrapper.classes('bg-line-target-blue'); + + it('does not attempt to scroll the page if no anchor tag is included in the URL', () => { + mockLocationHash = ''; + factory(release); + + expect(scrollToElement).not.toHaveBeenCalled(); + }); + + it("does not attempt to scroll the page if the anchor tag doesn't match the release's tag name", () => { + mockLocationHash = 'v0.4'; + factory(release); + + expect(scrollToElement).not.toHaveBeenCalled(); + }); + + it("attempts to scroll itself into view if the anchor tag matches the release's tag name", () => { + mockLocationHash = release.tag_name; + factory(release); + + expect(scrollToElement).toHaveBeenCalledTimes(1); + expect(scrollToElement).toHaveBeenCalledWith(wrapper.element); + }); + + it('renders with a light blue background if it is the target of the anchor', () => { + mockLocationHash = release.tag_name; + factory(release); + + return wrapper.vm.$nextTick().then(() => { + expect(hasTargetBlueBackground()).toBe(true); + }); + }); + + it('does not render with a light blue background if it is not the target of the anchor', () => { + mockLocationHash = ''; + factory(release); + + return wrapper.vm.$nextTick().then(() => { + expect(hasTargetBlueBackground()).toBe(false); + }); + }); + }); }); diff --git a/spec/javascripts/vue_mr_widget/components/deployment_spec.js b/spec/javascripts/vue_mr_widget/components/deployment_spec.js index 42bf3b7df09..1949bee1406 100644 --- a/spec/javascripts/vue_mr_widget/components/deployment_spec.js +++ b/spec/javascripts/vue_mr_widget/components/deployment_spec.js @@ -207,7 +207,7 @@ describe('Deployment component', () => { it('renders the link to the review app without dropdown', () => { expect(vm.$el.querySelector('.js-mr-wigdet-deployment-dropdown')).toBeNull(); - expect(vm.$el.querySelector('.js-deploy-url-feature-flag')).not.toBeNull(); + expect(vm.$el.querySelector('.js-deploy-url')).not.toBeNull(); }); }); @@ -223,12 +223,12 @@ describe('Deployment component', () => { it('renders the link to the review app without dropdown', () => { expect(vm.$el.querySelector('.js-mr-wigdet-deployment-dropdown')).toBeNull(); - expect(vm.$el.querySelector('.js-deploy-url-feature-flag')).not.toBeNull(); + expect(vm.$el.querySelector('.js-deploy-url')).not.toBeNull(); }); it('renders the link to the review app linked to to the first change', () => { const expectedUrl = deploymentMockData.changes[0].external_url; - const deployUrl = vm.$el.querySelector('.js-deploy-url-feature-flag'); + const deployUrl = vm.$el.querySelector('.js-deploy-url'); expect(vm.$el.querySelector('.js-mr-wigdet-deployment-dropdown')).toBeNull(); expect(deployUrl).not.toBeNull(); diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index c619a2ab237..218031784cb 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -520,20 +520,21 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do end end - describe '#restored_project' do + context 'Minimal JSON' do let(:project) { create(:project) } let(:tree_hash) { { 'visibility_level' => visibility } } let(:restorer) { described_class.new(user: nil, shared: shared, project: project) } before do - restorer.instance_variable_set(:@tree_hash, tree_hash) + expect(restorer).to receive(:read_tree_hash) { tree_hash } end context 'no group visibility' do let(:visibility) { Gitlab::VisibilityLevel::PRIVATE } it 'uses the project visibility' do - expect(restorer.restored_project.visibility_level).to eq(visibility) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(visibility) end end @@ -544,7 +545,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do it 'uses private visibility' do stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL]) - expect(restorer.restored_project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) end end end @@ -561,7 +563,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do let(:visibility) { Gitlab::VisibilityLevel::PUBLIC } it 'uses the group visibility' do - expect(restorer.restored_project.visibility_level).to eq(group_visibility) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(group_visibility) end end @@ -570,7 +573,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do let(:visibility) { Gitlab::VisibilityLevel::PRIVATE } it 'uses the project visibility' do - expect(restorer.restored_project.visibility_level).to eq(visibility) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(visibility) end end @@ -579,14 +583,16 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do let(:visibility) { Gitlab::VisibilityLevel::PUBLIC } it 'uses the group visibility' do - expect(restorer.restored_project.visibility_level).to eq(group_visibility) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(group_visibility) end context 'with restricted internal visibility' do it 'sets private visibility' do stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL]) - expect(restorer.restored_project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) + expect(restorer.restore).to eq(true) + expect(restorer.project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) end end end diff --git a/spec/models/concerns/atomic_internal_id_spec.rb b/spec/models/concerns/atomic_internal_id_spec.rb index 60e7e90e3f1..f9ca9660bdb 100644 --- a/spec/models/concerns/atomic_internal_id_spec.rb +++ b/spec/models/concerns/atomic_internal_id_spec.rb @@ -9,16 +9,10 @@ describe AtomicInternalId do let(:scope_attrs) { { project: milestone.project } } let(:usage) { :milestones } - describe '#ensure_project_iid!' do - subject { milestone.ensure_project_iid! } - - it 'generates a new value if non is present' do - expect(InternalId).to receive(:generate_next).with(milestone, scope_attrs, usage, anything).and_return(iid) + describe '#track_project_iid!' do + subject { milestone.track_project_iid! } - expect { subject }.to change { milestone.iid }.from(nil).to(iid.to_i) - end - - it 'tracks the present value if not generated by InternalId.generate_next' do + it 'tracks the present value' do milestone.iid = external_iid expect(InternalId).to receive(:track_greatest).once.with(milestone, scope_attrs, usage, external_iid, anything) @@ -27,27 +21,51 @@ describe AtomicInternalId do subject end - it 'generates a new value if first set with iid= but later set to nil' do - expect(InternalId).to receive(:generate_next).with(milestone, scope_attrs, usage, anything).and_return(iid) - - milestone.iid = external_iid - milestone.iid = nil + context 'when value is set by ensure_project_iid!' do + context 'with iid_always_track true' do + before do + stub_feature_flags(iid_always_track: false) + end - expect { subject }.to change { milestone.iid }.from(nil).to(iid.to_i) - end + it 'does not track the value' do + expect(InternalId).not_to receive(:track_greatest) - context 'with iid_always_track disabled' do - before do - stub_feature_flags(iid_always_track: false) + milestone.ensure_project_iid! + subject + end end - it 'does not track the present value if generated by InternalId.generate_next' do - milestone.ensure_project_iid! + context 'with iid_always_track enabled' do + before do + stub_feature_flags(iid_always_track: true) + end - expect(InternalId).not_to receive(:track_greatest) + it 'does not track the value' do + expect(InternalId).to receive(:track_greatest) - subject + milestone.ensure_project_iid! + subject + end end end end + + describe '#ensure_project_iid!' do + subject { milestone.ensure_project_iid! } + + it 'generates a new value if non is present' do + expect(InternalId).to receive(:generate_next).with(milestone, scope_attrs, usage, anything).and_return(iid) + + expect { subject }.to change { milestone.iid }.from(nil).to(iid.to_i) + end + + it 'generates a new value if first set with iid= but later set to nil' do + expect(InternalId).to receive(:generate_next).with(milestone, scope_attrs, usage, anything).and_return(iid) + + milestone.iid = external_iid + milestone.iid = nil + + expect { subject }.to change { milestone.iid }.from(nil).to(iid.to_i) + end + end end |