diff options
author | Robert Speicher <robert@gitlab.com> | 2017-01-13 20:49:39 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-01-13 20:49:39 +0000 |
commit | e8538f7a42f63996cadfb124e9947c862cd86cb2 (patch) | |
tree | 8f3ccf829ba99dff130f5c7e9ea82b832f8ef5d9 | |
parent | 57a2735a42a05e4e48ffeafc932f82fa397d990f (diff) | |
parent | 45485947e255c11ca6a45bddf0ba22e9f7dfdea5 (diff) | |
download | gitlab-ce-e8538f7a42f63996cadfb124e9947c862cd86cb2.tar.gz |
Merge branch 'fix-single-team-specs' into 'master'
Improve single mattermost team select disabled state
See merge request !8276
-rw-r--r-- | app/views/projects/mattermosts/_team_selection.html.haml | 11 | ||||
-rw-r--r-- | spec/features/projects/services/mattermost_slash_command_spec.rb | 85 |
2 files changed, 88 insertions, 8 deletions
diff --git a/app/views/projects/mattermosts/_team_selection.html.haml b/app/views/projects/mattermosts/_team_selection.html.haml index 24e86b8497f..a80f9aa4c4a 100644 --- a/app/views/projects/mattermosts/_team_selection.html.haml +++ b/app/views/projects/mattermosts/_team_selection.html.haml @@ -7,20 +7,21 @@ %p = @teams.one? ? 'The team' : 'Select the team' where the slash commands will be used in - - selected_id = @teams.keys.first if @teams.one? + - selected_id = @teams.one? ? @teams.keys.first : 0 - options = mattermost_teams_options(@teams) - options = options_for_select(options, selected_id) - = f.select(:team_id, options, {}, { class: 'form-control', selected: "#{selected_id}" }) + = f.select(:team_id, options, {}, { class: 'form-control', disabled: @teams.one?, selected: selected_id }) + = f.hidden_field(:team_id, value: selected_id) if @teams.one? .help-block - if @teams.one? - This is the only team where you are an administrator. + This is the only available team. - else - The list shows teams where you are administrator - To create a team, ask your Mattermost system administrator. + The list shows all available teams. To create a team, = link_to "#{Gitlab.config.mattermost.host}/create_team" do use Mattermost's interface = icon('external-link') + or ask your Mattermost system administrator. %hr %h4 Command trigger word %p Choose the word that will trigger commands diff --git a/spec/features/projects/services/mattermost_slash_command_spec.rb b/spec/features/projects/services/mattermost_slash_command_spec.rb index 8de827447ff..86a07b2c679 100644 --- a/spec/features/projects/services/mattermost_slash_command_spec.rb +++ b/spec/features/projects/services/mattermost_slash_command_spec.rb @@ -33,10 +33,89 @@ feature 'Setup Mattermost slash commands', feature: true do expect(value).to eq(token) end - describe 'mattermost service is enabled' do - it 'shows the add to mattermost button' do - expect(page).to have_link 'Add to Mattermost' + it 'shows the add to mattermost button' do + expect(page).to have_link('Add to Mattermost') + end + + it 'shows an explanation if user is a member of no teams' do + stub_teams(count: 0) + + 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 + + it 'shows an explanation if user is a member of 1 team' do + stub_teams(count: 1) + + 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.') + end + + 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' + + team_name = teams.first[1]['display_name'] + select_element = find('select#mattermost_team_id') + selected_option = select_element.find('option[selected]') + + expect(select_element['disabled']).to be(true) + expect(selected_option).to have_content(team_name.to_s) + end + + it 'has a hidden input for the prefilled value if user is a member of 1 team' do + teams = stub_teams(count: 1) + + click_link 'Add to Mattermost' + + expect(find('input#mattermost_team_id', visible: false).value).to eq(teams.first[0].to_s) + end + + it 'shows an explanation user is a member of multiple teams' do + stub_teams(count: 2) + + 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.') + end + + it 'shows a select with team options user is a member of multiple teams' do + stub_teams(count: 2) + + click_link 'Add to Mattermost' + + select_element = find('select#mattermost_team_id') + selected_option = select_element.find('option[selected]') + + expect(select_element['disabled']).to be(false) + expect(selected_option).to have_content('Select team...') + # The 'Select team...' placeholder is item `0`. + expect(select_element.all('option').count).to eq(3) + end + + def stub_teams(count: 0) + teams = create_teams(count) + + allow_any_instance_of(MattermostSlashCommandsService).to receive(:list_teams) { teams } + + teams + end + + def create_teams(count = 0) + teams = {} + + count.times do |i| + i += 1 + teams[i] = { id: i, display_name: i } end + + teams end describe 'mattermost service is not enabled' do |