debian-mirror-gitlab/spec/features/expand_collapse_diffs_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

311 lines
9.9 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Expand and collapse diffs', :js, feature_category: :source_code_management do
2016-08-24 12:49:21 +05:30
let(:branch) { 'expand-collapse-diffs' }
2022-11-25 23:54:43 +05:30
let_it_be(:project) { create(:project, :repository) }
let_it_be(:admin) { create(:admin) }
2016-08-24 12:49:21 +05:30
before do
2021-01-29 00:20:46 +05:30
allow(Gitlab::CurrentSettings).to receive(:diff_max_patch_bytes).and_return(100.kilobytes)
2021-02-22 17:27:13 +05:30
sign_in(admin)
gitlab_enable_admin_mode_sign_in(admin)
2016-08-24 12:49:21 +05:30
2022-05-07 20:08:51 +05:30
wait_for_requests
2016-08-24 12:49:21 +05:30
# Ensure that undiffable.md is in .gitattributes
project.repository.copy_gitattributes(branch)
2017-09-10 17:25:29 +05:30
visit project_commit_path(project, project.commit(branch))
2023-05-27 22:25:52 +05:30
wait_for_requests
2016-08-24 12:49:21 +05:30
end
def file_container(filename)
find("[data-blob-diff-path*='#{filename}']")
end
# Use define_method instead of let (which is memoized) so that this just works across a
# reload.
#
files = [
'small_diff.md', 'large_diff.md', 'large_diff_renamed.md', 'undiffable.md',
'too_large.md', 'too_large_image.jpg'
]
files.each do |file|
define_method(file.split('.').first) { file_container(file) }
end
2019-07-07 11:18:12 +05:30
it 'shows the diff content with a highlighted line when linking to line' do
2017-08-17 22:00:37 +05:30
expect(large_diff).not_to have_selector('.code')
expect(large_diff).to have_selector('.nothing-here-block')
2017-09-10 17:25:29 +05:30
visit project_commit_path(project, project.commit(branch), anchor: "#{large_diff[:id]}_0_1")
2017-08-17 22:00:37 +05:30
execute_script('window.location.reload()')
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
expect(large_diff).to have_selector('.code')
expect(large_diff).not_to have_selector('.nothing-here-block')
expect(large_diff).to have_selector('.hll')
end
2019-07-07 11:18:12 +05:30
it 'shows the diff content when linking to file' do
2017-08-17 22:00:37 +05:30
expect(large_diff).not_to have_selector('.code')
expect(large_diff).to have_selector('.nothing-here-block')
2017-09-10 17:25:29 +05:30
visit project_commit_path(project, project.commit(branch), anchor: large_diff[:id])
2017-08-17 22:00:37 +05:30
execute_script('window.location.reload()')
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
expect(large_diff).to have_selector('.code')
expect(large_diff).not_to have_selector('.nothing-here-block')
end
2016-08-24 12:49:21 +05:30
context 'visiting a commit with collapsed diffs' do
it 'shows small diffs immediately' do
expect(small_diff).to have_selector('.code')
expect(small_diff).not_to have_selector('.nothing-here-block')
end
it 'shows non-renderable diffs as such immediately, regardless of their size' do
expect(undiffable).not_to have_selector('.code')
expect(undiffable).to have_selector('.nothing-here-block')
expect(undiffable).to have_content('gitattributes')
end
it 'does not allow diffs that are larger than the maximum size to be expanded' do
expect(too_large).not_to have_selector('.code')
expect(too_large).to have_selector('.nothing-here-block')
expect(too_large).to have_content('too large')
end
it 'shows image diffs immediately, regardless of their size' do
expect(too_large_image).not_to have_selector('.nothing-here-block')
expect(too_large_image).to have_selector('.image')
end
context 'expanding a diff for a renamed file' do
before do
2016-11-03 12:29:30 +05:30
large_diff_renamed.find('.click-to-expand').click
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-08-24 12:49:21 +05:30
end
it 'shows the old content' do
old_line = large_diff_renamed.find('.line_content.old')
expect(old_line).to have_content('two copies')
end
it 'shows the new content' do
new_line = large_diff_renamed.find('.line_content.new', match: :prefer_exact)
expect(new_line).to have_content('three copies')
end
end
context 'expanding a large diff' do
before do
2016-11-03 12:29:30 +05:30
# Wait for diffs
2017-08-17 22:00:37 +05:30
find('.js-file-title', match: :first)
2016-11-03 12:29:30 +05:30
# Click `large_diff.md` title
2017-08-17 22:00:37 +05:30
all('.diff-toggle-caret')[1].click
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-08-24 12:49:21 +05:30
end
it 'shows the diff content' do
expect(large_diff).to have_selector('.code')
expect(large_diff).not_to have_selector('.nothing-here-block')
end
context 'adding a comment to the expanded diff' do
let(:comment_text) { 'A comment' }
before do
large_diff.find('.diff-line-num', match: :prefer_exact).hover
2017-09-10 17:25:29 +05:30
large_diff.find('.add-diff-note', match: :prefer_exact).click
2016-08-24 12:49:21 +05:30
large_diff.find('.note-textarea').send_keys comment_text
large_diff.find_button('Comment').click
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-08-24 12:49:21 +05:30
end
it 'adds the comment' do
expect(large_diff.find('.notes')).to have_content comment_text
end
context 'reloading the page' do
2017-09-10 17:25:29 +05:30
before do
refresh
end
2016-08-24 12:49:21 +05:30
it 'collapses the large diff by default' do
expect(large_diff).not_to have_selector('.code')
expect(large_diff).to have_selector('.nothing-here-block')
end
context 'expanding the diff' do
before do
2016-11-03 12:29:30 +05:30
# Wait for diffs
2017-08-17 22:00:37 +05:30
find('.js-file-title', match: :first)
2016-11-03 12:29:30 +05:30
# Click `large_diff.md` title
2017-08-17 22:00:37 +05:30
all('.diff-toggle-caret')[1].click
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-08-24 12:49:21 +05:30
end
it 'shows the diff content' do
expect(large_diff).to have_selector('.code')
expect(large_diff).not_to have_selector('.nothing-here-block')
end
it 'shows the diff comment' do
expect(large_diff.find('.notes')).to have_content comment_text
end
end
end
end
end
context 'collapsing an expanded diff' do
2016-11-03 12:29:30 +05:30
before do
# Wait for diffs
2017-08-17 22:00:37 +05:30
find('.js-file-title', match: :first)
2016-11-03 12:29:30 +05:30
# Click `small_diff.md` title
2017-08-17 22:00:37 +05:30
all('.diff-toggle-caret')[3].click
2016-11-03 12:29:30 +05:30
end
2016-08-24 12:49:21 +05:30
it 'hides the diff content' do
expect(small_diff).not_to have_selector('.code')
expect(small_diff).to have_selector('.nothing-here-block')
end
context 're-expanding the same diff' do
2016-11-03 12:29:30 +05:30
before do
# Wait for diffs
2017-08-17 22:00:37 +05:30
find('.js-file-title', match: :first)
2016-11-03 12:29:30 +05:30
# Click `small_diff.md` title
2017-08-17 22:00:37 +05:30
all('.diff-toggle-caret')[3].click
2016-11-03 12:29:30 +05:30
end
2016-08-24 12:49:21 +05:30
it 'shows the diff content' do
expect(small_diff).to have_selector('.code')
expect(small_diff).not_to have_selector('.nothing-here-block')
end
end
end
2017-08-17 22:00:37 +05:30
context 'expanding a diff when symlink was converted to a regular file' do
let(:branch) { 'symlink-expand-diff' }
it 'shows the content of the regular file' do
expect(page).to have_content('This diff is collapsed')
expect(page).to have_no_content('No longer a symlink')
find('.click-to-expand').click
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
expect(page).to have_content('No longer a symlink')
end
end
2016-08-24 12:49:21 +05:30
end
context 'visiting a commit without collapsed diffs' do
let(:branch) { 'feature' }
it 'does not show Expand all button' do
expect(page).not_to have_link('Expand all')
end
end
context 'visiting a commit with more than safe files' do
let(:branch) { 'expand-collapse-files' }
# safe-files -> 100 | safe-lines -> 5000 | commit-files -> 105
2023-05-27 22:25:52 +05:30
it 'does collapsing from the safe number of files to the end on small files', :aggregate_failures do
expect(page).not_to have_link('Expand all')
expect(page).to have_selector('.diff-content', count: 20)
expect(page).to have_selector('.diff-collapsed', count: 0)
visit project_commit_path(project, project.commit(branch), page: 6)
wait_for_requests
2016-08-24 12:49:21 +05:30
2023-05-27 22:25:52 +05:30
expect(page).to have_link('Expand all')
expect(page).to have_selector('.diff-content', count: 5)
2016-08-24 12:49:21 +05:30
expect(page).to have_selector('.diff-collapsed', count: 5)
%w(file-95.txt file-96.txt file-97.txt file-98.txt file-99.txt).each do |filename|
expect(find("[data-blob-diff-path*='#{filename}']")).to have_selector('.diff-collapsed')
end
end
end
context 'visiting a commit with more than safe lines' do
let(:branch) { 'expand-collapse-lines' }
# safe-files -> 100 | safe-lines -> 5000 | commit_files -> 8 (each 1250 lines)
it 'does collapsing from the safe number of lines to the end' do
expect(page).to have_link('Expand all')
expect(page).to have_selector('.diff-content', count: 6)
expect(page).to have_selector('.diff-collapsed', count: 2)
%w(file-4.txt file-5.txt).each do |filename|
expect(find("[data-blob-diff-path*='#{filename}']")).to have_selector('.diff-collapsed')
end
end
end
context 'expanding all diffs' do
before do
click_link('Expand all')
2016-09-29 09:46:39 +05:30
# Wait for elements to appear to ensure full page reload
2021-07-02 01:05:55 +05:30
expect(page).to have_content("File suppressed by a .gitattributes entry or the file's encoding is unsupported.")
2017-09-10 17:25:29 +05:30
expect(page).to have_content('This source diff could not be displayed because it is too large.')
2016-09-29 09:46:39 +05:30
expect(page).to have_content('too_large_image.jpg')
find('.note-textarea')
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-08-24 12:49:21 +05:30
end
it 'reloads the page with all diffs expanded' do
expect(small_diff).to have_selector('.code')
expect(small_diff).not_to have_selector('.nothing-here-block')
expect(large_diff).to have_selector('.code')
expect(large_diff).not_to have_selector('.nothing-here-block')
end
context 'collapsing an expanded diff' do
2016-11-03 12:29:30 +05:30
before do
# Wait for diffs
2017-08-17 22:00:37 +05:30
find('.js-file-title', match: :first)
2016-11-03 12:29:30 +05:30
# Click `small_diff.md` title
2017-08-17 22:00:37 +05:30
all('.diff-toggle-caret')[3].click
2016-11-03 12:29:30 +05:30
end
2016-08-24 12:49:21 +05:30
it 'hides the diff content' do
expect(small_diff).not_to have_selector('.code')
expect(small_diff).to have_selector('.nothing-here-block')
end
context 're-expanding the same diff' do
2016-11-03 12:29:30 +05:30
before do
# Wait for diffs
2017-08-17 22:00:37 +05:30
find('.js-file-title', match: :first)
2016-11-03 12:29:30 +05:30
# Click `small_diff.md` title
2017-08-17 22:00:37 +05:30
all('.diff-toggle-caret')[3].click
2016-11-03 12:29:30 +05:30
end
2016-08-24 12:49:21 +05:30
it 'shows the diff content' do
expect(small_diff).to have_selector('.code')
expect(small_diff).not_to have_selector('.nothing-here-block')
end
end
end
end
end