Add specs for comment and modal controller Turbo Frame actions

This commit is contained in:
Andreas Nedbal 2023-10-23 22:48:08 +02:00 committed by Andreas Nedbal
parent 4c393defb7
commit bc0ce6be3f
3 changed files with 59 additions and 1 deletions

View File

@ -7,7 +7,7 @@ class ModalController < ApplicationController
skip_before_action :find_active_announcements, :banned? skip_before_action :find_active_announcements, :banned?
def close def close
redirect_to root_path unless turbo_frame_request? return redirect_to root_path unless turbo_frame_request?
render inline: turbo_frame_tag("modal") render inline: turbo_frame_tag("modal")
end end
end end

View File

@ -34,4 +34,33 @@ describe CommentController, type: :controller do
end end
end end
end end
describe "#show_reactions" do
let(:answer_author) { FactoryBot.create(:user) }
let(:answer) { FactoryBot.create(:answer, user: answer_author) }
let(:commenter) { FactoryBot.create(:user) }
let(:comment) { FactoryBot.create(:comment, answer:, user: commenter) }
context "a regular web navigation request" do
subject { get :show_reactions, params: { username: commenter.screen_name, id: comment.id } }
it "should redirect to the answer page" do
subject
expect(response).to redirect_to answer_path(username: answer_author.screen_name, id: answer.id)
end
end
context "a Turbo Frame request" do
subject { get :show_reactions, params: { username: commenter.screen_name, id: comment.id } }
it "renders the show_reaction template" do
@request.headers["Turbo-Frame"] = "some_id"
subject
expect(response).to render_template(:show_reactions)
end
end
end
end end

View File

@ -0,0 +1,29 @@
# frozen_string_literal: true
require "rails_helper"
describe ModalController, type: :controller do
describe "#close" do
context "a regular web navigation request" do
subject { get :close }
it "should redirect to the root page" do
subject
expect(response).to redirect_to root_path
end
end
context "a Turbo Frame request" do
subject { get :close }
it "renders the show_reaction template" do
@request.headers["Turbo-Frame"] = "some_id"
subject
expect(response.body).to include('<turbo-frame id="modal"></turbo-frame>')
end
end
end
end