summaryrefslogtreecommitdiff
path: root/spec/views/projects/issues/show.html.haml_spec.rb
blob: 60a541916e998fcb8a58b31baa67e08fa410cafc (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# frozen_string_literal: true

require 'spec_helper'

describe 'projects/issues/show' do
  include_context 'project show action'

  context 'when the issue is closed' do
    before do
      allow(issue).to receive(:closed?).and_return(true)
      allow(view).to receive(:current_user).and_return(user)
    end

    context 'when the issue was moved' do
      let(:new_issue) { create(:issue, project: project, author: user) }

      before do
        issue.moved_to = new_issue
      end

      context 'when user can see the moved issue' do
        before do
          project.add_developer(user)
        end

        it 'shows "Closed (moved)" if an issue has been moved' do
          render

          expect(rendered).to have_selector('.status-box-issue-closed:not(.hidden)', text: 'Closed (moved)')
        end

        it 'shows "Closed (moved)" if an issue has been moved and discussion is locked' do
          allow(issue).to receive(:discussion_locked).and_return(true)
          render

          expect(rendered).to have_selector('.status-box-issue-closed:not(.hidden)', text: 'Closed (moved)')
        end

        it 'links "moved" to the new issue the original issue was moved to' do
          render

          expect(rendered).to have_selector("a[href=\"#{issue_path(new_issue)}\"]", text: 'moved')
        end
      end

      context 'when user cannot see moved issue' do
        it 'does not show moved issue link' do
          render

          expect(rendered).not_to have_selector("a[href=\"#{issue_path(new_issue)}\"]", text: 'moved')
        end
      end
    end

    context 'when the issue was duplicated' do
      let(:new_issue) { create(:issue, project: project, author: user) }

      before do
        issue.duplicated_to = new_issue
      end

      context 'when user can see the duplicated issue' do
        before do
          project.add_developer(user)
        end

        it 'shows "Closed (duplicated)" if an issue has been duplicated' do
          render

          expect(rendered).to have_selector('.status-box-issue-closed:not(.hidden)', text: 'Closed (duplicated)')
        end

        it 'links "duplicated" to the new issue the original issue was duplicated to' do
          render

          expect(rendered).to have_selector("a[href=\"#{issue_path(new_issue)}\"]", text: 'duplicated')
        end
      end

      context 'when user cannot see duplicated issue' do
        it 'does not show duplicated issue link' do
          render

          expect(rendered).not_to have_selector("a[href=\"#{issue_path(new_issue)}\"]", text: 'duplicated')
        end
      end
    end

    it 'shows "Closed" if an issue has not been moved or duplicated' do
      render

      expect(rendered).to have_selector('.status-box-issue-closed:not(.hidden)', text: 'Closed')
    end

    it 'shows "Closed" if discussion is locked' do
      allow(issue).to receive(:discussion_locked).and_return(true)
      render

      expect(rendered).to have_selector('.status-box-issue-closed:not(.hidden)', text: 'Closed')
    end
  end

  context 'when the issue is open' do
    before do
      allow(issue).to receive(:closed?).and_return(false)
      allow(issue).to receive(:discussion_locked).and_return(false)
    end

    it 'shows "Open" if an issue has been moved' do
      render

      expect(rendered).to have_selector('.status-box-open:not(.hidden)', text: 'Open')
    end

    it 'shows "Open" if discussion is locked' do
      allow(issue).to receive(:discussion_locked).and_return(true)
      render

      expect(rendered).to have_selector('.status-box-open:not(.hidden)', text: 'Open')
    end
  end

  context 'when the issue is related to a sentry error' do
    it 'renders a stack trace' do
      sentry_issue = double(:sentry_issue, sentry_issue_identifier: '1066622')
      allow(issue).to receive(:sentry_issue).and_return(sentry_issue)
      render

      expect(rendered).to have_selector(
        "#js-sentry-error-stack-trace"\
        "[data-issue-stack-trace-path="\
        "\"/#{project.full_path}/-/error_tracking/1066622/stack_trace.json\"]"
      )
    end
  end

  context 'when the issue is not related to a sentry error' do
    it 'does not render a stack trace' do
      render

      expect(rendered).not_to have_selector('#js-sentry-error-stack-trace')
    end
  end
end