diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-06 03:07:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-06 03:07:48 +0300 |
commit | 2349eabc1a473bfb70555f0ce6d3d808cecb181d (patch) | |
tree | 0dae6a2a6810f2198eed42b7f9566ebf9c292468 /spec | |
parent | 134fe182008dc13a16f12d723aa73771efb1a6a2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
17 files changed, 105 insertions, 53 deletions
diff --git a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb index 06d9af33189..8f4f85b55bb 100644 --- a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb @@ -25,6 +25,16 @@ describe Projects::MergeRequests::DiffsController do end end + shared_examples 'cached diff collection' do + it 'ensures diff highlighting cache writing' do + expect_next_instance_of(Gitlab::Diff::HighlightCache) do |cache| + expect(cache).to receive(:write_if_empty).once + end + + go + end + end + shared_examples 'persisted preferred diff view cookie' do context 'with view param' do before do @@ -112,6 +122,7 @@ describe Projects::MergeRequests::DiffsController do end it_behaves_like 'persisted preferred diff view cookie' + it_behaves_like 'cached diff collection' end describe 'GET diffs_metadata' do @@ -404,6 +415,7 @@ describe Projects::MergeRequests::DiffsController do it_behaves_like 'forked project with submodules' it_behaves_like 'persisted preferred diff view cookie' + it_behaves_like 'cached diff collection' context 'diff unfolding' do let!(:unfoldable_diff_note) do diff --git a/spec/features/snippets/internal_snippet_spec.rb b/spec/features/snippets/internal_snippet_spec.rb index fd7ef71db15..4ef3b0e5e7a 100644 --- a/spec/features/snippets/internal_snippet_spec.rb +++ b/spec/features/snippets/internal_snippet_spec.rb @@ -5,10 +5,6 @@ require 'spec_helper' describe 'Internal Snippets', :js do let(:internal_snippet) { create(:personal_snippet, :internal) } - before do - stub_feature_flags(snippets_vue: false) - end - describe 'normal user' do before do sign_in(create(:user)) diff --git a/spec/features/snippets/notes_on_personal_snippets_spec.rb b/spec/features/snippets/notes_on_personal_snippets_spec.rb index 57264f97ddc..2bd01be25e9 100644 --- a/spec/features/snippets/notes_on_personal_snippets_spec.rb +++ b/spec/features/snippets/notes_on_personal_snippets_spec.rb @@ -16,7 +16,6 @@ describe 'Comments on personal snippets', :js do let!(:other_note) { create(:note_on_personal_snippet) } before do - stub_feature_flags(snippets_vue: false) sign_in user visit snippet_path(snippet) diff --git a/spec/features/snippets/private_snippets_spec.rb b/spec/features/snippets/private_snippets_spec.rb index 37f45f22a27..9df4cd01103 100644 --- a/spec/features/snippets/private_snippets_spec.rb +++ b/spec/features/snippets/private_snippets_spec.rb @@ -6,7 +6,6 @@ describe 'Private Snippets', :js do let(:user) { create(:user) } before do - stub_feature_flags(snippets_vue: false) sign_in(user) end diff --git a/spec/features/snippets/public_snippets_spec.rb b/spec/features/snippets/public_snippets_spec.rb index 045afcf1c12..82edda509c2 100644 --- a/spec/features/snippets/public_snippets_spec.rb +++ b/spec/features/snippets/public_snippets_spec.rb @@ -3,10 +3,6 @@ require 'spec_helper' describe 'Public Snippets', :js do - before do - stub_feature_flags(snippets_vue: false) - end - it 'Unauthenticated user should see public snippets' do public_snippet = create(:personal_snippet, :public) diff --git a/spec/features/snippets/show_spec.rb b/spec/features/snippets/show_spec.rb index 9c686be012b..450e520e293 100644 --- a/spec/features/snippets/show_spec.rb +++ b/spec/features/snippets/show_spec.rb @@ -6,10 +6,6 @@ describe 'Snippet', :js do let(:project) { create(:project, :repository) } let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content) } - before do - stub_feature_flags(snippets_vue: false) - end - context 'Ruby file' do let(:file_name) { 'popen.rb' } let(:content) { project.repository.blob_at('master', 'files/ruby/popen.rb').data } diff --git a/spec/features/snippets/spam_snippets_spec.rb b/spec/features/snippets/spam_snippets_spec.rb index 0c3ca6f17c8..3e71a4e7879 100644 --- a/spec/features/snippets/spam_snippets_spec.rb +++ b/spec/features/snippets/spam_snippets_spec.rb @@ -7,7 +7,6 @@ describe 'User creates snippet', :js do before do stub_feature_flags(allow_possible_spam: false) - stub_feature_flags(snippets_vue: false) stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') Gitlab::CurrentSettings.update!( diff --git a/spec/features/snippets/user_creates_snippet_spec.rb b/spec/features/snippets/user_creates_snippet_spec.rb index b373264bbe4..9a141dd463a 100644 --- a/spec/features/snippets/user_creates_snippet_spec.rb +++ b/spec/features/snippets/user_creates_snippet_spec.rb @@ -8,7 +8,6 @@ describe 'User creates snippet', :js do let(:user) { create(:user) } before do - stub_feature_flags(snippets_vue: false) sign_in(user) visit new_snippet_path end diff --git a/spec/features/snippets/user_deletes_snippet_spec.rb b/spec/features/snippets/user_deletes_snippet_spec.rb index 35619b92561..217419a220a 100644 --- a/spec/features/snippets/user_deletes_snippet_spec.rb +++ b/spec/features/snippets/user_deletes_snippet_spec.rb @@ -10,8 +10,6 @@ describe 'User deletes snippet' do before do sign_in(user) - stub_feature_flags(snippets_vue: false) - visit snippet_path(snippet) end diff --git a/spec/features/snippets/user_edits_snippet_spec.rb b/spec/features/snippets/user_edits_snippet_spec.rb index 1d26660a4f6..51d9baf44bc 100644 --- a/spec/features/snippets/user_edits_snippet_spec.rb +++ b/spec/features/snippets/user_edits_snippet_spec.rb @@ -12,7 +12,6 @@ describe 'User edits snippet', :js do let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content, author: user) } before do - stub_feature_flags(snippets_vue: false) sign_in(user) visit edit_snippet_path(snippet) diff --git a/spec/features/snippets_spec.rb b/spec/features/snippets_spec.rb index bc7fa161e87..9df6fe7d16b 100644 --- a/spec/features/snippets_spec.rb +++ b/spec/features/snippets_spec.rb @@ -6,38 +6,11 @@ describe 'Snippets' do context 'when the project has snippets' do let(:project) { create(:project, :public) } let!(:snippets) { create_list(:project_snippet, 2, :public, author: project.owner, project: project) } - before do allow(Snippet).to receive(:default_per_page).and_return(1) - - visit project_snippets_path(project) + visit snippets_path(username: project.owner.username) end it_behaves_like 'paginated snippets' end - - describe 'rendering engine' do - let_it_be(:snippet) { create(:personal_snippet, :public) } - let(:snippets_vue_feature_flag_enabled) { true } - - before do - stub_feature_flags(snippets_vue: snippets_vue_feature_flag_enabled) - - visit snippet_path(snippet) - end - - it 'renders Vue application' do - expect(page).to have_selector('#js-snippet-view') - expect(page).not_to have_selector('.personal-snippets') - end - - context 'when feature flag is disabled' do - let(:snippets_vue_feature_flag_enabled) { false } - - it 'renders HAML application and not Vue' do - expect(page).not_to have_selector('#js-snippet-view') - expect(page).to have_selector('.personal-snippets') - end - end - end end diff --git a/spec/frontend/monitoring/embed/embed_spec.js b/spec/frontend/monitoring/embed/embed_spec.js index c5219f6130e..6d40719fa32 100644 --- a/spec/frontend/monitoring/embed/embed_spec.js +++ b/spec/frontend/monitoring/embed/embed_spec.js @@ -1,7 +1,7 @@ import { createLocalVue, shallowMount } from '@vue/test-utils'; import Vuex from 'vuex'; import Embed from '~/monitoring/components/embed.vue'; -import MonitorTimeSeriesChart from '~/monitoring/components/charts/time_series.vue'; +import PanelType from 'ee_else_ce/monitoring/components/panel_type.vue'; import { TEST_HOST } from 'helpers/test_constants'; import { groups, initialState, metricsData, metricsWithData } from './mock_data'; @@ -55,7 +55,7 @@ describe('Embed', () => { it('shows an empty state when no metrics are present', () => { expect(wrapper.find('.metrics-embed').exists()).toBe(true); - expect(wrapper.find(MonitorTimeSeriesChart).exists()).toBe(false); + expect(wrapper.find(PanelType).exists()).toBe(false); }); }); @@ -71,12 +71,12 @@ describe('Embed', () => { it('shows a chart when metrics are present', () => { wrapper.setProps({}); expect(wrapper.find('.metrics-embed').exists()).toBe(true); - expect(wrapper.find(MonitorTimeSeriesChart).exists()).toBe(true); - expect(wrapper.findAll(MonitorTimeSeriesChart).length).toBe(2); + expect(wrapper.find(PanelType).exists()).toBe(true); + expect(wrapper.findAll(PanelType).length).toBe(2); }); it('includes groupId with dashboardUrl', () => { - expect(wrapper.find(MonitorTimeSeriesChart).props('groupId')).toBe(TEST_HOST); + expect(wrapper.find(PanelType).props('groupId')).toBe(TEST_HOST); }); }); }); diff --git a/spec/frontend/monitoring/panel_type_spec.js b/spec/frontend/monitoring/panel_type_spec.js index b30ad747a12..7adecc56d18 100644 --- a/spec/frontend/monitoring/panel_type_spec.js +++ b/spec/frontend/monitoring/panel_type_spec.js @@ -102,6 +102,10 @@ describe('Panel Type component', () => { expect(clipboardText()).toBe(exampleText); }); + + it('includes a default group id', () => { + expect(panelType.vm.groupId).toBe('panel-type-chart'); + }); }); describe('Anomaly Chart panel type', () => { diff --git a/spec/lib/gitlab/diff/file_collection/merge_request_diff_batch_spec.rb b/spec/lib/gitlab/diff/file_collection/merge_request_diff_batch_spec.rb index 265c6260ca9..7e945d1d140 100644 --- a/spec/lib/gitlab/diff/file_collection/merge_request_diff_batch_spec.rb +++ b/spec/lib/gitlab/diff/file_collection/merge_request_diff_batch_spec.rb @@ -123,4 +123,8 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do collection_default_args) end end + + it_behaves_like 'cacheable diff collection' do + let(:cacheable_files_count) { batch_size } + end end diff --git a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb index 7f207d5d2ee..d8f1fd26aeb 100644 --- a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb +++ b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb @@ -4,7 +4,8 @@ require 'spec_helper' describe Gitlab::Diff::FileCollection::MergeRequestDiff do let(:merge_request) { create(:merge_request) } - let(:subject) { described_class.new(merge_request.merge_request_diff, diff_options: nil) } + let(:diffable) { merge_request.merge_request_diff } + let(:subject) { described_class.new(diffable, diff_options: nil) } let(:diff_files) { subject.diff_files } describe '#diff_files' do @@ -52,6 +53,10 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do let(:stub_path) { '.gitignore' } end + it_behaves_like 'cacheable diff collection' do + let(:cacheable_files_count) { diffable.size.to_i } + end + it 'returns a valid instance of a DiffCollection' do expect(diff_files).to be_a(Gitlab::Git::DiffCollection) end diff --git a/spec/presenters/ci/legacy_stage_presenter_spec.rb b/spec/presenters/ci/legacy_stage_presenter_spec.rb new file mode 100644 index 00000000000..932cfacafb1 --- /dev/null +++ b/spec/presenters/ci/legacy_stage_presenter_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::LegacyStagePresenter do + let(:legacy_stage) { create(:ci_stage) } + let(:presenter) { described_class.new(legacy_stage) } + + let!(:build) { create(:ci_build, :tags, pipeline: legacy_stage.pipeline, stage: legacy_stage.name) } + let!(:retried_build) { create(:ci_build, :tags, :retried, pipeline: legacy_stage.pipeline, stage: legacy_stage.name) } + + before do + create(:generic_commit_status, pipeline: legacy_stage.pipeline, stage: legacy_stage.name) + end + + describe '#latest_ordered_statuses' do + subject(:latest_ordered_statuses) { presenter.latest_ordered_statuses } + + it 'preloads build tags' do + expect(latest_ordered_statuses.second.association(:tags)).to be_loaded + end + end + + describe '#retried_ordered_statuses' do + subject(:retried_ordered_statuses) { presenter.retried_ordered_statuses } + + it 'preloads build tags' do + expect(retried_ordered_statuses.first.association(:tags)).to be_loaded + end + end +end diff --git a/spec/support/shared_examples/diff_file_collections.rb b/spec/support/shared_examples/diff_file_collections.rb index 4c64abd2a97..c8bd137bf84 100644 --- a/spec/support/shared_examples/diff_file_collections.rb +++ b/spec/support/shared_examples/diff_file_collections.rb @@ -57,3 +57,45 @@ shared_examples 'unfoldable diff' do subject.unfold_diff_files([position]) end end + +shared_examples 'cacheable diff collection' do + let(:cache) { instance_double(Gitlab::Diff::HighlightCache) } + + before do + expect(Gitlab::Diff::HighlightCache).to receive(:new).with(subject) { cache } + end + + describe '#write_cache' do + it 'calls Gitlab::Diff::HighlightCache#write_if_empty' do + expect(cache).to receive(:write_if_empty).once + + subject.write_cache + end + end + + describe '#clear_cache' do + it 'calls Gitlab::Diff::HighlightCache#clear' do + expect(cache).to receive(:clear).once + + subject.clear_cache + end + end + + describe '#cache_key' do + it 'calls Gitlab::Diff::HighlightCache#key' do + expect(cache).to receive(:key).once + + subject.cache_key + end + end + + describe '#diff_files' do + it 'calls Gitlab::Diff::HighlightCache#decorate' do + expect(cache).to receive(:decorate) + .with(instance_of(Gitlab::Diff::File)) + .exactly(cacheable_files_count).times + + subject.diff_files + end + end +end |