diff options
Diffstat (limited to 'spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb')
-rw-r--r-- | spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb | 204 |
1 files changed, 102 insertions, 102 deletions
diff --git a/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb b/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb index ac9cb00be84..c6825ee663a 100644 --- a/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb +++ b/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb @@ -3,158 +3,158 @@ require 'spec_helper' describe 'Set up Mattermost slash commands', :js do - let(:user) { create(:user) } - let(:project) { create(:project) } - let(:mattermost_enabled) { true } - - before do - stub_mattermost_setting(enabled: mattermost_enabled) - project.add_maintainer(user) - sign_in(user) - visit edit_project_service_path(project, :mattermost_slash_commands) - end - describe 'user visits the mattermost slash command config page' do - it 'shows a help message' do - expect(page).to have_content("This service allows users to perform common") + include_context 'project service activation' + + before do + stub_mattermost_setting(enabled: mattermost_enabled) + visit_project_integration('Mattermost slash commands') end - it 'shows a token placeholder' do - token_placeholder = find_field('service_token')['placeholder'] + context 'mattermost service is enabled' do + let(:mattermost_enabled) { true } - expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx') - end + it 'shows a help message' do + expect(page).to have_content("This service allows users to perform common") + end - it 'redirects to the integrations page after saving but not activating' do - token = ('a'..'z').to_a.join + it 'shows a token placeholder' do + token_placeholder = find_field('service_token')['placeholder'] - fill_in 'service_token', with: token - find('input[name="service[active]"] + button').click - click_on 'Save changes' + expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx') + end - expect(current_path).to eq(project_settings_integrations_path(project)) - expect(page).to have_content('Mattermost slash commands settings saved, but not activated.') - end + it 'redirects to the integrations page after saving but not activating' do + token = ('a'..'z').to_a.join - it 'redirects to the integrations page after activating' do - token = ('a'..'z').to_a.join + fill_in 'service_token', with: token + click_active_toggle + click_on 'Save changes' - fill_in 'service_token', with: token - click_on 'Save changes' + expect(current_path).to eq(project_settings_integrations_path(project)) + expect(page).to have_content('Mattermost slash commands settings saved, but not activated.') + end - expect(current_path).to eq(project_settings_integrations_path(project)) - expect(page).to have_content('Mattermost slash commands activated.') - end + it 'redirects to the integrations page after activating' do + token = ('a'..'z').to_a.join - it 'shows the add to mattermost button' do - expect(page).to have_link('Add to Mattermost') - end + fill_in 'service_token', with: token + click_on 'Save changes' - it 'shows an explanation if user is a member of no teams' do - stub_teams(count: 0) + expect(current_path).to eq(project_settings_integrations_path(project)) + expect(page).to have_content('Mattermost slash commands activated.') + end - click_link 'Add to Mattermost' + it 'shows the add to mattermost button' do + expect(page).to have_link('Add to Mattermost') + end - expect(page).to have_content('You aren’t a member of any team on the Mattermost instance') - expect(page).to have_link('join a team', href: "#{Gitlab.config.mattermost.host}/select_team") - end + it 'shows an explanation if user is a member of no teams' do + stub_teams(count: 0) - it 'shows an explanation if user is a member of 1 team' do - stub_teams(count: 1) + click_link 'Add to Mattermost' - click_link 'Add to Mattermost' + expect(page).to have_content('You aren’t a member of any team on the Mattermost instance') + expect(page).to have_link('join a team', href: "#{Gitlab.config.mattermost.host}/select_team") + end - expect(page).to have_content('The team where the slash commands will be used in') - expect(page).to have_content('This is the only available team that you are a member of.') - end + it 'shows an explanation if user is a member of 1 team' do + stub_teams(count: 1) - it 'shows a disabled prefilled select if user is a member of 1 team' do - teams = stub_teams(count: 1) + click_link 'Add to Mattermost' - click_link 'Add to Mattermost' + expect(page).to have_content('The team where the slash commands will be used in') + expect(page).to have_content('This is the only available team that you are a member of.') + end - team_name = teams.first['display_name'] - select_element = find('#mattermost_team_id') - selected_option = select_element.find('option[selected]') + it 'shows a disabled prefilled select if user is a member of 1 team' do + teams = stub_teams(count: 1) - expect(select_element['disabled']).to eq("true") - expect(selected_option).to have_content(team_name.to_s) - end + click_link 'Add to Mattermost' - it 'has a hidden input for the prefilled value if user is a member of 1 team' do - teams = stub_teams(count: 1) + team_name = teams.first['display_name'] + select_element = find('#mattermost_team_id') + selected_option = select_element.find('option[selected]') - click_link 'Add to Mattermost' + expect(select_element['disabled']).to eq("true") + expect(selected_option).to have_content(team_name.to_s) + end - expect(find('input#mattermost_team_id', visible: false).value).to eq(teams.first['id']) - end + it 'has a hidden input for the prefilled value if user is a member of 1 team' do + teams = stub_teams(count: 1) - it 'shows an explanation user is a member of multiple teams' do - stub_teams(count: 2) + click_link 'Add to Mattermost' - click_link 'Add to Mattermost' + expect(find('input#mattermost_team_id', visible: false).value).to eq(teams.first['id']) + end - expect(page).to have_content('Select the team where the slash commands will be used in') - expect(page).to have_content('The list shows all available teams that you are a member of.') - end + it 'shows an explanation user is a member of multiple teams' do + stub_teams(count: 2) - it 'shows a select with team options user is a member of multiple teams' do - stub_teams(count: 2) + click_link 'Add to Mattermost' - click_link 'Add to Mattermost' + expect(page).to have_content('Select the team where the slash commands will be used in') + expect(page).to have_content('The list shows all available teams that you are a member of.') + end - select_element = find('#mattermost_team_id') + it 'shows a select with team options user is a member of multiple teams' do + stub_teams(count: 2) - expect(select_element['disabled']).to be_falsey - expect(select_element.all('option').count).to eq(3) - end + click_link 'Add to Mattermost' - it 'shows an error alert with the error message if there is an error requesting teams' do - allow_any_instance_of(MattermostSlashCommandsService).to receive(:list_teams) { [[], 'test mattermost error message'] } + select_element = find('#mattermost_team_id') - click_link 'Add to Mattermost' + expect(select_element['disabled']).to be_falsey + expect(select_element.all('option').count).to eq(3) + end - expect(page).to have_selector('.alert') - expect(page).to have_content('test mattermost error message') - end + it 'shows an error alert with the error message if there is an error requesting teams' do + allow_any_instance_of(MattermostSlashCommandsService).to receive(:list_teams) { [[], 'test mattermost error message'] } - it 'enables the submit button if the required fields are provided', :js do - stub_teams(count: 1) + click_link 'Add to Mattermost' - click_link 'Add to Mattermost' + expect(page).to have_selector('.alert') + expect(page).to have_content('test mattermost error message') + end - expect(find('input[type="submit"]')['disabled']).not_to eq("true") - end + it 'enables the submit button if the required fields are provided', :js do + stub_teams(count: 1) - it 'disables the submit button if the required fields are not provided', :js do - stub_teams(count: 1) + click_link 'Add to Mattermost' - click_link 'Add to Mattermost' + expect(find('input[type="submit"]')['disabled']).not_to eq("true") + end - fill_in('mattermost_trigger', with: '') + it 'disables the submit button if the required fields are not provided', :js do + stub_teams(count: 1) - expect(find('input[type="submit"]')['disabled']).to eq("true") - end + click_link 'Add to Mattermost' - def stub_teams(count: 0) - teams = create_teams(count) + fill_in('mattermost_trigger', with: '') - allow_any_instance_of(MattermostSlashCommandsService).to receive(:list_teams) { [teams, nil] } + expect(find('input[type="submit"]')['disabled']).to eq("true") + end - teams - end + def stub_teams(count: 0) + teams = create_teams(count) - def create_teams(count = 0) - teams = [] + allow_any_instance_of(MattermostSlashCommandsService).to receive(:list_teams) { [teams, nil] } - count.times do |i| - teams.push({ "id" => "x#{i}", "display_name" => "x#{i}-name" }) + teams end - teams + def create_teams(count = 0) + teams = [] + + count.times do |i| + teams.push({ "id" => "x#{i}", "display_name" => "x#{i}-name" }) + end + + teams + end end - describe 'mattermost service is not enabled' do + context 'mattermost service is not enabled' do let(:mattermost_enabled) { false } it 'shows the correct trigger url' do |