Commit 976e2e11 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'blackst0ne-replace-spinach-admin-emails.feature' into 'master'

Replace the `admin/emails.feature` spinach test with an rspec analog

See merge request gitlab-org/gitlab-ee!5513
parents 192b08df 132340d2
---
title: 'Replace the `admin/emails.feature` spinach test with an rspec analog'
merge_request: 5513
author: '@blackst0ne'
type: other
require 'spec_helper'
describe "Admin::Emails", :js do
let!(:current_user) { create(:admin) }
let!(:group) { create(:group) }
let!(:project) { create(:project, namespace: group) }
describe "GET /admin/email" do
before do
sign_in(current_user)
visit admin_email_path
end
describe 'Recipient group select' do
it "includes groups and projects" do
find('.ajax-admin-email-select').click
wait_for_requests
expect(page).to have_selector('.ajax-admin-email-dropdown li', count: 3)
group_names = page.all('.ajax-admin-email-dropdown li .group-name')
expect(group_names[0].text).to eq('All')
expect(group_names[1].text).to eq(group.name)
expect(find('.ajax-admin-email-dropdown li .project-name').text).to eq(project.name)
end
end
end
end
require "spec_helper"
describe "Admin sends notification", :js do
let(:group) { create(:group) }
let!(:project) { create(:project, group: group) }
let(:admin) { create(:admin) }
let(:user) { create(:user) }
before do
group.add_developer(user)
sign_in(admin)
visit(admin_email_path)
end
it "sends notification" do
perform_enqueued_jobs do
NOTIFICATION_TEXT = "Your project has been moved.".freeze
body = find(:xpath, "//body")
page.within("form#new-admin-email") do
fill_in(:subject, with: "My Subject")
fill_in(:body, with: NOTIFICATION_TEXT)
find(".ajax-admin-email-select").click
wait_for_requests
options = body.all("li.select2-result")
expect(body).to have_selector("li.select2-result", count: 3)
expect(options[0].text).to include("All")
expect(options[1].text).to include(group.name)
expect(options[2].text).to include(project.name)
body.find("input.select2-input").set(group.name)
body.find(".group-name", text: group.name).click
click_button("Send message")
end
end
emails = ActionMailer::Base.deliveries
expect(find(".flash-notice")).to have_content("Email sent")
expect(emails.count).to eql(group.users.count)
expect(emails.last.text_part.body.decoded).to include(NOTIFICATION_TEXT)
end
end
require "spec_helper"
describe "Admin unsubscribes from notification" do
set(:user) { create(:user) }
set(:urlsafe_email) { Base64.urlsafe_encode64(user.email) }
before do
sign_in(user)
visit(unsubscribe_path(urlsafe_email))
end
it "unsubscribes from notifications" do
NOTIFICATION_TEXT = "You have been unsubscribed from receiving GitLab administrator notifications.".freeze
perform_enqueued_jobs do
click_button("Unsubscribe")
end
last_email = ActionMailer::Base.deliveries.last
expect(current_path).to eq(root_path)
expect(last_email.text_part.body.decoded).to include(NOTIFICATION_TEXT)
end
end
Feature: Admin email
Background:
Given I sign in as an admin
And there are groups with projects
@javascript
Scenario: Create a new email notification
Given I visit admin email page
When I submit form with email notification info
Then I should see a notification email is begin sent
And admin emails are being sent
Scenario: Create a new email notification
Given I visit unsubscribe from admin notification page
When I click unsubscribe
Then I get redirected to the sign in path
And unsubscribed email is sent
class Spinach::Features::AdminEmail < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedAdmin
step 'I submit form with email notification info' do
perform_enqueued_jobs do
ActionMailer::Base.deliveries = []
@email_text = "Your project has been moved."
@selected_group = Group.last
# ensure there are ppl to be emailed
2.times do
@selected_group.add_user(create(:user), Gitlab::Access::DEVELOPER)
end
page.within('form#new-admin-email') do
fill_in :subject, with: 'my subject'
fill_in :body, with: @email_text
# Note: Unable to use select2 helper because
# the helper uses select2 method "val" to select the group from the dropdown
# and the method "val" requires "initSelection" to be used in the select2 call
select2_container = first("#s2id_recipients")
select2_container.find(".select2-choice").click
find(:xpath, "//body").find("input.select2-input").set(@selected_group.name)
page.execute_script(%|$("input.select2-input:visible").keyup();|)
find(:xpath, "//body").find(".group-name", text: @selected_group.name).click
find('.btn-create').click
end
end
end
step 'I should see a notification email is begin sent' do
expect(find('.flash-notice')).to have_content 'Email sent'
end
step 'admin emails are being sent' do
expect(ActionMailer::Base.deliveries.count).to eql @selected_group.users.count
mail = ActionMailer::Base.deliveries.last
expect(mail.text_part.body.decoded).to include @email_text
end
step 'I visit unsubscribe from admin notification page' do
@user = create(:user)
urlsafe_email = Base64.urlsafe_encode64(@user.email)
visit unsubscribe_path(urlsafe_email)
end
step 'I click unsubscribe' do
perform_enqueued_jobs do
click_button 'Unsubscribe'
end
end
step 'I get redirected to the sign in path' do
expect(current_path).to eq root_path
end
step 'unsubscribed email is sent' do
mail = ActionMailer::Base.deliveries.last
expect(mail.text_part.body.decoded).to include "You have been unsubscribed from receiving GitLab administrator notifications."
end
end
......@@ -8,11 +8,4 @@ module SharedAdmin
step 'system has users' do
2.times { create(:user) }
end
And 'there are groups with projects' do
2.times do
group = create :group
create :project, group: group
end
end
end
......@@ -188,10 +188,6 @@ module SharedPaths
visit admin_teams_path
end
step 'I visit admin email page' do
visit admin_email_path
end
step 'I visit admin settings page' do
visit admin_application_settings_path
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