docbrown/spec/system/user_uses_the_editor_spec.rb
Vaidehi Joshi b1de4cb1cf
Add Percy 🦔 (#7783) [deploy]
* Add Percy to Gemfile, rails helper

* Percy snapshots for using the editor

* Add PERCY_TOKEN to sample_application.yml

* Percy snapshots for visiting the homepage

* Percy snapshots for viewing an article's comments

* Percy snapshots for creating an article

* Percy snapshots for editing an article

* Percy snapshots for logged in/out user

* Remove empty spec file

* Percy snapshots for settings page

* Percy snapshots for reading list

* Percy snapshots for admin view

* Percy snapshots for moderator view

* Percy snapshots for authentication views

* Percy snapshots for article and tag views

* Percy snapshots for editing/deleting comment views

* Percy snapshots for admin views

* Percy snapshots for comment views

* Percy snapshots for organization views

* Percy snapshots for pro membership views

* Percy snapshots for podcast views

* Percy snapshots for user views

* Percy snapshots for dashboard views

* Percy snapshots for homepage views

* Percy snapshots for video views

* Add js: true in tests that require it for Percy

* Percy dependency cleanup

* Add the Percy agent
* Remove the PERCY_TOKEN from sample_application.yml
* Move the Percy gem into the "test" group in the Gemfile

* Remove duplicate snapshots, provide unique names to snapshots

* Set seed on Faker::Config for deterministic Percy snapshots

* Freeze time in js: true tests for determinstic snapshots

* Upgrade Percy to v0.26.3

* Add percy: true flag for Percy snapshotting tests

* Add more percy: true flags
2020-05-18 11:35:53 -07:00

87 lines
2.8 KiB
Ruby

require "rails_helper"
RSpec.describe "Using the editor", type: :system do
let(:user) { create(:user) }
let(:raw_text) { "../support/fixtures/sample_article_template_spec.txt" }
# what are these
let(:dir) { "../support/fixtures/sample_article.txt" }
let(:rich_dir) { "../support/fixtures/sample_rich_article.txt" }
let(:template) { File.read(File.join(File.dirname(__FILE__), dir)) }
let(:rich_template) { File.read(File.join(File.dirname(__FILE__), rich_dir)) }
before do
sign_in user
end
def read_from_file(dir)
File.read(File.join(File.dirname(__FILE__), dir))
end
def fill_markdown_with(content)
visit "/new"
fill_in "article_body_markdown", with: content
end
describe "Previewing an article", js: true do
before do
fill_markdown_with(read_from_file(raw_text))
page.execute_script("window.scrollTo(0, -100000)")
find("button", text: /\APREVIEW\z/).click
end
after do
page.evaluate_script("window.onbeforeunload = function(){}")
end
it "renders the page", percy: true do
Percy.snapshot(page, name: "Using the editor: preview an article")
end
it "fills out form with rich content and click preview" do
article_body = find("div.body")["innerHTML"]
article_body.gsub!(/"https:\/\/res\.cloudinary\.com\/.{1,}"/, "cloudinary_link")
Approvals.verify(article_body, name: "user_preview_article_body", format: :html)
end
end
describe "Submitting an article", js: true do
it "renders the page", percy: true do
fill_markdown_with(read_from_file(raw_text))
find("button", text: /\ASAVE CHANGES\z/).click
Percy.snapshot(page, name: "Using the editor: submit an article")
end
it "fill out form and submit" do
fill_markdown_with(read_from_file(raw_text))
find("button", text: /\ASAVE CHANGES\z/).click
article_body = find(:xpath, "//div[@id='article-body']")["innerHTML"]
article_body.gsub!(/"https:\/\/res\.cloudinary\.com\/.{1,}"/, "cloudinary_link")
Approvals.verify(article_body, name: "user_preview_article_body", format: :html)
end
it "user write and publish an article" do
fill_markdown_with(template.gsub("false", "true"))
find("button", text: /\ASAVE CHANGES\z/).click
["Sample Article", template[-200..], "test"].each do |text|
expect(page).to have_text(text)
end
end
context "without a title", js: true do
before do
fill_markdown_with(template.gsub("Sample Article", ""))
find("button", text: /\ASAVE CHANGES\z/).click
end
it "renders the page", percy: true do
Percy.snapshot(page, name: "Using the editor: publishing an article without a title")
end
it "shows a message that the title cannot be blank" do
expect(page).to have_text(/title: can't be blank/)
end
end
end
end