PageRenderTime 76ms CodeModel.GetById 51ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/features/users/user_browses_projects_on_user_page_spec.rb

https://gitlab.com/tnir/gitlab-ce
Ruby | 148 lines | 112 code | 35 blank | 1 comment | 0 complexity | 34815856fa2403bb60bf0d53afaa33df MD5 | raw file
  1# frozen_string_literal: true
  2
  3require 'spec_helper'
  4
  5describe 'Users > User browses projects on user page', :js do
  6  let!(:user) { create :user }
  7  let!(:private_project) do
  8    create :project, :private, name: 'private', namespace: user.namespace do |project|
  9      project.add_maintainer(user)
 10    end
 11  end
 12
 13  let!(:internal_project) do
 14    create :project, :internal, name: 'internal', namespace: user.namespace do |project|
 15      project.add_maintainer(user)
 16    end
 17  end
 18
 19  let!(:public_project) do
 20    create :project, :public, name: 'public', namespace: user.namespace do |project|
 21      project.add_maintainer(user)
 22    end
 23  end
 24
 25  def click_nav_link(name)
 26    page.within '.nav-links' do
 27      click_link name
 28    end
 29  end
 30
 31  it 'hides loading spinner after load', :js do
 32    visit user_path(user)
 33    click_nav_link('Personal projects')
 34
 35    wait_for_requests
 36
 37    expect(page).not_to have_selector('.loading-status .loading', visible: true)
 38  end
 39
 40  it 'paginates projects', :js do
 41    project = create(:project, namespace: user.namespace, updated_at: 2.minutes.since)
 42    project2 = create(:project, namespace: user.namespace, updated_at: 1.minute.since)
 43    allow(Project).to receive(:default_per_page).and_return(1)
 44
 45    sign_in(user)
 46    visit user_path(user)
 47    click_nav_link('Personal projects')
 48
 49    wait_for_requests
 50
 51    expect(page).to have_content(project.name)
 52
 53    click_link('Next')
 54
 55    expect(page).to have_content(project2.name)
 56  end
 57
 58  it 'does not have incorrectly interpolated message', :js do
 59    project = create(:project, namespace: user.namespace, updated_at: 2.minutes.since)
 60
 61    sign_in(user)
 62    visit user_path(user)
 63    click_nav_link('Personal projects')
 64
 65    wait_for_requests
 66
 67    expect(page).to have_content(project.name)
 68    expect(page).not_to have_content("_('Updated')")
 69  end
 70
 71  context 'when not signed in' do
 72    it 'renders user public project' do
 73      visit user_path(user)
 74      click_nav_link('Personal projects')
 75
 76      expect(page).to have_css('.tab-content #projects.active')
 77      expect(title).to start_with(user.name)
 78
 79      expect(page).to have_content(public_project.name)
 80      expect(page).not_to have_content(private_project.name)
 81      expect(page).not_to have_content(internal_project.name)
 82    end
 83  end
 84
 85  context 'when signed in as another user' do
 86    let(:another_user) { create :user }
 87
 88    before do
 89      sign_in(another_user)
 90    end
 91
 92    it 'renders user public and internal projects' do
 93      visit user_path(user)
 94      click_nav_link('Personal projects')
 95
 96      expect(title).to start_with(user.name)
 97
 98      expect(page).not_to have_content(private_project.name)
 99      expect(page).to have_content(public_project.name)
100      expect(page).to have_content(internal_project.name)
101    end
102  end
103
104  context 'when signed in as user' do
105    before do
106      sign_in(user)
107    end
108
109    describe 'personal projects' do
110      it 'renders all user projects' do
111        visit user_path(user)
112        click_nav_link('Personal projects')
113
114        expect(title).to start_with(user.name)
115        expect(page).to have_content(private_project.name)
116        expect(page).to have_content(public_project.name)
117        expect(page).to have_content(internal_project.name)
118      end
119    end
120
121    describe 'contributed projects' do
122      context 'when user has contributions' do
123        let(:contributed_project) do
124          create :project, :public, :empty_repo
125        end
126
127        before do
128          Issues::CreateService.new(contributed_project, user, { title: 'Bug in old browser' }).execute
129          event = create(:push_event, project: contributed_project, author: user)
130          create(:push_event_payload, event: event, commit_count: 3)
131        end
132
133        it 'renders contributed project' do
134          visit user_path(user)
135
136          expect(title).to start_with(user.name)
137          expect(page).to have_css('.js-contrib-calendar')
138
139          click_nav_link('Contributed projects')
140
141          page.within '#contributed' do
142            expect(page).to have_content(contributed_project.name)
143          end
144        end
145      end
146    end
147  end
148end