Commit 4d2f8fdc authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Alex Kalderimis

Add group and instance level integration tests

This adds an initial test of the Mattermost Slash Command integration
for group- and instance-level.

This is an initial effort in order to have coverage for
https://gitlab.com/gitlab-org/gitlab/-/issues/331262.

Further tests will be added in
https://gitlab.com/gitlab-org/gitlab/-/issues/331325.
parent 8d852684
......@@ -48,9 +48,12 @@ module IntegrationsActions
private
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def integration
@integration ||= find_or_initialize_non_project_specific_integration(params[:id])
@service ||= @integration # TODO: remove references to @service https://gitlab.com/gitlab-org/gitlab/-/issues/329759
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
def success_message
if integration.active?
......
......@@ -85,7 +85,7 @@ class Projects::ServicesController < Projects::ApplicationController
def integration
@integration ||= @project.find_or_initialize_service(params[:id])
@service ||= @integration # TODO: remove references to @service
@service ||= @integration # TODO: remove references to @service https://gitlab.com/gitlab-org/gitlab/-/issues/329759
end
alias_method :service, :integration
......
---
title: Fix errors in instance and group-level integration pages for some integrations
merge_request: 62054
author:
type: fixed
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'User activates the instance-level Mattermost Slash Command integration', :js do
include_context 'instance integration activation'
before do
stub_mattermost_setting(enabled: true)
visit_instance_integration('Mattermost slash commands')
end
let(:edit_path) { edit_admin_application_settings_integration_path(:mattermost_slash_commands) }
include_examples 'user activates the Mattermost Slash Command integration'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'User activates the group-level Mattermost Slash Command integration', :js do
include_context 'group integration activation'
before do
stub_mattermost_setting(enabled: true)
visit_group_integration('Mattermost slash commands')
end
let(:edit_path) { edit_group_settings_integration_path(group, :mattermost_slash_commands) }
include_examples 'user activates the Mattermost Slash Command integration'
end
......@@ -14,35 +14,10 @@ RSpec.describe 'Set up Mattermost slash commands', :js do
context 'mattermost service is enabled' do
let(:mattermost_enabled) { true }
it 'shows a help message' do
expect(page).to have_content("Use this service to perform common")
end
it 'shows a token placeholder' do
token_placeholder = find_field('service_token')['placeholder']
expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx')
end
it 'redirects to the integrations page after saving but not activating' do
token = ('a'..'z').to_a.join
fill_in 'service_token', with: token
click_active_checkbox
click_save_integration
expect(current_path).to eq(edit_project_service_path(project, :mattermost_slash_commands))
expect(page).to have_content('Mattermost slash commands settings saved, but not active.')
end
it 'redirects to the integrations page after activating' do
token = ('a'..'z').to_a.join
fill_in 'service_token', with: token
click_save_integration
describe 'activation' do
let(:edit_path) { edit_project_service_path(project, :mattermost_slash_commands) }
expect(current_path).to eq(edit_project_service_path(project, :mattermost_slash_commands))
expect(page).to have_content('Mattermost slash commands settings saved and active.')
include_examples 'user activates the Mattermost Slash Command integration'
end
it 'shows the add to mattermost button' do
......
# frozen_string_literal: true
RSpec.shared_context 'group integration activation' do
include_context 'instance and group integration activation'
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
before_all do
group.add_owner(user)
end
before do
sign_in(user)
end
def visit_group_integrations
visit group_settings_integrations_path(group)
end
def visit_group_integration(name)
visit_group_integrations
within('#content-body') do
click_link(name)
end
end
end
# frozen_string_literal: true
RSpec.shared_context 'instance and group integration activation' do
include_context 'integration activation'
def click_save_integration
click_save_changes_button
click_save_settings_modal
end
def click_save_changes_button
click_button('Save changes')
end
def click_save_settings_modal
click_button('Save')
end
end
# frozen_string_literal: true
RSpec.shared_context 'instance integration activation' do
include_context 'instance and group integration activation'
let_it_be(:user) { create(:user, :admin) }
before do
sign_in(user)
gitlab_enable_admin_mode_sign_in(user)
end
def visit_instance_integrations
visit integrations_admin_application_settings_path
end
def visit_instance_integration(name)
visit_instance_integrations
within('#content-body') do
click_link(name)
end
end
end
......@@ -70,3 +70,9 @@ Integration.available_services_names.each do |service|
end
end
end
RSpec.shared_context 'integration activation' do
def click_active_checkbox
find('label', text: 'Active').click
end
end
# frozen_string_literal: true
RSpec.shared_context 'project service activation' do
include_context 'integration activation'
let(:project) { create(:project) }
let(:user) { create(:user) }
......@@ -21,10 +23,6 @@ RSpec.shared_context 'project service activation' do
end
end
def click_active_checkbox
find('label', text: 'Active').click
end
def click_save_integration
click_button('Save changes')
end
......
# frozen_string_literal: true
RSpec.shared_examples 'user activates the Mattermost Slash Command integration' do
it 'shows a help message' do
expect(page).to have_content('Use this service to perform common')
end
it 'shows a token placeholder' do
token_placeholder = find_field('service_token')['placeholder']
expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx')
end
it 'redirects to the integrations page after saving but not activating' do
token = ('a'..'z').to_a.join
fill_in 'service_token', with: token
click_active_checkbox
click_save_integration
expect(current_path).to eq(edit_path)
expect(page).to have_content('Mattermost slash commands settings saved, but not active.')
end
it 'redirects to the integrations page after activating' do
token = ('a'..'z').to_a.join
fill_in 'service_token', with: token
click_save_integration
expect(current_path).to eq(edit_path)
expect(page).to have_content('Mattermost slash commands settings saved and active.')
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment