Reinstate skip link on search page (#14463)
* reinstate skip link on search page * actually commit the tests this time * use optional chaining * Revert "use optional chaining" This reverts commit 921677f425c2e90f272a6e21dc8a8d37f916e0da.
This commit is contained in:
parent
9e6bf7f08f
commit
a884c56828
2 changed files with 26 additions and 12 deletions
|
|
@ -123,15 +123,10 @@ var instantClick
|
|||
prog.classList.remove("showing");
|
||||
|
||||
if (newUrl) {
|
||||
// We skip showing the "Skip to content" button for the search page, see
|
||||
// https://github.com/forem/forem/issues/13876
|
||||
var path = new URL(newUrl, window.location.origin).pathname;
|
||||
if (path != '/search') {
|
||||
const skipLink = document.querySelector('.skip-content-link');
|
||||
const skipLink = document.querySelector('.skip-content-link');
|
||||
if (skipLink) {
|
||||
skipLink.focus();
|
||||
}
|
||||
}
|
||||
document.getElementById('page-route-change').textContent = title;
|
||||
history.pushState(null, null, newUrl.replace("?samepage=true","").replace("&samepage=true",""))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,33 @@
|
|||
// Regression test for https://github.com/forem/forem/issues/13876
|
||||
describe('Search on homepage', () => {
|
||||
it('Does not show the "Skip to content" link', () => {
|
||||
beforeEach(() => {
|
||||
cy.testSetup();
|
||||
cy.visit('/');
|
||||
});
|
||||
|
||||
cy.get('#header-search')
|
||||
.get('form')
|
||||
.findByPlaceholderText('Search...')
|
||||
it('Does not show the "Skip to content" link if button is pressed', () => {
|
||||
cy.findByRole('search')
|
||||
.findByLabelText('Search term')
|
||||
.type('admin mcadmin');
|
||||
|
||||
cy.findByRole('button', { name: 'Search' }).click();
|
||||
|
||||
cy.url().should('include', '/search');
|
||||
|
||||
// Make sure the page has loaded before assertion
|
||||
cy.findByRole('heading', { name: 'Test article' });
|
||||
cy.get('.skip-content-link').should('not.be.visible');
|
||||
});
|
||||
|
||||
it('Shows "Skip to content" if search is submitted by Enter press', () => {
|
||||
cy.findByRole('search')
|
||||
.findByLabelText('Search term')
|
||||
.type('admin mcadmin{enter}');
|
||||
|
||||
cy.url().should('include', '/search');
|
||||
cy.get('.skip-content-link').should('not.be.visible');
|
||||
// Make sure the page has loaded before assertion
|
||||
cy.findByRole('heading', { name: 'Test article' });
|
||||
|
||||
cy.get('.skip-content-link').should('be.visible');
|
||||
cy.get('.skip-content-link').should('have.focus');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue