docbrown/spec/system/admin/admin_manages_pages_spec.rb
Julianna Tetreault b12ebfa0e5
RFC #74, Pt. 2: Private Forem Landing Page (#13819)
* Adds landing_page checkbox for Landing Page

* Adds landing_page to page_params in Admin::Pages::Controller

* Adds landing_page to admin_manages_pages and admin_creates_pages specs

* Adjusts copy for Landing Page in pages/_form.html.erb

* Places #post_a_job before #privacy in Pages::Controller
  - Ensures that all page-related methods are properly
 alphabetized

* Alphabetizes remaining out-of-order page-related methods
  - Ensures that all page-related methods within the
 Pages::Controller are in alphabetical order, following
 the order of the other methods

* Adds landing_page check to ApplicationController#verify_private_forem

* Adds a single_landing_page validation to the Page model

* Adds a lock.svg to /images and uses it in the pages index

* Adjusts buttons and checkboxes to use crayons class in pages partial

* Ensures that pages/_form.html.erb destroy button uses crayons

* Adds a landing_page validation-related test to page_spec.rb

* Updates #single_landing_page validation and error message

* WIP: Adds JS modal upon landing_page error in pages/_form.html.erb

* Adds a working modal upon error in pages/_form.html.erb
- Removes redundant #single_landing_page validation from Page
- Adds #has_a_landing_page? in place of #single_landing_page
- Conditionally renders the landing_page checkbox in _form.html.erb
- Adds styles to locked screen/landing page modal
- Adds copy to locked screen/landing page modal
- Beings adding buttons to overwrite current landing_page

* Updates the data-modal-selectors and ids in pages/_form.html.erb

* Uses #landing_page_path within pages/_form.html.erb modal
- Adds a link_to to link to the current landing page in the modal
- Adds styles to buttons and link_to in modal

* Adds back single_landing_page validation to Page.rb

* Reverts changes and updates methods within Page.rb
 - Reverts changes to #single_landing_page
 - Refactors #has_a_landing_page? and #landing_page_path
 - Updates div id in pages/_form.html.erb

* Adjusts #single_landing_page error message slightly

* Adds a test for landing_pages in stories_index_spec.rb

* Adds an overwrite attribute to Pages for the modal in _form
  - Fixes anonymous spelling

* Refactors pages/_form.html.erb and cleans up spelling

* Adds a safe operator to landing_page.path in Page
  - Adjusts the placement of the hidden value in pages/_form.html.erb

* Updates styling for Current Locked Screen link

* Adds the ability to overwrite an active landing page on click
  - Adds Admin::PagesController#update_and_overwrite and refactors
AdminPages::Controller#udpate to work with new method
  - Adds a remote attribute, overwrite, to Admin::PagesController
via a hidden_field in pages/_form.html.erb and an attr_accessor in
the Page model
  - Adds a toggleOverwrite() function to pages/_form.html.erb to
toggle the (soon to be hidden) overwrite checkbox in the form --
the checkbox is toggled on button click

* Adds a guard clause to #landing_page_path in Page.rb

* Adds a safe naviagtor to Admin::PagesController#update_and_overwrite_landing_page

* Adds a type and return to Overwrite button to prevent submit

* Adds a hidden class to the overwrite checkbox field in _form.html.erb
  - Hides the overwrite checkbox since it is only used to overwrite
the landing_page boolean on click of the "Overwrite current locked
screen" button

* Adds Admin::PagesController#create_and_overwrite and removes hidden class

* Adds landing page-related tests to admin_manages_pages_spec.rb

* Remove messy commented out code and place it in GH comment instead

* PR Review Feedback: Renames remote attr, defines class methods, updates views
  - Renames remote attribute to overwrite_landing_page
  - Updates all necessary views, methods, etc. w/ new attr
  - Defines two class methods to make code more extensible
  - Updates all necessary views, methods, etc. w/ new methods

* Remove unnecessary comments and revert changes to ternary in _form.html.erb

* Adjustments for accessibility within _form and index
  - Adds a descriptive id to <p> in _form.html.erb
  - Adds an ariadescribedby field to _form.html.erb
  - Adjusts title within index.html.erb

* Refactors landing_page-related code per PR review requests
  - Adds a landing_page_modal_controller.js that handles
and further customizes the dismiss and overwrite button, and
handles opening the modal
  - Adds a _landing_page_modal partial to extract modal-specific
html outside of the _form.html.erb partial
  - Refactors _form.html.erb to account for the _landing_page_modal
partial and the landing_page_modal_controller.js
  - Refactors the overwrite checkbox to be a hidden_field rather than
a hidden checkbox and removes existing hidden_field to accomodate it
  - Loads the @landing_page within Admin::PagesController#edit for
use by the _landing_page_modal.html.erb partial
  - Refactors Page#single_landing_page to be more readable
  - Removes useless JS from _form.html.erb

* Removes #landing_page_exists? class method since it isnt used now

* Uses the #landing_page class method within ApplicationController

* Removes pending status from test in admin_manages_pages_spec.rb

* Adds an e2e test for landing pages and adds to seeds_e2e
  - Adds a landingPage.spec.js to test landing pages
  - Adds a Page to seeds_e2e.rb for landingPage.spec.js

* Removes references to articles from e2e test and adds clickable link

* Adds another Page to seeds_e2e.rb and updates link names in test

* Adds the Current Locked Screen title to modal and opens in new link

* Renames Dismiss to Cancel and updates all necessary code

* Adjusts landingPage.spec.js

* check for existing landing page before showing modal

* Update Cypress tests and fix bug in LandingPageModalController

* Apply suggestions from code review

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Orders Pages by created_at desc in /admin/pages/index.html.erb for consistency

* Targets specific edit button in landingPage.spec.js

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
Co-authored-by: rhymes <github@rhymes.dev>
2021-06-10 11:46:24 -06:00

148 lines
5.5 KiB
Ruby

require "rails_helper"
RSpec.describe "Admin manages pages", type: :system do
let(:admin) { create(:user, :super_admin) }
before do
create(:page,
slug: "test-page",
body_html: "<div>hello there</div>",
title: "Test Page",
description: "A test page",
is_top_level_path: true,
landing_page: false)
sign_in admin
visit admin_pages_path
end
it "loads the view" do
expect(page).to have_content("Pages")
expect(page).to have_content("New page")
end
describe "when there are default pages" do
it "shows an override defaults section with a warning" do
expect(page).to have_content("Override defaults")
expect(page).to have_content("Note: Proceed with caution.")
end
it "shows the code of conduct link in the overrides section" do
within(".pages__override_defaults") do
expect(page).to have_link("Code of Conduct", href: code_of_conduct_path)
expect(page).to have_link("Override", href: new_admin_page_path(slug: "code-of-conduct"))
end
end
it "shows the privacy policy link in the overrides section" do
within(".pages__override_defaults") do
expect(page).to have_link("Privacy Policy", href: privacy_path)
expect(page).to have_link("Override", href: new_admin_page_path(slug: "privacy"))
end
end
it "shows the terms of use link in the overrides section" do
within(".pages__override_defaults") do
expect(page).to have_link("Terms of Use", href: terms_path)
expect(page).to have_link("Override", href: new_admin_page_path(slug: "terms"))
end
end
it "does not show any of the links in the pages table" do
within(".pages__table") do
expect(page).not_to have_content("Terms of Use")
expect(page).not_to have_content("Code of Conduct")
expect(page).not_to have_content("Privacy Policy")
end
end
it "has client-side validation" do
expect(page).to have_content("Test Page")
click_on("Edit")
fill_in "page_description", with: ""
click_on("Update Page")
expect(page).not_to have_current_path(admin_pages_path)
fill_in "page_description", with: "Walk without rhythm"
fill_in "page_slug", with: ""
click_on("Update Page")
expect(page).not_to have_current_path(admin_pages_path)
end
it "allows a page to be deleted" do
expect(page).to have_content("Test Page")
click_on("Edit")
expect(page).to have_selector("input[type=submit][value='Delete Page']")
click_on("Delete Page")
expect(page).to have_current_path(admin_pages_path)
expect(page).not_to have_content("Test Page")
end
end
describe "when the defaults are overridden" do
before do
create(:page,
slug: "code-of-conduct",
body_html: "<div>Code of Conduct</div>",
title: "Code of Conduct",
description: "A page that describes how to behave on this platform",
is_top_level_path: true)
create(:page,
slug: "privacy",
body_html: "<div>Privacy Policy</div>",
title: "Privacy Policy",
description: "A page that describes the privacy policy", is_top_level_path: true)
create(:page,
slug: "terms",
body_html: "<div>Terms of Use</div>",
title: "Terms of Use",
description: "A page that describes the terms of use for the application",
is_top_level_path: true)
sign_in admin
visit admin_pages_path
end
it "shows the notice that the defaults have been overriden" do
expect(page).to have_content("You will no longer receive updates on these pages from the Forem team")
end
it "shows the overriden pages in the pages table" do
within(".pages__table") do
expect(page).to have_content("Terms of Use")
expect(page).to have_content("Code of Conduct")
expect(page).to have_content("Privacy Policy")
end
end
end
describe "when there is a landing page" do
let(:current_landing_page) { create(:page, landing_page: true) }
let(:new_landing_page) { create(:page, landing_page: true) }
it "allows a landing page to be updated", :aggregate_failures do
visit edit_admin_page_path(current_landing_page.id)
expect(page).to have_content("Use as 'Locked Screen")
uncheck "Use as 'Locked Screen'"
click_on("Update Page")
expect(page).to have_current_path(admin_pages_path)
end
it "allows an Admin to click through to the current landing page via the modal", :aggregate_failures do
visit edit_admin_page_path(new_landing_page.id)
expect(page).to have_content("Use as 'Locked Screen")
check "Use as 'Locked Screen'"
expect(page).to have_link("Current Locked Screen: #{new_landing_page.title}")
click_on("Current Locked Screen")
expect(page).to have_current_path(new_landing_page.path)
expect(page).to have_content(new_landing_page.title)
end
it "allows an Admin to overwrite the current landing page via the checkbox and modal", :aggregate_failures do
visit edit_admin_page_path(new_landing_page.id)
expect(page).to have_content("Use as 'Locked Screen")
check "Use as 'Locked Screen'"
expect(page).to have_link("Current Locked Screen: #{new_landing_page.title}")
click_on("Overwrite current locked screen")
click_on("Update Page")
expect(page).to have_current_path(admin_pages_path)
end
end
end