Skip to content

Commit

Permalink
Ability to configure Google YOLO on desktop, mobile and both (#1392)
Browse files Browse the repository at this point in the history
  • Loading branch information
mokimo authored Oct 17, 2023
1 parent 0cfd668 commit f228439
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
5 changes: 4 additions & 1 deletion libs/scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
66 changes: 65 additions & 1 deletion test/features/google-login/google-login.test.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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;
});
});
});

0 comments on commit f228439

Please sign in to comment.