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

Mobile gnav tests #3433

Merged
merged 5 commits into from
Jan 8, 2025
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
12 changes: 12 additions & 0 deletions test/blocks/global-navigation/global-navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,5 +750,17 @@ describe('global navigation', () => {
headline.click();
expect(headline.getAttribute('aria-expanded')).to.equal('true');
});

it('adds the correct class when on Safari', async () => {
Object.defineProperty(navigator, 'userAgent', { get: () => 'Safari' });
await createFullGlobalNavigation({ globalNavigation: gnavWithlocalNav, viewport: 'mobile' });
const localNavTitle = document.querySelector(selectors.localNavTitle);
localNavTitle.click();
const localNav = document.querySelector(selectors.localNav);
const curtain = localNav.querySelector('.feds-localnav-curtain');
expect(document.body.classList.contains('disable-ios-scroll')).to.equal(true);
curtain.click();
expect(document.body.classList.contains('disable-ios-scroll')).to.equal(false);
});
});
});
2 changes: 1 addition & 1 deletion test/blocks/global-navigation/gnav-promo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Promo', () => {
it('is available if set up correctly', async () => {
const promoMeta = toFragment`<meta name="gnav-promo-source" content="http://localhost:2000/fragments/correct-promo-fragment">`;
document.head.append(promoMeta);
const nav = await createFullGlobalNavigation({ hasPromo: true });
const nav = await createFullGlobalNavigation({ hasPromo: true, imsInitialized: true });
expect(nav.block.classList.contains('has-promo')).to.be.true;
const asideElem = nav.block.querySelector('.aside.promobar');
expect(asideElem).to.exist;
Expand Down
11 changes: 11 additions & 0 deletions test/blocks/global-navigation/keyboard/keyboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,17 @@ describe('keyboard navigation', () => {
const localnavTitle = document.querySelector('.feds-localnav-title');
expect(document.activeElement).to.equal(localnavTitle);
});
it('closes when escape is pressed', async () => {
await sendKeys({ press: 'Tab' });
await sendKeys({ press: 'Tab' });
await sendKeys({ press: 'Tab' });
await sendKeys({ press: 'Tab' });
await sendKeys({ press: 'Tab' });
await sendKeys({ press: 'Tab' });
await sendKeys({ press: 'Space' });
await sendKeys({ press: 'Escape' });
expect(document.querySelector('feds-localnav--active')).to.not.exist;
});
});
});
});
9 changes: 5 additions & 4 deletions test/blocks/global-navigation/test-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ export const createFullGlobalNavigation = async ({
hasPromo,
hasBreadcrumbs = true,
unavContent = null,
imsInitialized = false,
} = {}) => {
const clock = sinon.useFakeTimers({
// Intercept setTimeout and call the function immediately
toFake: ['setTimeout'],
});
const clock = sinon.useFakeTimers({ shouldAdvanceTime: true });
setConfig({ ...config, ...customConfig });
await setViewport(viewports[viewport]);
window.lana = { log: stub() };
Expand All @@ -198,6 +196,7 @@ export const createFullGlobalNavigation = async ({
return null;
});
window.adobeIMS = {
initialized: imsInitialized,
isSignedInUser: stub().returns(signedIn),
getAccessToken: stub().returns('mock-access-token'),
getProfile: stub().returns(
Expand Down Expand Up @@ -228,9 +227,11 @@ export const createFullGlobalNavigation = async ({
const instancePromise = initGnav(document.body.querySelector('header'));

await clock.runToLastAsync();
clock.tick(1000);
const instance = await instancePromise;
const imsPromise = instance.imsReady();
await clock.runToLastAsync();
clock.tick(1000);
// We restore the clock here, because waitForElement uses setTimeout
clock.restore();

Expand Down
Loading