summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/features/sidebar_shared_examples.rb
blob: d509d124de0cba9143753877a29f95b50cf22bba (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# frozen_string_literal: true

RSpec.shared_examples 'issue boards sidebar' do
  include MobileHelpers

  before do
    first_card.click
  end

  it 'shows sidebar when clicking issue' do
    expect(page).to have_selector('[data-testid="issue-boards-sidebar"]')
  end

  it 'closes sidebar when clicking issue' do
    expect(page).to have_selector('[data-testid="issue-boards-sidebar"]')

    first_card.click

    expect(page).not_to have_selector('[data-testid="issue-boards-sidebar"]')
  end

  it 'shows issue details when sidebar is open', :aggregate_failures do
    page.within('[data-testid="issue-boards-sidebar"]') do
      expect(page).to have_content(issue.title)
      expect(page).to have_content(issue.to_reference)
    end
  end

  context 'when clicking close button' do
    before do
      find('[data-testid="issue-boards-sidebar"] .gl-drawer-close-button').click
    end

    it 'unhighlights the active issue card' do
      expect(first_card[:class]).not_to include('is-active')
      expect(first_card[:class]).not_to include('multi-select')
    end

    it 'closes sidebar when clicking close button' do
      expect(page).not_to have_selector('[data-testid="issue-boards-sidebar"]')
    end
  end

  context 'in notifications subscription' do
    it 'displays notifications toggle', :aggregate_failures do
      page.within('[data-testid="sidebar-notifications"]') do
        expect(page).to have_selector('[data-testid="subscription-toggle"]')
        expect(page).to have_content('Notifications')
        expect(page).not_to have_content('Disabled by project owner')
      end
    end

    it 'shows toggle as on then as off as user toggles to subscribe and unsubscribe', :aggregate_failures do
      wait_for_requests
      subscription_button = find('[data-testid="subscription-toggle"]')

      subscription_button.click

      expect(subscription_button).to have_css("button.is-checked")

      subscription_button.click

      wait_for_requests

      expect(subscription_button).to have_css("button:not(.is-checked)")
    end

    context 'when notifications have been disabled' do
      before do
        project.update_attribute(:emails_disabled, true)

        refresh_and_click_first_card
      end

      it 'displays a message that notifications have been disabled' do
        page.within('[data-testid="sidebar-notifications"]') do
          expect(page).to have_selector('[data-testid="subscription-toggle"]', class: 'is-disabled')
          expect(page).to have_content('Disabled by project owner')
        end
      end
    end
  end

  context 'confidentiality' do
    it 'make issue confidential' do
      page.within('.confidentiality') do
        expect(page).to have_content('Not confidential')

        click_button 'Edit'
        expect(page).to have_css('.sidebar-item-warning-message')

        within('.sidebar-item-warning-message') do
          click_button 'Turn on'
        end

        wait_for_requests

        expect(page).to have_content('This issue is confidential')
      end
    end
  end

  context 'in time tracking' do
    it 'displays time tracking feature with default message' do
      page.within('[data-testid="time-tracker"]') do
        expect(page).to have_content('Time tracking')
        expect(page).to have_content('No estimate or time spent')
      end
    end

    context 'when only spent time is recorded' do
      before do
        issue.timelogs.create!(time_spent: 3600, user: user)

        refresh_and_click_first_card
      end

      it 'shows the total time spent only' do
        page.within('[data-testid="time-tracker"]') do
          expect(page).to have_content('Spent: 1h')
          expect(page).not_to have_content('Estimated')
        end
      end
    end

    context 'when only estimated time is recorded' do
      before do
        issue.update!(time_estimate: 3600)

        refresh_and_click_first_card
      end

      it 'shows the estimated time only', :aggregate_failures do
        page.within('[data-testid="time-tracker"]') do
          expect(page).to have_content('Estimated: 1h')
          expect(page).not_to have_content('Spent')
        end
      end
    end

    context 'when estimated and spent times are available' do
      before do
        issue.timelogs.create!(time_spent: 1800, user: user)
        issue.update!(time_estimate: 3600)

        refresh_and_click_first_card
      end

      it 'shows time tracking progress bar' do
        page.within('[data-testid="time-tracker"]') do
          expect(page).to have_selector('[data-testid="timeTrackingComparisonPane"]')
        end
      end

      it 'shows both estimated and spent time text', :aggregate_failures do
        page.within('[data-testid="time-tracker"]') do
          expect(page).to have_content('Spent 30m')
          expect(page).to have_content('Est 1h')
        end
      end
    end

    context 'when limitedToHours instance option is turned on' do
      before do
        # 3600+3600*24 = 1d 1h or 25h
        issue.timelogs.create!(time_spent: 3600 + 3600 * 24, user: user)
        stub_application_setting(time_tracking_limit_to_hours: true)

        refresh_and_click_first_card
      end

      it 'shows the total time spent only' do
        page.within('[data-testid="time-tracker"]') do
          expect(page).to have_content('Spent: 25h')
        end
      end
    end
  end
end