summaryrefslogtreecommitdiff
path: root/spec/features/projects/show/user_interacts_with_stars_spec.rb
blob: e0dd4f650109618cece890379a320e8f8d11dd19 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Projects > Show > User interacts with project stars' do
  let(:project) { create(:project, :public, :repository) }

  context 'when user is signed in', :js do
    let(:user) { create(:user) }

    before do
      sign_in(user)
      visit(project_path(project))
    end

    it 'toggles the star' do
      star_project

      expect(page).to have_css('.star-count', text: 1)

      unstar_project

      expect(page).to have_css('.star-count', text: 0)
    end

    it 'validates starring a project' do
      project.add_owner(user)

      star_project

      visit(dashboard_projects_path)

      expect(page).to have_css('.stars', text: 1)
    end

    it 'validates un-starring a project' do
      project.add_owner(user)

      star_project

      unstar_project

      visit(dashboard_projects_path)

      expect(page).to have_css('.stars', text: 0)
    end
  end

  context 'when user is not signed in' do
    before do
      visit(project_path(project))
    end

    it 'does not allow to star a project' do
      expect(page).not_to have_content('.toggle-star')

      find('.star-btn').click

      expect(page).to have_current_path(new_user_session_path, ignore_query: true)
    end
  end
end

private

def star_project
  click_button(_('Star'))
  wait_for_requests
end

def unstar_project
  click_button(_('Unstar'))
  wait_for_requests
end