diff --git a/app/controllers/admin/navigation_links_controller.rb b/app/controllers/admin/navigation_links_controller.rb index 5d8d8fc7c..1ad7ed5d3 100644 --- a/app/controllers/admin/navigation_links_controller.rb +++ b/app/controllers/admin/navigation_links_controller.rb @@ -7,7 +7,8 @@ module Admin layout "admin" def index - @navigation_links = NavigationLink.ordered + @default_nav_links = NavigationLink.default_section.ordered + @other_nav_links = NavigationLink.other_section.ordered end def create diff --git a/app/views/admin/navigation_links/_form.html.erb b/app/views/admin/navigation_links/_form.html.erb index 1427a5ad6..3d5c09f03 100644 --- a/app/views/admin/navigation_links/_form.html.erb +++ b/app/views/admin/navigation_links/_form.html.erb @@ -24,6 +24,22 @@
+
+
+ Section +
+ + +
+
+
Determines which section the link will be displayed in
+
<%= form.label :position %> <%= form.number_field :position, class: "form-control" %> diff --git a/app/views/admin/navigation_links/index.html.erb b/app/views/admin/navigation_links/index.html.erb index 762192d4e..3936d59ea 100644 --- a/app/views/admin/navigation_links/index.html.erb +++ b/app/views/admin/navigation_links/index.html.erb @@ -2,26 +2,63 @@
Configure the left sidebar navigation links that appear at <%= app_url %> using the form below:
<%= render "add_navigation_link_modal" %> - <% @navigation_links.each do |link| %> -
-
<%= link[:position] %>
- + +
+

+ Other +

+
    + <% @other_nav_links.each_with_index do |link, index| %> +
  • +
    <%= link[:position] %>
    + + +
    +
    + <%= render partial: "edit_navigation_link_modal", locals: { link: link } %> +
    +
    + <%= link_to "Delete", admin_navigation_link_path(link), data: { confirm: "Are you sure?" }, method: :delete, class: "color-accent-danger" %> +
    +
    +
  • + <% end %> +
+
diff --git a/app/views/layouts/_main_nav.html.erb b/app/views/layouts/_main_nav.html.erb index ca3872a5a..4225dc200 100644 --- a/app/views/layouts/_main_nav.html.erb +++ b/app/views/layouts/_main_nav.html.erb @@ -1,32 +1,44 @@ -<% nav_links = NavigationLink.all.ordered.to_a %> +<% default_nav_links = NavigationLink.default_section.ordered.to_a %> +<% other_nav_links = NavigationLink.other_section.ordered.to_a %> - + +<% if other_nav_links.any? %> + +<% end %> + +
+ <%= render partial: "layouts/social_media" %> +
diff --git a/app/views/layouts/_sidebar_nav_link.html.erb b/app/views/layouts/_sidebar_nav_link.html.erb index d3996ad7e..0679be53e 100644 --- a/app/views/layouts/_sidebar_nav_link.html.erb +++ b/app/views/layouts/_sidebar_nav_link.html.erb @@ -1,11 +1,13 @@ <% if !link.display_only_when_signed_in || (link.display_only_when_signed_in && user_signed_in?) %> - - - <%= link.icon.html_safe %> - - <%= link.name %> - <% if link.url.include?("readinglist") %> - - <% end %> - +
  • + + + <%= link.icon.html_safe %> + + <%= link.name %> + <% if link.url.include?("readinglist") %> + + <% end %> + +
  • <% end %> diff --git a/cypress/integration/seededFlows/navigationFlows/homePageLeftSidebar.spec.js b/cypress/integration/seededFlows/navigationFlows/homePageLeftSidebar.spec.js deleted file mode 100644 index d05b6f0a9..000000000 --- a/cypress/integration/seededFlows/navigationFlows/homePageLeftSidebar.spec.js +++ /dev/null @@ -1,35 +0,0 @@ -describe('Home Page Left Sidebar', () => { - beforeEach(() => { - cy.testSetup(); - }); - - it('should open the "More" links', () => { - // Go to home page - cy.visit('/'); - - // Click on the More... button in the nav - cy.get('#page-content-inner').within(() => { - cy.findByRole('link', { name: 'More...' }) - .click() - .should('not.be.visible'); - cy.findByText('Nav link 5').should('be.visible'); - // visit another page with InstantClick - cy.findByText('Nav link 0').click(); - }); - - // go back to the homepage with InstantClick - cy.intercept('/?i=i').as('homepage'); - cy.findAllByRole('link', { name: 'DEV(local) Home' }).first().click(); - cy.wait('@homepage'); - - // Wait for home page to load - cy.findByRole('heading', { name: 'Posts' }); - // repeat and assert - cy.get('#page-content-inner').within(() => { - cy.findByRole('link', { name: 'More...' }) - .click() - .should('not.be.visible'); - cy.findByText('Nav link 5').should('be.visible'); - }); - }); -}); diff --git a/spec/system/homepage/user_visits_homepage_spec.rb b/spec/system/homepage/user_visits_homepage_spec.rb index 6832f5cf7..5a6e61132 100644 --- a/spec/system/homepage/user_visits_homepage_spec.rb +++ b/spec/system/homepage/user_visits_homepage_spec.rb @@ -41,19 +41,64 @@ RSpec.describe "User visits a homepage", type: :system do display_only_when_signed_in: true, position: 1) create(:navigation_link, + name: "Shop", + icon: "", + display_only_when_signed_in: false, + position: 2) + create(:navigation_link, + :other_section_link, name: "Podcasts", icon: "", display_only_when_signed_in: false, position: nil) + create(:navigation_link, + :other_section_link, + name: "Privacy Policy", + icon: "", + display_only_when_signed_in: false, + position: 1) + visit "/" end - it "shows the correct count of links" do - visit "/" - expect(page).to have_selector(".spec-sidebar-navigation-links", count: 2) - - within(".spec-sidebar-navigation-links", match: :first) do + it "shows expected number of links when signed out" do + within("nav[aria-labelledby='default-nav-heading']", match: :first) do expect(page).to have_selector(".sidebar-navigation-link", count: 1) end + + within("nav[aria-labelledby='other-nav-heading']", match: :first) do + expect(page).to have_selector(".sidebar-navigation-link", count: 2) + end + end + + it "shows the Other section when other nav links exist" do + within("nav[aria-labelledby='other-nav-heading']", match: :first) do + expect(page).to have_selector(".other-navigation-links") + end + + NavigationLink.other_section.destroy_all + visit "/" + + expect(page).not_to have_selector("nav[aria-labelledby='other-nav-heading']") + end + + it "hides link when display_only_when_signed_in is true" do + within("nav[aria-labelledby='default-nav-heading']", match: :first) do + expect(page).to have_selector(".default-navigation-links .sidebar-navigation-link", count: 1) + end + end + + it "shows links in their correct section and order" do + create(:navigation_link, + name: "Mock", + icon: "", + display_only_when_signed_in: false, + position: 3) + visit "/" + + within("nav[aria-labelledby='default-nav-heading']", match: :first) do + expect(page).to have_selector(".default-navigation-links li:nth-child(3)", text: "Shop") + expect(page).to have_selector(".default-navigation-links li:nth-child(4)", text: "Mock") + end end end end @@ -115,7 +160,7 @@ RSpec.describe "User visits a homepage", type: :system do end end - context "when rendering < 5 navigation links" do + describe "navigation_links" do let!(:navigation_link_1) do create(:navigation_link, name: "Reading List", @@ -126,6 +171,7 @@ RSpec.describe "User visits a homepage", type: :system do end let!(:navigation_link_2) do create(:navigation_link, + :other_section_link, name: "Podcasts", icon: "", display_only_when_signed_in: false, @@ -143,59 +189,37 @@ RSpec.describe "User visits a homepage", type: :system do visit "/" end - it "shows the correct count of links" do - within(".spec-sidebar-navigation-links", match: :first) do - expect(page).to have_selector(".sidebar-navigation-link", count: 3) - end - end - it "shows the correct navigation_links" do - within(".spec-sidebar-navigation-links", match: :first) do + within("nav[aria-labelledby='default-nav-heading']", match: :first) do expect(page).to have_text(navigation_link_1.name) - expect(page).to have_text(navigation_link_2.name) expect(page).to have_text(navigation_link_3.name) end + + within("nav[aria-labelledby='other-nav-heading']", match: :first) do + expect(page).to have_text(navigation_link_2.name) + end end it "shows the correct urls" do - within(".spec-sidebar-navigation-links", match: :first) do + within("nav[aria-labelledby='default-nav-heading']", match: :first) do expect(page).to have_link(href: navigation_link_1.url) - expect(page).to have_link(href: navigation_link_2.url) expect(page).to have_link(href: navigation_link_3.url) end - end - it "shows the correct order of the links" do - within(".spec-sidebar-navigation-links", match: :first) do - sidebar_navigation_link1 = page.find(".sidebar-navigation-link:nth-child(1)") - expect(sidebar_navigation_link1).to have_text(navigation_link_1.name) - - sidebar_navigation_link2 = page.find(".sidebar-navigation-link:nth-child(2)") - expect(sidebar_navigation_link2).to have_text(navigation_link_3.name) - - sidebar_navigation_link3 = page.find(".sidebar-navigation-link:nth-child(3)") - expect(sidebar_navigation_link3).to have_text(navigation_link_2.name) + within("nav[aria-labelledby='other-nav-heading']", match: :first) do + expect(page).to have_link(href: navigation_link_2.url) end end - it "shows the count when the url /readinglist is added" do - within(".spec-sidebar-navigation-links", match: :first) do - within(".sidebar-navigation-link:nth-child(1)") do - expect(page).to have_selector("#reading-list-count") - end + it "shows expected # of links when signed in" do + within("nav[aria-labelledby='default-nav-heading']", match: :first) do + expect(page).to have_selector(".sidebar-navigation-link", count: 2) # it's count: 1 when signed out end end - end - context "when rendering > 5 navigation links" do - before do - create_list(:navigation_link, 7) - end - - it "shows some in the 'More' section" do - visit "/" - within(".spec-nav-more", match: :first) do - expect(page).to have_selector(".sidebar-navigation-link", count: 2) + it "shows link when display_only_when_signed_in is true" do + within("nav[aria-labelledby='default-nav-heading']", match: :first) do + expect(page).to have_selector(".default-navigation-links li:nth-child(4)", text: "Beauty") end end end