|
| 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 |
0 commit comments