Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dm 3592 anchor tags #542

Merged
merged 12 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/assets/javascripts/_page_show.es6
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,27 @@ const COMPONENT_CLASSES = [
});
}

function chromeWorkaroundForAnchorTags(){
var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
if (window.location.hash && isChrome) {
setTimeout(function () {
var hash = window.location.hash;
window.location.hash = "";
window.location.hash = hash;
}, 300);
}
}



function execPageBuilderFunctions() {
browsePageBuilderPageHappy();
removeBottomMarginFromLastAccordionHeading();
containerizeSubpageHyperlinkCards();
remediateInternalLinksTarget();
identifyExternalLinks();
chromeWorkaroundForAnchorTags();
}

$document.on('turbolinks:load', execPageBuilderFunctions);
})(window.jQuery);

})(window.jQuery);
6 changes: 3 additions & 3 deletions app/views/page/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
<%= javascript_include_tag 'ie', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag '_page_show', 'data-turbolinks-track': 'reload' %>
<% end %>

<% accordion_ctr = 0 %>
<% page_narrow_classes = 'desktop:grid-col-8 margin-x-auto' if @page.narrow? %>

<div id="page-builder-page" class="margin-top-5">
<section class="grid-container">
<div class="dm-page-content">
Expand Down Expand Up @@ -56,7 +55,8 @@

<%# Accordion %>
<% when 'PageAccordionComponent' %>
<div class="page-accordion-component <%= page_narrow_classes %> margin-bottom-3<%= ' margin-bottom-0' if last_component === index %>">
<% accordion_ctr += 1 %>
<div id="accordion_anchor_<%= accordion_ctr %>" class="page-accordion-component <%= page_narrow_classes %> margin-bottom-3<%= ' margin-bottom-0' if last_component === index %>">
<div class="usa-accordion">
<h2 class="usa-accordion__heading margin-bottom-2">
<button class="usa-accordion__button font-sans-sm"
Expand Down
13 changes: 13 additions & 0 deletions spec/features/pages/show_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
downloadable_file_component = PageDownloadableFileComponent.create(attachment: downloadable_file, description: 'Test file')
paragraph_component = PageParagraphComponent.create(text: "<div><p><a href='https://marketplace.va.gov/about'>about the marketplace</a></p><p><a href='https://wikipedia.org/'>an external link</a></p></div>")
legacy_paragraph_component = PageParagraphComponent.create(text: "<div><p><a href='../../about' target='_blank'>relative internal link with dot</a></p><p><a href='/about' target='_blank'>relative internal link with slash</a></p><p><a href='https://marketplace.va.gov/' target='_blank'>absolute internal link</a></p></div>")
accordion_component = PageAccordionComponent.create(title: 'FAQ 1', text: 'FAQ 1 text')
accordion_component_2 = PageAccordionComponent.create(title: 'FAQ 2', text: 'FAQ 2 text')

PageComponent.create(page: @page, component: practice_list_component, created_at: Time.now)
PageComponent.create(page: @page, component: subpage_hyperlink_component, created_at: Time.now)
PageComponent.create(page: @page, component: image_component, created_at: Time.now)
Expand All @@ -48,6 +51,9 @@
PageComponent.create(page: @page, component: downloadable_file_component, created_at: Time.now)
PageComponent.create(page: @page, component: paragraph_component, created_at: Time.now)
PageComponent.create(page: @page, component: legacy_paragraph_component, created_at: Time.now)
PageComponent.create(page: @page, component: accordion_component, created_at: Time.now)
PageComponent.create(page: @page, component: accordion_component_2, created_at: Time.now)

# must be logged in to view pages
login_as(user, scope: :user, run_callbacks: false)
visit '/programming/ruby-rocks'
Expand Down Expand Up @@ -88,6 +94,13 @@
expect(page).to have_content('It is pretty cool too')
end

it 'Should display the accordion component' do
expect(page).to have_content('FAQ 1')
expect(page).to have_css('#accordion_anchor_1')
expect(page).to have_content('FAQ 2')
expect(page).to have_css('#accordion_anchor_2')
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test that checks to make sure that when the anchor link name is added to the url, the page jumps to the correct top position?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked in to this... and found https://stackoverflow.com/questions/18948687/capybara-how-to-test-link-to-different-section-of-same-page .. so not sure if this is possible.

it 'Should display the page image' do
expect(page).to have_css("img[src*='charmander.png']")
expect(page).to have_css('.flex-justify-end')
Expand Down