* Starting out
* Building away...
* Hooking buttons up
* Hook Auth Provider buttons to Array Field
* trying to fix NoNameError
* Remains InviteOnlyMode disable and tests
* Smashing remaining tasks
* Last of tasks
* add tests
* Complete specs and tests 😅
* Fix bug
* Additional guard
* pass event to functions
* Position Email Auth first
* Fix bug in Email Auth Modal
* Fix spacing issue
* Update docs for adminModal.js
* Show/hide Enabled Indicator with Enable/Undo buttons
* Complete Auth Providers functionality
* Update app/javascript/admin/controllers/config_controller.js
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
* Update app/javascript/admin/controllers/config_controller.js
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
* Update app/controllers/admin/configs_controller.rb
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
* Update helper names
* better implementation of EnabledIndicator show/hide
* Small copy changes
* Update spec/helpers/authentication_helper_spec.rb
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
* Update app/views/admin/configs/show.html.erb
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
* Update app/helpers/authentication_helper.rb
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
201 lines
5.6 KiB
Ruby
201 lines
5.6 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "Creating Comment", type: :system, js: true do
|
|
include_context "with runkit_tag"
|
|
|
|
let(:user) { create(:user) }
|
|
let(:raw_comment) { Faker::Lorem.paragraph }
|
|
let(:runkit_comment) { compose_runkit_comment "comment 1" }
|
|
let(:runkit_comment2) { compose_runkit_comment "comment 2" }
|
|
|
|
# the article should be created before signing in
|
|
let!(:article) { create(:article, user_id: user.id, show_comments: true) }
|
|
|
|
before do
|
|
sign_in user
|
|
end
|
|
|
|
it "User fills out comment box normally" do
|
|
visit article.path.to_s
|
|
wait_for_javascript
|
|
|
|
fill_in "text-area", with: raw_comment
|
|
click_button("Submit")
|
|
expect(page).to have_text(raw_comment)
|
|
end
|
|
|
|
context "when user makes too many comments" do
|
|
let(:rate_limit_checker) { RateLimitChecker.new(user) }
|
|
|
|
before do
|
|
allow(RateLimitChecker).to receive(:new).and_return(rate_limit_checker)
|
|
allow(rate_limit_checker).to receive(:limit_by_action)
|
|
.with(:comment_creation)
|
|
.and_return(true)
|
|
end
|
|
|
|
it "displays a rate limit modal" do
|
|
visit article.path.to_s
|
|
wait_for_javascript
|
|
|
|
fill_in "text-area", with: raw_comment
|
|
click_button("Submit")
|
|
expect(page).to have_text("Wait a Moment...")
|
|
end
|
|
|
|
it "closes modal with close button" do
|
|
visit article.path.to_s
|
|
wait_for_javascript
|
|
|
|
fill_in "text-area", with: raw_comment
|
|
click_button("Submit")
|
|
click_button("Got it")
|
|
expect(page).not_to have_text("Wait a Moment...")
|
|
end
|
|
|
|
it "closes model with 'x' image button" do
|
|
visit article.path.to_s
|
|
wait_for_javascript
|
|
|
|
fill_in "text-area", with: raw_comment
|
|
click_button("Submit")
|
|
find(".crayons-modal__box__header").click_button
|
|
expect(page).not_to have_text("Wait a Moment...")
|
|
end
|
|
end
|
|
|
|
context "with Runkit tags" do
|
|
before do
|
|
visit article.path.to_s
|
|
|
|
wait_for_javascript
|
|
end
|
|
|
|
it "Users fills out comment box with a Runkit tag" do
|
|
fill_in "text-area", with: runkit_comment
|
|
click_button("Submit")
|
|
|
|
expect_runkit_tag_to_be_active
|
|
end
|
|
|
|
it "Users fills out comment box 2 Runkit tags" do
|
|
fill_in "text-area", with: runkit_comment
|
|
click_button("Submit")
|
|
|
|
expect_runkit_tag_to_be_active
|
|
|
|
fill_in "text-area", with: runkit_comment2
|
|
click_button("Submit")
|
|
|
|
expect_runkit_tag_to_be_active(count: 2)
|
|
end
|
|
|
|
it "User fill out comment box with a Runkit tag, then clicks preview" do
|
|
fill_in "text-area", with: runkit_comment
|
|
click_button("Preview")
|
|
|
|
expect_runkit_tag_to_be_active
|
|
end
|
|
end
|
|
|
|
it "User fill out comment box then click previews and submit" do
|
|
visit article.path.to_s
|
|
wait_for_javascript
|
|
|
|
fill_in "text-area", with: raw_comment
|
|
click_button("Preview")
|
|
expect(page).to have_text(raw_comment)
|
|
expect(page).to have_text("Continue editing")
|
|
click_button("Continue editing")
|
|
expect(page).to have_text("Preview")
|
|
click_button("Submit")
|
|
expect(page).to have_text(raw_comment)
|
|
end
|
|
|
|
it "User replies to a comment" do
|
|
create(:comment, commentable: article, user_id: user.id)
|
|
visit article.path.to_s
|
|
|
|
wait_for_javascript
|
|
|
|
find(".toggle-reply-form").click
|
|
find(:xpath, "//textarea[contains(@id, \"textarea-for\")]").set(raw_comment)
|
|
click_button("Submit")
|
|
expect(page).to have_text(raw_comment)
|
|
end
|
|
|
|
# This is basically a black box test for
|
|
# ./app/javascripts/packs/validateFileInputs.js
|
|
# which is logic to validate file size and format when uploading via a form.
|
|
it "User attaches a valid image" do
|
|
visit article.path.to_s
|
|
|
|
attach_file(
|
|
"image-upload-main",
|
|
Rails.root.join("app/assets/images/apple-icon.png"),
|
|
visible: :hidden,
|
|
)
|
|
|
|
expect(page).to have_no_css("div.file-upload-error")
|
|
end
|
|
|
|
it "User attaches a large image" do
|
|
visit article.path.to_s
|
|
|
|
reduce_max_file_size = 'document.querySelector("#image-upload-main").setAttribute("data-max-file-size-mb", "0")'
|
|
page.execute_script(reduce_max_file_size)
|
|
expect(page).to have_selector('input[data-max-file-size-mb="0"]', visible: :hidden)
|
|
|
|
attach_file(
|
|
"image-upload-main",
|
|
Rails.root.join("app/assets/images/onboarding-background.png"),
|
|
visible: :hidden,
|
|
)
|
|
|
|
expect(page).to have_css(
|
|
"div.file-upload-error",
|
|
text: "File size too large (0.07 MB). The limit is 0 MB.",
|
|
visible: :hidden,
|
|
)
|
|
end
|
|
|
|
it "User attaches an invalid file type" do
|
|
visit article.path.to_s
|
|
|
|
allow_vids = 'document.querySelector("#image-upload-main").setAttribute("data-permitted-file-types", "[\"video\"]")'
|
|
page.execute_script(allow_vids)
|
|
expect(page).to have_selector('input[data-permitted-file-types="[\"video\"]"]', visible: :hidden)
|
|
|
|
attach_file(
|
|
"image-upload-main",
|
|
Rails.root.join("app/assets/images/apple-icon.png"),
|
|
visible: :hidden,
|
|
)
|
|
|
|
expect(page).to have_css(
|
|
"div.file-upload-error",
|
|
text: "Invalid file format (image). Only video files are permitted.",
|
|
visible: :hidden,
|
|
)
|
|
end
|
|
|
|
it "User attaches a file with too long of a name" do
|
|
visit article.path.to_s
|
|
|
|
limit_length = 'document.querySelector("#image-upload-main").setAttribute("data-max-file-name-length", "5")'
|
|
page.execute_script(limit_length)
|
|
expect(page).to have_selector('input[data-max-file-name-length="5"]', visible: :hidden)
|
|
|
|
attach_file(
|
|
"image-upload-main",
|
|
Rails.root.join("app/assets/images/apple-icon.png"),
|
|
visible: :hidden,
|
|
)
|
|
|
|
expect(page).to have_css(
|
|
"div.file-upload-error",
|
|
text: "File name is too long. It can't be longer than 5 characters.",
|
|
visible: :hidden,
|
|
)
|
|
end
|
|
end
|