From f2284390dbd6c50a52001cc17709a526a8532a62 Mon Sep 17 00:00:00 2001 From: Okan Sahin <39759830+mokimo@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:22:15 +0200 Subject: [PATCH] Ability to configure Google YOLO on desktop, mobile and both (#1392) --- libs/scripts/delayed.js | 5 +- .../google-login/google-login.test.js | 66 ++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/libs/scripts/delayed.js b/libs/scripts/delayed.js index b594d22ca6..81ef7a6614 100644 --- a/libs/scripts/delayed.js +++ b/libs/scripts/delayed.js @@ -51,7 +51,10 @@ export const loadPrivacy = async (getConfig, loadScript) => { export const loadGoogleLogin = async (getMetadata, loadIms, loadScript) => { const googleLogin = getMetadata('google-login')?.toLowerCase(); - if (googleLogin !== 'on' || window.adobeIMS?.isSignedInUser()) return; + if (window.adobeIMS?.isSignedInUser() || !['mobile', 'desktop', 'on'].includes(googleLogin)) return; + const desktopViewport = window.matchMedia('(min-width: 900px)').matches; + if (googleLogin === 'mobile' && desktopViewport) return; + if (googleLogin === 'desktop' && !desktopViewport) return; const { default: initGoogleLogin } = await import('../features/google-login.js'); initGoogleLogin(loadIms, getMetadata, loadScript); diff --git a/test/features/google-login/google-login.test.js b/test/features/google-login/google-login.test.js index bcf63d7499..f2a22c6ba3 100644 --- a/test/features/google-login/google-login.test.js +++ b/test/features/google-login/google-login.test.js @@ -1,12 +1,15 @@ import sinon from 'sinon'; import { expect } from '@esm-bundle/chai'; -import { readFile } from '@web/test-runner-commands'; +import { readFile, setViewport } from '@web/test-runner-commands'; import initGoogleLogin from '../../../libs/features/google-login.js'; +import { viewports } from '../../blocks/global-navigation/test-utilities.js'; describe('Google Login', () => { let initializeSpy; let promptSpy; + let clock; beforeEach(async () => { + clock = sinon.useFakeTimers(); document.body.innerHTML = await readFile({ path: './mocks/google-login.html' }); window.google = window.google || { accounts: { @@ -30,6 +33,7 @@ describe('Google Login', () => { promptSpy.restore(); delete window.adobeid; delete window.google; + clock.restore(); }); it('should create a placeholder to inject DOM markup', async () => { @@ -83,4 +87,64 @@ describe('Google Login', () => { expect(document.getElementById('feds-googleLogin')).not.to.exist; loggedInStub.restore(); }); + + describe('desktop', () => { + before(async () => { + await setViewport(viewports.desktop); + }); + + it('should load yolo metadata set to "desktop"', async () => { + const { loadGoogleLogin } = await import('../../../libs/scripts/delayed.js'); + loadGoogleLogin(sinon.stub().returns('desktop'), sinon.stub(), sinon.stub()); + await clock.runAllAsync(); + expect(initializeSpy.called).to.be.true; + }); + + it('should not load yolo with metadata set to "mobile"', async () => { + const { loadGoogleLogin } = await import('../../../libs/scripts/delayed.js'); + loadGoogleLogin(sinon.stub().returns('mobile'), sinon.stub(), sinon.stub()); + await clock.runAllAsync(); + expect(initializeSpy.called).to.be.false; + }); + }); + + describe('tablet', () => { + before(async () => { + await setViewport(viewports.smallDesktop); + }); + + it('should load yolo with metadata set to "desktop"', async () => { + const { loadGoogleLogin } = await import('../../../libs/scripts/delayed.js'); + loadGoogleLogin(sinon.stub().returns('desktop'), sinon.stub(), sinon.stub()); + await clock.runAllAsync(); + expect(initializeSpy.called).to.be.true; + }); + + it('should not load yolo with metadata set to "mobile"', async () => { + const { loadGoogleLogin } = await import('../../../libs/scripts/delayed.js'); + loadGoogleLogin(sinon.stub().returns('mobile'), sinon.stub(), sinon.stub()); + await clock.runAllAsync(); + expect(initializeSpy.called).to.be.false; + }); + }); + + describe('mobile', () => { + before(async () => { + await setViewport(viewports.mobile); + }); + + it('should load yolo metadata set to "mobile"', async () => { + const { loadGoogleLogin } = await import('../../../libs/scripts/delayed.js'); + loadGoogleLogin(sinon.stub().returns('mobile'), sinon.stub(), sinon.stub()); + await clock.runAllAsync(); + expect(initializeSpy.called).to.be.true; + }); + + it('should not load yolo with metadata set to "desktop"', async () => { + const { loadGoogleLogin } = await import('../../../libs/scripts/delayed.js'); + loadGoogleLogin(sinon.stub().returns('desktop'), sinon.stub(), sinon.stub()); + await clock.runAllAsync(); + expect(initializeSpy.called).to.be.false; + }); + }); });