Commit a4fd4528 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'ph/323053/removeDiffsGradualLoadFeatureFlag' into 'master'

Remove diffs gradual load feature flag [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!55478
parents c4447cc9 027d7c43
...@@ -59,7 +59,6 @@ export const MIN_RENDERING_MS = 2; ...@@ -59,7 +59,6 @@ export const MIN_RENDERING_MS = 2;
export const START_RENDERING_INDEX = 200; export const START_RENDERING_INDEX = 200;
export const INLINE_DIFF_LINES_KEY = 'highlighted_diff_lines'; export const INLINE_DIFF_LINES_KEY = 'highlighted_diff_lines';
export const PARALLEL_DIFF_LINES_KEY = 'parallel_diff_lines'; export const PARALLEL_DIFF_LINES_KEY = 'parallel_diff_lines';
export const DIFFS_PER_PAGE = 20;
export const DIFF_COMPARE_BASE_VERSION_INDEX = -1; export const DIFF_COMPARE_BASE_VERSION_INDEX = -1;
export const DIFF_COMPARE_HEAD_VERSION_INDEX = -2; export const DIFF_COMPARE_HEAD_VERSION_INDEX = -2;
......
...@@ -25,7 +25,6 @@ import { ...@@ -25,7 +25,6 @@ import {
MIN_RENDERING_MS, MIN_RENDERING_MS,
START_RENDERING_INDEX, START_RENDERING_INDEX,
INLINE_DIFF_LINES_KEY, INLINE_DIFF_LINES_KEY,
DIFFS_PER_PAGE,
DIFF_FILE_MANUAL_COLLAPSE, DIFF_FILE_MANUAL_COLLAPSE,
DIFF_FILE_AUTOMATIC_COLLAPSE, DIFF_FILE_AUTOMATIC_COLLAPSE,
EVT_PERF_MARK_FILE_TREE_START, EVT_PERF_MARK_FILE_TREE_START,
...@@ -92,15 +91,9 @@ export const setBaseConfig = ({ commit }, options) => { ...@@ -92,15 +91,9 @@ export const setBaseConfig = ({ commit }, options) => {
}; };
export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
const diffsGradualLoad = window.gon?.features?.diffsGradualLoad; let perPage = state.viewDiffsFileByFile ? 1 : 5;
let perPage = DIFFS_PER_PAGE;
let increaseAmount = 1.4; let increaseAmount = 1.4;
const startPage = 0;
if (diffsGradualLoad) {
perPage = state.viewDiffsFileByFile ? 1 : 5;
}
const startPage = diffsGradualLoad ? 0 : 1;
const id = window?.location?.hash; const id = window?.location?.hash;
const isNoteLink = id.indexOf('#note') === 0; const isNoteLink = id.indexOf('#note') === 0;
const urlParams = { const urlParams = {
...@@ -130,11 +123,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { ...@@ -130,11 +123,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
dispatch('setCurrentDiffFileIdFromNote', id.split('_').pop()); dispatch('setCurrentDiffFileIdFromNote', id.split('_').pop());
} }
if ( if (totalLoaded === pagination.total_pages || pagination.total_pages === null) {
(diffsGradualLoad &&
(totalLoaded === pagination.total_pages || pagination.total_pages === null)) ||
(!diffsGradualLoad && !pagination.next_page)
) {
commit(types.SET_RETRIEVING_BATCHES, false); commit(types.SET_RETRIEVING_BATCHES, false);
// We need to check that the currentDiffFileId points to a file that exists // We need to check that the currentDiffFileId points to a file that exists
...@@ -164,15 +153,11 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { ...@@ -164,15 +153,11 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
return null; return null;
} }
if (diffsGradualLoad) { const nextPage = page + perPage;
const nextPage = page + perPage; perPage = Math.min(Math.ceil(perPage * increaseAmount), 30);
perPage = Math.min(Math.ceil(perPage * increaseAmount), 30); increaseAmount = Math.min(increaseAmount + 0.2, 2);
increaseAmount = Math.min(increaseAmount + 0.2, 2);
return nextPage;
}
return pagination.next_page; return nextPage;
}) })
.then((nextPage) => { .then((nextPage) => {
dispatch('startRenderDiffsQueue'); dispatch('startRenderDiffsQueue');
......
...@@ -35,7 +35,6 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo ...@@ -35,7 +35,6 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
push_frontend_feature_flag(:drag_comment_selection, @project, default_enabled: true) push_frontend_feature_flag(:drag_comment_selection, @project, default_enabled: true)
push_frontend_feature_flag(:default_merge_ref_for_diffs, @project, default_enabled: :yaml) push_frontend_feature_flag(:default_merge_ref_for_diffs, @project, default_enabled: :yaml)
push_frontend_feature_flag(:core_security_mr_widget_counts, @project) push_frontend_feature_flag(:core_security_mr_widget_counts, @project)
push_frontend_feature_flag(:diffs_gradual_load, @project, default_enabled: true)
push_frontend_feature_flag(:local_file_reviews, default_enabled: :yaml) push_frontend_feature_flag(:local_file_reviews, default_enabled: :yaml)
push_frontend_feature_flag(:paginated_notes, @project, default_enabled: :yaml) push_frontend_feature_flag(:paginated_notes, @project, default_enabled: :yaml)
push_frontend_feature_flag(:confidential_notes, @project, default_enabled: :yaml) push_frontend_feature_flag(:confidential_notes, @project, default_enabled: :yaml)
......
---
name: diffs_gradual_load
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/48253/
rollout_issue_url:
milestone: '13.7'
type: development
group: group::code review
default_enabled: true
...@@ -21,9 +21,9 @@ module Gitlab ...@@ -21,9 +21,9 @@ module Gitlab
@paginated_collection = load_paginated_collection(batch_page, batch_size, diff_options) @paginated_collection = load_paginated_collection(batch_page, batch_size, diff_options)
@pagination_data = { @pagination_data = {
current_page: current_page, current_page: nil,
next_page: next_page, next_page: nil,
total_pages: total_pages total_pages: @paginated_collection.blank? ? nil : relation.size
} }
end end
...@@ -62,24 +62,6 @@ module Gitlab ...@@ -62,24 +62,6 @@ module Gitlab
@merge_request_diff.merge_request_diff_files @merge_request_diff.merge_request_diff_files
end end
def current_page
return if @paginated_collection.blank?
batch_gradual_load? ? nil : @paginated_collection.current_page
end
def next_page
return if @paginated_collection.blank?
batch_gradual_load? ? nil : @paginated_collection.next_page
end
def total_pages
return if @paginated_collection.blank?
batch_gradual_load? ? relation.size : @paginated_collection.total_pages
end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def load_paginated_collection(batch_page, batch_size, diff_options) def load_paginated_collection(batch_page, batch_size, diff_options)
batch_page ||= DEFAULT_BATCH_PAGE batch_page ||= DEFAULT_BATCH_PAGE
...@@ -87,21 +69,12 @@ module Gitlab ...@@ -87,21 +69,12 @@ module Gitlab
paths = diff_options&.fetch(:paths, nil) paths = diff_options&.fetch(:paths, nil)
paginated_collection = if batch_gradual_load? paginated_collection = relation.offset(batch_page).limit([batch_size.to_i, DEFAULT_BATCH_SIZE].min)
relation.offset(batch_page).limit([batch_size.to_i, DEFAULT_BATCH_SIZE].min)
else
relation.page(batch_page).per(batch_size)
end
paginated_collection = paginated_collection.by_paths(paths) if paths paginated_collection = paginated_collection.by_paths(paths) if paths
paginated_collection paginated_collection
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def batch_gradual_load?
Feature.enabled?(:diffs_gradual_load, @merge_request_diff.project, default_enabled: true)
end
end end
end end
end end
......
...@@ -88,8 +88,6 @@ RSpec.describe Projects::MergeRequests::DiffsController do ...@@ -88,8 +88,6 @@ RSpec.describe Projects::MergeRequests::DiffsController do
let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
before do before do
stub_feature_flags(diffs_gradual_load: false)
project.add_maintainer(user) project.add_maintainer(user)
sign_in(user) sign_in(user)
end end
...@@ -486,7 +484,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do ...@@ -486,7 +484,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
namespace_id: project.namespace.to_param, namespace_id: project.namespace.to_param,
project_id: project, project_id: project,
id: merge_request.iid, id: merge_request.iid,
page: 1, page: 0,
per_page: 20, per_page: 20,
format: 'json' format: 'json'
} }
...@@ -517,7 +515,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do ...@@ -517,7 +515,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like 'serializes diffs with expected arguments' do it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
let(:expected_options) { collection_arguments(current_page: 1, total_pages: 1).merge(merge_ref_head_diff: false) } let(:expected_options) { collection_arguments(current_page: nil, total_pages: 20).merge(merge_ref_head_diff: false) }
end end
it_behaves_like 'successful request' it_behaves_like 'successful request'
...@@ -557,7 +555,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do ...@@ -557,7 +555,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like 'serializes diffs with expected arguments' do it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
let(:expected_options) do let(:expected_options) do
collection_arguments(current_page: 1, total_pages: 1) collection_arguments(current_page: nil, total_pages: 20)
end end
end end
...@@ -576,18 +574,18 @@ RSpec.describe Projects::MergeRequests::DiffsController do ...@@ -576,18 +574,18 @@ RSpec.describe Projects::MergeRequests::DiffsController do
it_behaves_like 'serializes diffs with expected arguments' do it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
let(:expected_options) { collection_arguments(current_page: 1, total_pages: 1) } let(:expected_options) { collection_arguments(current_page: nil, total_pages: 20) }
end end
it_behaves_like 'successful request' it_behaves_like 'successful request'
end end
context 'with smaller diff batch params' do context 'with smaller diff batch params' do
subject { go(page: 2, per_page: 5) } subject { go(page: 5, per_page: 5) }
it_behaves_like 'serializes diffs with expected arguments' do it_behaves_like 'serializes diffs with expected arguments' do
let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch } let(:collection) { Gitlab::Diff::FileCollection::MergeRequestDiffBatch }
let(:expected_options) { collection_arguments(current_page: 2, next_page: 3, total_pages: 4) } let(:expected_options) { collection_arguments(current_page: nil, next_page: nil, total_pages: 20) }
end end
it_behaves_like 'successful request' it_behaves_like 'successful request'
......
...@@ -17,8 +17,6 @@ RSpec.describe 'Merge request > User sees versions', :js do ...@@ -17,8 +17,6 @@ RSpec.describe 'Merge request > User sees versions', :js do
let!(:params) { {} } let!(:params) { {} }
before do before do
stub_feature_flags(diffs_gradual_load: false)
project.add_maintainer(user) project.add_maintainer(user)
sign_in(user) sign_in(user)
visit diffs_project_merge_request_path(project, merge_request, params) visit diffs_project_merge_request_path(project, merge_request, params)
......
...@@ -8,7 +8,6 @@ import { ...@@ -8,7 +8,6 @@ import {
DIFF_VIEW_COOKIE_NAME, DIFF_VIEW_COOKIE_NAME,
INLINE_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE,
PARALLEL_DIFF_VIEW_TYPE, PARALLEL_DIFF_VIEW_TYPE,
DIFFS_PER_PAGE,
} from '~/diffs/constants'; } from '~/diffs/constants';
import { import {
setBaseConfig, setBaseConfig,
...@@ -154,16 +153,16 @@ describe('DiffsStoreActions', () => { ...@@ -154,16 +153,16 @@ describe('DiffsStoreActions', () => {
it('should fetch batch diff files', (done) => { it('should fetch batch diff files', (done) => {
const endpointBatch = '/fetch/diffs_batch'; const endpointBatch = '/fetch/diffs_batch';
const res1 = { diff_files: [{ file_hash: 'test' }], pagination: { next_page: 2 } }; const res1 = { diff_files: [{ file_hash: 'test' }], pagination: { total_pages: 7 } };
const res2 = { diff_files: [{ file_hash: 'test2' }], pagination: {} }; const res2 = { diff_files: [{ file_hash: 'test2' }], pagination: { total_pages: 7 } };
mock mock
.onGet( .onGet(
mergeUrlParams( mergeUrlParams(
{ {
w: '1', w: '1',
view: 'inline', view: 'inline',
page: 1, page: 0,
per_page: DIFFS_PER_PAGE, per_page: 5,
}, },
endpointBatch, endpointBatch,
), ),
...@@ -174,8 +173,8 @@ describe('DiffsStoreActions', () => { ...@@ -174,8 +173,8 @@ describe('DiffsStoreActions', () => {
{ {
w: '1', w: '1',
view: 'inline', view: 'inline',
page: 2, page: 5,
per_page: DIFFS_PER_PAGE, per_page: 7,
}, },
endpointBatch, endpointBatch,
), ),
......
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
let(:batch_page) { 1 } let(:batch_page) { 0 }
let(:batch_size) { 10 } let(:batch_size) { 10 }
let(:diffable) { merge_request.merge_request_diff } let(:diffable) { merge_request.merge_request_diff }
let(:diff_files_relation) { diffable.merge_request_diff_files } let(:diff_files_relation) { diffable.merge_request_diff_files }
...@@ -18,19 +18,15 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do ...@@ -18,19 +18,15 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do
let(:diff_files) { subject.diff_files } let(:diff_files) { subject.diff_files }
before do
stub_feature_flags(diffs_gradual_load: false)
end
describe 'initialize' do describe 'initialize' do
it 'memoizes pagination_data' do it 'memoizes pagination_data' do
expect(subject.pagination_data).to eq(current_page: 1, next_page: 2, total_pages: 2) expect(subject.pagination_data).to eq(current_page: nil, next_page: nil, total_pages: 20)
end end
end end
describe '#diff_files' do describe '#diff_files' do
let(:batch_size) { 3 } let(:batch_size) { 3 }
let(:paginated_rel) { diff_files_relation.page(batch_page).per(batch_size) } let(:paginated_rel) { diff_files_relation.offset(batch_page).limit(batch_size) }
let(:expected_batch_files) do let(:expected_batch_files) do
paginated_rel.map(&:new_path) paginated_rel.map(&:new_path)
...@@ -51,7 +47,7 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do ...@@ -51,7 +47,7 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do
end end
context 'another page' do context 'another page' do
let(:batch_page) { 2 } let(:batch_page) { 1 }
it 'returns correct diff files' do it 'returns correct diff files' do
expect(diff_files.map(&:new_path)).to eq(expected_batch_files) expect(diff_files.map(&:new_path)).to eq(expected_batch_files)
...@@ -63,7 +59,7 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do ...@@ -63,7 +59,7 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do
it 'returns correct diff files' do it 'returns correct diff files' do
expected_batch_files = expected_batch_files =
diff_files_relation.page(described_class::DEFAULT_BATCH_PAGE).per(batch_size).map(&:new_path) diff_files_relation.offset(described_class::DEFAULT_BATCH_PAGE).limit(batch_size).map(&:new_path)
expect(diff_files.map(&:new_path)).to eq(expected_batch_files) expect(diff_files.map(&:new_path)).to eq(expected_batch_files)
end end
...@@ -74,7 +70,7 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do ...@@ -74,7 +70,7 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do
it 'returns correct diff files' do it 'returns correct diff files' do
expected_batch_files = expected_batch_files =
diff_files_relation.page(batch_page).per(described_class::DEFAULT_BATCH_SIZE).map(&:new_path) diff_files_relation.offset(batch_page).limit(described_class::DEFAULT_BATCH_SIZE).map(&:new_path)
expect(diff_files.map(&:new_path)).to eq(expected_batch_files) expect(diff_files.map(&:new_path)).to eq(expected_batch_files)
end end
...@@ -90,29 +86,17 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do ...@@ -90,29 +86,17 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do
context 'last page' do context 'last page' do
it 'returns correct diff files' do it 'returns correct diff files' do
last_page = paginated_rel.total_pages last_page = diff_files_relation.count - batch_size
collection = described_class.new(diffable, collection = described_class.new(diffable,
last_page, last_page,
batch_size, batch_size,
diff_options: nil) diff_options: nil)
expected_batch_files = diff_files_relation.page(last_page).per(batch_size).map(&:new_path) expected_batch_files = diff_files_relation.offset(last_page).limit(batch_size).map(&:new_path)
expect(collection.diff_files.map(&:new_path)).to eq(expected_batch_files) expect(collection.diff_files.map(&:new_path)).to eq(expected_batch_files)
end end
end end
context 'with diffs gradual load feature flag enabled' do
let(:batch_page) { 0 }
before do
stub_feature_flags(diffs_gradual_load: true)
end
it 'returns correct diff files' do
expect(subject.diffs.map(&:new_path)).to eq(diff_files_relation.page(1).per(batch_size).map(&:new_path))
end
end
end end
it_behaves_like 'unfoldable diff' do it_behaves_like 'unfoldable diff' do
...@@ -130,7 +114,7 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do ...@@ -130,7 +114,7 @@ RSpec.describe Gitlab::Diff::FileCollection::MergeRequestDiffBatch do
end end
let(:diffable) { merge_request.merge_request_diff } let(:diffable) { merge_request.merge_request_diff }
let(:batch_page) { 2 } let(:batch_page) { 10 }
let(:stub_path) { '.gitignore' } let(:stub_path) { '.gitignore' }
subject do subject do
......
...@@ -9,10 +9,6 @@ RSpec.describe MergeRequestDiff do ...@@ -9,10 +9,6 @@ RSpec.describe MergeRequestDiff do
let(:diff_with_commits) { create(:merge_request).merge_request_diff } let(:diff_with_commits) { create(:merge_request).merge_request_diff }
before do
stub_feature_flags(diffs_gradual_load: false)
end
describe 'validations' do describe 'validations' do
subject { diff_with_commits } subject { diff_with_commits }
...@@ -460,19 +456,19 @@ RSpec.describe MergeRequestDiff do ...@@ -460,19 +456,19 @@ RSpec.describe MergeRequestDiff do
context 'when persisted files available' do context 'when persisted files available' do
it 'returns paginated diffs' do it 'returns paginated diffs' do
diffs = diff_with_commits.diffs_in_batch(1, 10, diff_options: diff_options) diffs = diff_with_commits.diffs_in_batch(0, 10, diff_options: diff_options)
expect(diffs).to be_a(Gitlab::Diff::FileCollection::MergeRequestDiffBatch) expect(diffs).to be_a(Gitlab::Diff::FileCollection::MergeRequestDiffBatch)
expect(diffs.diff_files.size).to eq(10) expect(diffs.diff_files.size).to eq(10)
expect(diffs.pagination_data).to eq(current_page: 1, expect(diffs.pagination_data).to eq(current_page: nil,
next_page: 2, next_page: nil,
total_pages: 2) total_pages: 20)
end end
it 'sorts diff files directory first' do it 'sorts diff files directory first' do
diff_with_commits.update!(sorted: false) # Mark as unsorted so it'll re-order diff_with_commits.update!(sorted: false) # Mark as unsorted so it'll re-order
expect(diff_with_commits.diffs_in_batch(1, 10, diff_options: diff_options).diff_file_paths).to eq([ expect(diff_with_commits.diffs_in_batch(0, 10, diff_options: diff_options).diff_file_paths).to eq([
'bar/branch-test.txt', 'bar/branch-test.txt',
'custom-highlighting/test.gitlab-custom', 'custom-highlighting/test.gitlab-custom',
'encoding/iso8859.txt', 'encoding/iso8859.txt',
...@@ -491,44 +487,22 @@ RSpec.describe MergeRequestDiff do ...@@ -491,44 +487,22 @@ RSpec.describe MergeRequestDiff do
{ ignore_whitespace_change: true } { ignore_whitespace_change: true }
end end
it 'returns a Gitlab::Diff::FileCollection::Compare with paginated diffs' do it 'returns pagination data from MergeRequestDiffBatch' do
diffs = diff_with_commits.diffs_in_batch(1, 10, diff_options: diff_options) diffs = diff_with_commits.diffs_in_batch(1, 10, diff_options: diff_options)
file_count = diff_with_commits.merge_request_diff_files.count
expect(diffs).to be_a(Gitlab::Diff::FileCollection::Compare) expect(diffs).to be_a(Gitlab::Diff::FileCollection::Compare)
expect(diffs.diff_files.size).to eq 10 expect(diffs.diff_files.size).to eq 10
expect(diffs.pagination_data).to eq(current_page: 1, next_page: 2, total_pages: 2) expect(diffs.pagination_data).to eq(current_page: nil, next_page: nil, total_pages: file_count)
end end
it 'returns an empty MergeRequestBatch with empty pagination data when the batch is empty' do it 'returns an empty MergeRequestBatch with empty pagination data when the batch is empty' do
diffs = diff_with_commits.diffs_in_batch(3, 10, diff_options: diff_options) diffs = diff_with_commits.diffs_in_batch(30, 10, diff_options: diff_options)
expect(diffs).to be_a(Gitlab::Diff::FileCollection::MergeRequestDiffBatch) expect(diffs).to be_a(Gitlab::Diff::FileCollection::MergeRequestDiffBatch)
expect(diffs.diff_files.size).to eq 0 expect(diffs.diff_files.size).to eq 0
expect(diffs.pagination_data).to eq(current_page: nil, next_page: nil, total_pages: nil) expect(diffs.pagination_data).to eq(current_page: nil, next_page: nil, total_pages: nil)
end end
context 'with gradual load enabled' do
before do
stub_feature_flags(diffs_gradual_load: true)
end
it 'returns pagination data from MergeRequestDiffBatch' do
diffs = diff_with_commits.diffs_in_batch(1, 10, diff_options: diff_options)
file_count = diff_with_commits.merge_request_diff_files.count
expect(diffs).to be_a(Gitlab::Diff::FileCollection::Compare)
expect(diffs.diff_files.size).to eq 10
expect(diffs.pagination_data).to eq(current_page: nil, next_page: nil, total_pages: file_count)
end
it 'returns an empty MergeRequestBatch with empty pagination data when the batch is empty' do
diffs = diff_with_commits.diffs_in_batch(30, 10, diff_options: diff_options)
expect(diffs).to be_a(Gitlab::Diff::FileCollection::MergeRequestDiffBatch)
expect(diffs.diff_files.size).to eq 0
expect(diffs.pagination_data).to eq(current_page: nil, next_page: nil, total_pages: nil)
end
end
end end
end end
end end
......
...@@ -19,20 +19,16 @@ RSpec.describe PaginatedDiffEntity do ...@@ -19,20 +19,16 @@ RSpec.describe PaginatedDiffEntity do
subject { entity.as_json } subject { entity.as_json }
before do
stub_feature_flags(diffs_gradual_load: false)
end
it 'exposes diff_files' do it 'exposes diff_files' do
expect(subject[:diff_files]).to be_present expect(subject[:diff_files]).to be_present
end end
it 'exposes pagination data' do it 'exposes pagination data' do
expect(subject[:pagination]).to eq( expect(subject[:pagination]).to eq(
current_page: 2, current_page: nil,
next_page: 3, next_page: nil,
next_page_href: "/#{merge_request.project.full_path}/-/merge_requests/#{merge_request.iid}/diffs_batch.json?page=3", next_page_href: nil,
total_pages: 7 total_pages: 20
) )
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment