Skip to content

Commit

Permalink
Add mailer previews to support settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitemaeric committed Jul 4, 2024
1 parent af87080 commit 4c889b1
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/claims/support/mailers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Claims::Support::MailersController < Claims::Support::ApplicationController
before_action :skip_authorization

def index
@previews = ActionMailer::Preview.all.filter { |preview| preview.preview_name.start_with?("claims/") }
end
end
15 changes: 15 additions & 0 deletions app/views/claims/support/mailers/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% render "claims/support/primary_navigation", current: :settings %>

<div class="govuk-width-container">
<h1 class="govuk-heading-l">Email Previews</h1>

<% @previews.each do |mailer| %>
<h2 class="govuk-heading-m"><%= mailer.preview_name.delete_prefix("claims/").titleize %></h2>

<% email_links = mailer.emails.map do |email| %>
<% govuk_link_to(email, url_for(controller: "/rails/mailers", action: :preview, path: "#{mailer.preview_name}/#{email}"), no_visited_state: true, new_tab: true) %>
<% end %>

<%= govuk_list email_links, type: :bullet %>
<% end %>
</div>
1 change: 1 addition & 0 deletions app/views/claims/support/settings/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<%= govuk_list [
govuk_link_to("Background Jobs", "/good_job", no_visited_state: true, new_tab: true),
govuk_link_to("Emails", claims_support_mailers_path, no_visited_state: true),
], spaced: true %>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class Application < Rails::Application
"node_modules/govuk-frontend/dist/govuk/assets",
)

config.action_mailer.show_previews = true
config.action_mailer.preview_paths << Rails.root.join("spec/mailers/previews").to_s

config.view_component.preview_paths << Rails.root.join("spec/components/previews").to_s
config.view_component.default_preview_layout = "component_preview"

Expand Down
2 changes: 2 additions & 0 deletions config/routes/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,7 @@
end

get :settings, to: "settings#index"

resources :mailers, only: :index
end
end
9 changes: 9 additions & 0 deletions spec/mailers/previews/claims/support_user_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Claims::SupportUserMailerPreview < ActionMailer::Preview
def support_user_invitation
SupportUserMailer.with(service: :claims).support_user_invitation(Claims::SupportUser.first)
end

def support_user_removal_notification
SupportUserMailer.with(service: :claims).support_user_removal_notification(Claims::SupportUser.first)
end
end
17 changes: 17 additions & 0 deletions spec/mailers/previews/claims/user_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Claims::UserMailerPreview < ActionMailer::Preview
def user_membership_created_notification
UserMailer.with(service: :claims).user_membership_created_notification(Claims::User.first, Claims::School.first)
end

def user_membership_destroyed_notification
UserMailer.with(service: :claims).user_membership_destroyed_notification(Claims::User.first, Claims::School.first)
end

def claim_submitted_notification
UserMailer.with(service: :claims).claim_submitted_notification(Claims::User.first, Claims::Claim.submitted.first)
end

def claim_created_support_notification
UserMailer.with(service: :claims).claim_created_support_notification(Claims::Claim.draft.first, Claims::User.first)
end
end
39 changes: 39 additions & 0 deletions spec/system/claims/support/view_emails_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "rails_helper"

RSpec.describe "View Emails", service: :claims, type: :system do
let(:support_user) { create(:claims_support_user) }

before do
user_exists_in_dfe_sign_in(user: support_user)
given_i_sign_in
end

scenario "User visits the emails page" do
when_i_visit_the_emails_page
then_i_can_see_the_list_of_claims_email_templates
end

private

def given_i_sign_in
visit sign_in_path
click_on "Sign in using DfE Sign In"
end

def when_i_visit_the_emails_page
click_on "Settings"
click_on "Emails"
end

def then_i_can_see_the_list_of_claims_email_templates
expect(page).to have_content("Support User Mailer")
expect(page).to have_link("support_user_invitation (opens in new tab)", href: "/rails/mailers/claims/support_user_mailer/support_user_invitation")
expect(page).to have_link("support_user_removal_notification (opens in new tab)", href: "/rails/mailers/claims/support_user_mailer/support_user_removal_notification")

expect(page).to have_content("User Mailer")
expect(page).to have_link("claim_created_support_notification (opens in new tab)", href: "/rails/mailers/claims/user_mailer/claim_created_support_notification")
expect(page).to have_link("claim_submitted_notification (opens in new tab)", href: "/rails/mailers/claims/user_mailer/claim_submitted_notification")
expect(page).to have_link("user_membership_created_notification (opens in new tab)", href: "/rails/mailers/claims/user_mailer/user_membership_created_notification")
expect(page).to have_link("user_membership_destroyed_notification (opens in new tab)", href: "/rails/mailers/claims/user_mailer/user_membership_destroyed_notification")
end
end

0 comments on commit 4c889b1

Please sign in to comment.