summaryrefslogtreecommitdiff
path: root/spec/features/commit_spec.rb
blob: a9672569a4a6fd78b73ecd50782559e9eebb7724 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Commit', feature_category: :source_code_management do
  let_it_be(:project) { create(:project, :repository) }
  let_it_be(:user) { create(:user) }

  describe "single commit view" do
    let(:commit) do
      project.repository.commits(nil, limit: 100).find do |commit|
        commit.diffs.size > 1
      end
    end

    let(:files) { commit.diffs.diff_files.to_a }

    before do
      stub_feature_flags(async_commit_diff_files: false)
      project.add_maintainer(user)
      sign_in(user)
    end

    describe "commit details" do
      subject { page }

      before do
        visit project_commit_path(project, commit)
      end

      it "shows the short commit message" do
        expect(page).to have_content(commit.title)
      end

      it "reports the correct number of total changes" do
        expect(page).to have_content("Changes #{commit.diffs.size}")
      end

      it 'renders diff stats', :js do
        expect(page).to have_selector(".diff-stats")
      end

      it_behaves_like 'code highlight'
    end

    describe "pagination" do
      before do
        stub_const("Projects::CommitController::COMMIT_DIFFS_PER_PAGE", 1)

        visit project_commit_path(project, commit)
      end

      it "shows an adjusted count for changed files on this page", :js do
        expect(page).to have_content("Showing 1 changed file")
      end

      it "shows only the first diff on the first page" do
        expect(page).to have_selector(".files ##{files[0].file_hash}")
        expect(page).not_to have_selector(".files ##{files[1].file_hash}")
      end

      it "can navigate to the second page" do
        within(".files .gl-pagination") do
          click_on("2")
        end

        expect(page).not_to have_selector(".files ##{files[0].file_hash}")
        expect(page).to have_selector(".files ##{files[1].file_hash}")
      end
    end
  end
end