debian-mirror-gitlab/spec/features/projects/services/user_activates_mattermost_slash_command_spec.rb

180 lines
5.6 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2018-12-05 23:21:45 +05:30
describe 'Set up Mattermost slash commands', :js do
2017-08-17 22:00:37 +05:30
describe 'user visits the mattermost slash command config page' do
2020-05-24 23:13:21 +05:30
include_context 'project service activation'
before do
stub_mattermost_setting(enabled: mattermost_enabled)
visit_project_integration('Mattermost slash commands')
2017-08-17 22:00:37 +05:30
end
2020-05-24 23:13:21 +05:30
context 'mattermost service is enabled' do
let(:mattermost_enabled) { true }
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'shows a help message' do
expect(page).to have_content("This service allows users to perform common")
end
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'shows a token placeholder' do
token_placeholder = find_field('service_token')['placeholder']
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx')
end
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'redirects to the integrations page after saving but not activating' do
token = ('a'..'z').to_a.join
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
fill_in 'service_token', with: token
click_active_toggle
click_on 'Save changes'
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
expect(current_path).to eq(project_settings_integrations_path(project))
expect(page).to have_content('Mattermost slash commands settings saved, but not activated.')
end
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'redirects to the integrations page after activating' do
token = ('a'..'z').to_a.join
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
fill_in 'service_token', with: token
click_on 'Save changes'
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
expect(current_path).to eq(project_settings_integrations_path(project))
expect(page).to have_content('Mattermost slash commands activated.')
end
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'shows the add to mattermost button' do
expect(page).to have_link('Add to Mattermost')
end
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'shows an explanation if user is a member of no teams' do
stub_teams(count: 0)
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
click_link 'Add to Mattermost'
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
expect(page).to have_content('You arent 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
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'shows an explanation if user is a member of 1 team' do
stub_teams(count: 1)
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
click_link 'Add to Mattermost'
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
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
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'shows a disabled prefilled select if user is a member of 1 team' do
teams = stub_teams(count: 1)
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
click_link 'Add to Mattermost'
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
team_name = teams.first['display_name']
select_element = find('#mattermost_team_id')
selected_option = select_element.find('option[selected]')
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
expect(select_element['disabled']).to eq("true")
expect(selected_option).to have_content(team_name.to_s)
end
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'has a hidden input for the prefilled value if user is a member of 1 team' do
teams = stub_teams(count: 1)
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
click_link 'Add to Mattermost'
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
expect(find('input#mattermost_team_id', visible: false).value).to eq(teams.first['id'])
end
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'shows an explanation user is a member of multiple teams' do
stub_teams(count: 2)
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
click_link 'Add to Mattermost'
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
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
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'shows a select with team options user is a member of multiple teams' do
stub_teams(count: 2)
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
click_link 'Add to Mattermost'
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
select_element = find('#mattermost_team_id')
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
expect(select_element['disabled']).to be_falsey
expect(select_element.all('option').count).to eq(3)
end
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
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'] }
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
click_link 'Add to Mattermost'
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
expect(page).to have_selector('.alert')
expect(page).to have_content('test mattermost error message')
end
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'enables the submit button if the required fields are provided', :js do
stub_teams(count: 1)
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
click_link 'Add to Mattermost'
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
expect(find('input[type="submit"]')['disabled']).not_to eq("true")
end
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
it 'disables the submit button if the required fields are not provided', :js do
stub_teams(count: 1)
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
click_link 'Add to Mattermost'
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
fill_in('mattermost_trigger', with: '')
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
expect(find('input[type="submit"]')['disabled']).to eq("true")
end
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
def stub_teams(count: 0)
teams = create_teams(count)
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
allow_any_instance_of(MattermostSlashCommandsService).to receive(:list_teams) { [teams, nil] }
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
teams
2017-08-17 22:00:37 +05:30
end
2020-05-24 23:13:21 +05:30
def create_teams(count = 0)
teams = []
count.times do |i|
teams.push({ "id" => "x#{i}", "display_name" => "x#{i}-name" })
end
teams
end
2017-08-17 22:00:37 +05:30
end
2020-05-24 23:13:21 +05:30
context 'mattermost service is not enabled' do
2017-08-17 22:00:37 +05:30
let(:mattermost_enabled) { false }
it 'shows the correct trigger url' do
value = find_field('request_url').value
2017-09-10 17:25:29 +05:30
expect(value).to match("api/v4/projects/#{project.id}/services/mattermost_slash_commands/trigger")
2017-08-17 22:00:37 +05:30
end
it 'shows a token placeholder' do
token_placeholder = find_field('service_token')['placeholder']
expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx')
end
end
end
describe 'stable logo url' do
it 'shows a publicly available logo' do
2020-04-22 19:07:51 +05:30
expect(File.exist?(Rails.root.join('public/slash-command-logo.png'))).to be_truthy
2017-08-17 22:00:37 +05:30
end
end
end