Read about our upcoming Code of Conduct on this issue

This instance was upgraded to Heptapod 0.28.0 today

projects_spec.rb 7.18 KB
Newer Older
1
2
require 'spec_helper'

3
describe 'Dashboard Projects' do
4
  let(:user) { create(:user) }
5
  let(:project) { create(:project, :repository, name: 'awesome stuff') }
6
  let(:project2) { create(:project, :public, name: 'Community project') }
7

8
  before do
9
    project.add_developer(user)
10
11
12
    sign_in(user)
  end

13
  it_behaves_like "an autodiscoverable RSS feed with current_user's feed token" do
14
15
16
    before do
      visit dashboard_projects_path
    end
17
  end
18
19
20
21
22
23

  it 'shows the project the user in a member of in the list' do
    visit dashboard_projects_path
    expect(page).to have_content('awesome stuff')
  end

24
25
26
27
28
29
30
31
  it 'shows "New project" button' do
    visit dashboard_projects_path

    page.within '#content-body' do
      expect(page).to have_link('New project')
    end
  end

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
  context 'when user has access to the project' do
    it 'shows role badge' do
      visit dashboard_projects_path

      page.within '.user-access-role' do
        expect(page).to have_content('Developer')
      end
    end

    context 'when role changes', :use_clean_rails_memory_store_fragment_caching do
      it 'displays the right role' do
        visit dashboard_projects_path

        page.within '.user-access-role' do
          expect(page).to have_content('Developer')
        end

        project.members.last.update(access_level: 40)

        visit dashboard_projects_path

        page.within '.user-access-role' do
          expect(page).to have_content('Maintainer')
        end
      end
    end
  end

60
61
  context 'when last_repository_updated_at, last_activity_at and update_at are present' do
    it 'shows the last_repository_updated_at attribute as the update date' do
Lin Jen-Shin's avatar
Lin Jen-Shin committed
62
      project.update!(last_repository_updated_at: Time.now, last_activity_at: 1.hour.ago)
63

64
65
66
67
      visit dashboard_projects_path

      expect(page).to have_xpath("//time[@datetime='#{project.last_repository_updated_at.getutc.iso8601}']")
    end
68
69

    it 'shows the last_activity_at attribute as the update date' do
Lin Jen-Shin's avatar
Lin Jen-Shin committed
70
      project.update!(last_repository_updated_at: 1.hour.ago, last_activity_at: Time.now)
71
72
73
74
75

      visit dashboard_projects_path

      expect(page).to have_xpath("//time[@datetime='#{project.last_activity_at.getutc.iso8601}']")
    end
76
  end
77

78
79
  context 'when last_repository_updated_at and last_activity_at are missing' do
    it 'shows the updated_at attribute as the update date' do
Lin Jen-Shin's avatar
Lin Jen-Shin committed
80
      project.update!(last_repository_updated_at: nil, last_activity_at: nil)
81
82
83
84
85
86
      project.touch

      visit dashboard_projects_path

      expect(page).to have_xpath("//time[@datetime='#{project.updated_at.getutc.iso8601}']")
    end
87
88
  end

89
90
91
92
93
  context 'when on Your projects tab' do
    it 'shows all projects by default' do
      visit dashboard_projects_path

      expect(page).to have_content(project.name)
94
      expect(find('.nav-links li:nth-child(1) .badge-pill')).to have_content(1)
95
96
97
98
99
100
101
102
103
104
105
106
    end

    it 'shows personal projects on personal projects tab', :js do
      project3 = create(:project, namespace: user.namespace)

      visit dashboard_projects_path

      click_link 'Personal'

      expect(page).not_to have_content(project.name)
      expect(page).to have_content(project3.name)
    end
107
108
109
110
111
112
113
114

    it 'sorts projects by most stars when sorting by most stars' do
      project_with_most_stars = create(:project, namespace: user.namespace, star_count: 10)

      visit dashboard_projects_path(sort: :stars_desc)

      expect(first('.project-row')).to have_content(project_with_most_stars.title)
    end
Ezekiel Kigbo's avatar
Ezekiel Kigbo committed
115
116
117
118
119
120
121
122

    it 'shows tabs to filter by all projects or personal' do
      visit dashboard_projects_path
      segmented_button = page.find('.filtered-search-nav .button-filter-group')

      expect(segmented_button).to have_content 'All'
      expect(segmented_button).to have_content 'Personal'
    end
123
124
  end

125
126
127
128
129
130
131
132
133
134
  context 'when on Starred projects tab', :js do
    it 'shows the empty state when there are no starred projects' do
      visit(starred_dashboard_projects_path)

      element = page.find('.row.empty-state')

      expect(element).to have_content("You don't have starred projects yet.")
      expect(element.find('.svg-content img')['src']).to have_content('illustrations/starred_empty')
    end

135
136
137
138
139
140
141
    it 'shows only starred projects' do
      user.toggle_star(project2)

      visit(starred_dashboard_projects_path)

      expect(page).not_to have_content(project.name)
      expect(page).to have_content(project2.name)
142
143
      expect(find('.nav-links li:nth-child(1) .badge-pill')).to have_content(1)
      expect(find('.nav-links li:nth-child(2) .badge-pill')).to have_content(1)
144
    end
Ezekiel Kigbo's avatar
Ezekiel Kigbo committed
145
146
147

    it 'does not show tabs to filter by all projects or personal' do
      visit(starred_dashboard_projects_path)
148

Ezekiel Kigbo's avatar
Ezekiel Kigbo committed
149
150
      expect(page).not_to have_content '.filtered-search-nav'
    end
151
152
  end

153
  describe 'with a pipeline', :clean_gitlab_redis_shared_state do
154
    let(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit.sha, ref: project.default_branch) }
155
156

    before do
157
158
159
160
      # Since the cache isn't updated when a new pipeline is created
      # we need the pipeline to advance in the pipeline since the cache was created
      # by visiting the login page.
      pipeline.succeed
161
162
163
164
    end

    it 'shows that the last pipeline passed' do
      visit dashboard_projects_path
165

166
      page.within('.controls') do
167
        expect(page).to have_xpath("//a[@href='#{pipelines_project_commit_path(project, project.commit, ref: pipeline.ref)}']")
168
169
170
171
        expect(page).to have_css('.ci-status-link')
        expect(page).to have_css('.ci-status-icon-success')
        expect(page).to have_link('Commit: passed')
      end
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
    end

    context 'guest user of project and project has private pipelines' do
      let(:guest_user) { create(:user) }

      before do
        project.update(public_builds: false)
        project.add_guest(guest_user)
        sign_in(guest_user)
      end

      it 'shows that the last pipeline passed' do
        visit dashboard_projects_path

        page.within('.controls') do
          expect(page).not_to have_xpath("//a[@href='#{pipelines_project_commit_path(project, project.commit, ref: pipeline.ref)}']")
          expect(page).not_to have_css('.ci-status-link')
          expect(page).not_to have_css('.ci-status-icon-success')
          expect(page).not_to have_link('Commit: passed')
        end
      end
193
194
195
    end
  end

196
  context 'last push widget', :use_clean_rails_memory_store_caching do
197
    before do
198
199
      event = create(:push_event, project: project, author: user)

200
      create(:push_event_payload, event: event, ref: 'feature', action: :created)
201

202
203
      Users::LastPushEventService.new(user).cache_last_push_event(event)

204
205
206
      visit dashboard_projects_path
    end

207
    it 'shows "Create merge request" button' do
208
209
210
211
212
213
214
      expect(page).to have_content 'You pushed to feature'

      within('#content-body') do
        find_link('Create merge request', visible: false).click
      end

      expect(page).to have_selector('.merge-request-form')
215
      expect(current_path).to eq project_new_merge_request_path(project)
216
      expect(find('#merge_request_target_project_id', visible: false).value).to eq project.id.to_s
217
      expect(find('input#merge_request_source_branch', visible: false).value).to eq 'feature'
218
      expect(find('input#merge_request_target_branch', visible: false).value).to eq 'master'
219
220
    end
  end
221
end