Skip to content

Commit 9f5148c

Browse files
committed
added team_managemenet feature specs and shared steps
1 parent 931c181 commit 9f5148c

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
require "rails_helper"
2+
3+
feature "Teams management", js: true do
4+
5+
background do
6+
login_as(username: 'alice', bypass_ui_login: true)
7+
end
8+
9+
context 'creating a team with no similar names in db' do
10+
scenario 'create a new team' do
11+
create_team('TEST_TEAM')
12+
expect(page).to have_content('Successfully created a team TEST_TEAM')
13+
end
14+
15+
scenario 'add user to the newly created team' do
16+
create_team('TEST_TEAM')
17+
18+
find('section.feature.payment') # ensures that we wait until the create_team action completes
19+
visit '/alice'
20+
21+
expect(page).to have_content('TEST_TEAM')
22+
end
23+
24+
scenario 'show payment plans selection' do
25+
create_team('TEST_TEAM')
26+
27+
expect(page).to have_content('Select a plan and enter payment details to get started')
28+
expect(page).to have_content('FREE')
29+
expect(page).to have_content('MONTHLY')
30+
expect(page).to have_content('ANALYTICS')
31+
end
32+
33+
scenario 'redirect to team profile page when user selects FREE plan' do
34+
create_team('TEST_TEAM')
35+
find('section.feature.payment').find('.plans .plan.free').click_link 'Select plan'
36+
37+
team_id = Team.any_of({name: 'TEST_TEAM'}).first.id
38+
expect(current_path).to eq(team_path(team_id))
39+
end
40+
end
41+
42+
context 'create a team with similar names already in db' do
43+
let!(:team) { Team.create(name: 'EXISTING_TEAM') }
44+
45+
scenario 'create a new team' do
46+
create_team('TEAM')
47+
48+
expect(page).to have_content('We found some matching teams')
49+
expect(page).to have_content('EXISTING_TEAM')
50+
expect(page).to have_content('Select')
51+
expect(page).to have_content('None of the above are my team')
52+
expect(page).to have_content('Create team TEAM')
53+
end
54+
55+
scenario 'create a new team with originally supplied name' do
56+
create_team('TEAM')
57+
find('.just-create-team').click_link('Create team TEAM')
58+
expect(page).to have_content('Successfully created a team TEAM')
59+
end
60+
61+
scenario 'attempt to create a team with exact name already in db' do
62+
create_team('EXISTING_TEAM')
63+
find('.just-create-team').click_link('Create team EXISTING_TEAM')
64+
expect(page).to have_content('There was an error in creating a team EXISTING_TEAM')
65+
expect(page).to have_content('Name is already taken')
66+
end
67+
end
68+
69+
context 'join a team with a similar name' do
70+
let!(:team) { Team.create(name: 'EXISTING_TEAM') }
71+
72+
scenario 'join an existing team' do
73+
create_team('TEAM')
74+
75+
find('.results-list').click_link('Select')
76+
77+
expect(page).to have_content('Select a plan and enter payment details to get started')
78+
expect(page).to have_content('I work at EXISTING_TEAM and just want to join the team')
79+
expect(page).to have_content('Request to join team')
80+
end
81+
82+
scenario 'request to join a team' do
83+
create_team('TEAM')
84+
85+
find('.results-list').click_link('Select')
86+
find('section.feature.payment').click_link 'Request to join team'
87+
88+
expect(current_path).to eq(teamname_path(team.slug))
89+
expect(page).to have_content('We have submitted your join request to the team admin to approve')
90+
end
91+
end
92+
93+
94+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Features
2+
module GeneralHelpers
3+
def login_as(settings = {})
4+
settings.reverse_merge!({
5+
username: 'test_user',
6+
email: 'test_user@test.com',
7+
location: 'Iceland',
8+
bypass_ui_login: false,
9+
})
10+
11+
if settings[:bypass_ui_login]
12+
settings.delete(:bypass_ui_login)
13+
14+
user = User.create(settings)
15+
page.set_rack_session(current_user: user.id)
16+
else
17+
visit "/auth/developer"
18+
19+
fill_in 'name', with: settings[:username]
20+
fill_in 'email', with: settings[:email]
21+
click_button 'Sign In'
22+
23+
fill_in 'user_username', with: settings[:username]
24+
fill_in 'user_location', with: settings[:location]
25+
click_button 'Finish'
26+
end
27+
end
28+
29+
def create_team(name = 'TEST_TEAM')
30+
visit '/employers'
31+
fill_in 'team_name', with: name
32+
click_button 'Next'
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)