Skip to content

Commit

Permalink
Add fullScreen prop (#44)
Browse files Browse the repository at this point in the history
* fullScreen prop

* tests

* tests

* add tests

Co-authored-by: Steve Mask <[email protected]>
  • Loading branch information
mnicpt and Steve Mask authored Mar 10, 2022
1 parent 2f5d5f8 commit b64e595
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 21 deletions.
12 changes: 12 additions & 0 deletions src/overlay/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,24 @@ export function getContainerStyle({ uid } : {| uid : string |}) : string {
max-width: 95vw;
}
#${ uid }.paypal-overlay-context-${ CONTEXT.IFRAME } .paypal-checkout-iframe-container-full,
#${ uid }.paypal-overlay-context-${ CONTEXT.IFRAME } .paypal-checkout-iframe-container-full > .${ CLASS.OUTLET },
#${ uid }.paypal-overlay-context-${ CONTEXT.IFRAME } .paypal-checkout-iframe-container-full > .${ CLASS.OUTLET } > iframe {
height: 100vh;
width: 100vw;
}
@media screen and (max-width: 470px) {
#${ uid }.paypal-overlay-context-${ CONTEXT.IFRAME } .paypal-checkout-iframe-container,
#${ uid }.paypal-overlay-context-${ CONTEXT.IFRAME } .paypal-checkout-iframe-container > .${ CLASS.OUTLET },
#${ uid }.paypal-overlay-context-${ CONTEXT.IFRAME } .paypal-checkout-iframe-container > .${ CLASS.OUTLET } > iframe {
max-height: 85vh;
}
#${ uid }.paypal-overlay-context-${ CONTEXT.IFRAME } .paypal-checkout-iframe-container-full,
#${ uid }.paypal-overlay-context-${ CONTEXT.IFRAME } .paypal-checkout-iframe-container-full > .${ CLASS.OUTLET },
#${ uid }.paypal-overlay-context-${ CONTEXT.IFRAME } .paypal-checkout-iframe-container-full > .${ CLASS.OUTLET } > iframe {
height: 100vh;
}
}
#${ uid }.paypal-overlay-context-${ CONTEXT.IFRAME } .paypal-checkout-iframe-container {
Expand Down
43 changes: 22 additions & 21 deletions src/overlay/template.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ export type OverlayProps = {|
|},
autoResize? : boolean,
hideCloseButton? : boolean,
nonce : string
nonce : string,
fullScreen? : boolean
|};

export function Overlay({ context, close, focus, event, frame, prerenderFrame, content = {}, autoResize, hideCloseButton, nonce } : OverlayProps) : ElementNode {
export function Overlay({ context, close, focus, event, frame, prerenderFrame, content = {}, autoResize, hideCloseButton, nonce, fullScreen = false } : OverlayProps) : ElementNode {
const uid = `paypal-overlay-${ uniqueID() }`;

function closeCheckout(e) {
Expand Down Expand Up @@ -119,25 +120,25 @@ export function Overlay({ context, close, focus, event, frame, prerenderFrame, c
<body>
<div id={ uid } onClick={ focusCheckout } class={ `paypal-overlay-context-${ context } paypal-checkout-overlay` }>
{ !hideCloseButton && <a href='#' class="paypal-checkout-close" onClick={ closeCheckout } aria-label="close" role="button" /> }
<div class="paypal-checkout-modal">
<div class="paypal-checkout-logo">
<PPLogo logoColor={ LOGO_COLOR.WHITE } />
<PayPalLogo logoColor={ LOGO_COLOR.WHITE } />
</div>
{content.windowMessage &&
<div class="paypal-checkout-message">
{content.windowMessage}
</div>}
{content.continueMessage &&
<div class="paypal-checkout-continue">
<a onClick={ focus } href='#'>{content.continueMessage}</a>
</div>}
<div class="paypal-checkout-loader">
<div class="paypal-spinner" />
</div>
</div>

<div class="paypal-checkout-iframe-container">
{ !fullScreen &&
<div class="paypal-checkout-modal">
<div class="paypal-checkout-logo">
<PPLogo logoColor={ LOGO_COLOR.WHITE } />
<PayPalLogo logoColor={ LOGO_COLOR.WHITE } />
</div>
{content.windowMessage &&
<div class="paypal-checkout-message">
{content.windowMessage}
</div>}
{content.continueMessage &&
<div class="paypal-checkout-continue">
<a onClick={ focus } href='#'>{content.continueMessage}</a>
</div>}
<div class="paypal-checkout-loader">
<div class="paypal-spinner" />
</div>
</div>}
<div class={ fullScreen ? 'paypal-checkout-iframe-container-full' : 'paypal-checkout-iframe-container' }>
{ outlet }
</div>

Expand Down
1 change: 1 addition & 0 deletions test/integration/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

import './three-domain-secure';
import './spinner-page';
import './overlay';
import './post-robot';
147 changes: 147 additions & 0 deletions test/integration/tests/overlay/happy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/* @flow */
/** @jsx node */

import { node, dom } from 'jsx-pragmatic/src';
import { ZalgoPromise } from 'zalgo-promise/src';

import { Overlay } from '../../../../src/overlay';

describe(`paypal overlay component happy path`, () => {
const cancel = () => undefined;

let context = 'popup';
let focussed;

const close = () => ZalgoPromise.resolve();
const focus = () => {
focussed = true;
return ZalgoPromise.resolve();
};
const event = {
on: () => ({ cancel }),
once: () => ({ cancel }),
reset: () => undefined,
trigger: () => ZalgoPromise.resolve(),
triggerOnce: () => ZalgoPromise.resolve()
};
const frame = null;
const prerenderFrame = null;
const content = {
windowMessage: 'window message',
continueMessage: 'continue message'
};
const autoResize = true;
let hideCloseButton = false;
const nonce = 'abc123';
let fullScreen = false;

const getOverlay = () =>
(<Overlay
context={ context }
content={ content }
close={ close }
focus={ focus }
event={ event }
frame={ frame }
prerenderFrame={ prerenderFrame }
autoResize={ autoResize }
hideCloseButton={ hideCloseButton }
nonce={ nonce }
fullScreen={ fullScreen }
/>);

const addOverlayToDOM = (child) => {
// $FlowFixMe
document.body.appendChild(child);
};

const getOverlayContainer = (domNode) => {
// $FlowFixMe
return domNode.querySelector('iframe').contentWindow.document;
};

beforeEach(() => {
// $FlowFixMe
document.body.innerHTML = '';
});

it('should render the overlay component', () => {
const domNode = getOverlay().render(dom());

if (domNode.ownerDocument !== document) {
throw new Error(`Expected overlay component to be rendered to current dom`);
}
});

it('should render the overlay component with popup', () => {
context = 'popup';

const domNode = getOverlay().render(dom());
addOverlayToDOM(domNode);

if (!getOverlayContainer(domNode).querySelector('.paypal-overlay-context-popup')) {
throw new Error(`Expected overlay to have popup`);
}
});

it('should render the overlay component with iframe', () => {
context = 'iframe';

const domNode = getOverlay().render(dom());
addOverlayToDOM(domNode);

if (!getOverlayContainer(domNode).querySelector('.paypal-overlay-context-iframe')) {
throw new Error(`Expected overlay to have iframe`);
}

context = 'popup'; // reset
});

it('should render the overlay component fullscreen', () => {
fullScreen = true;

const domNode = getOverlay().render(dom());
addOverlayToDOM(domNode);

if (!getOverlayContainer(domNode).querySelector('.paypal-checkout-iframe-container-full')) {
throw new Error(`Expected overlay to be full screen`);
}
});

it('should hide the overlay close button', () => {
hideCloseButton = true;

const domNode = getOverlay().render(dom());
addOverlayToDOM(domNode);

if (getOverlayContainer(domNode).querySelector('.paypal-checkout-close')) {
throw new Error(`Expected close button to be hidden`);
}

hideCloseButton = false; // reset
});

it('should be able to close the overlay using close button', () => {
const domNode = getOverlay().render(dom());
addOverlayToDOM(domNode);

getOverlayContainer(domNode).querySelector('.paypal-checkout-close').click();

if (getOverlayContainer(domNode).querySelector('.paypal-checkout-sandbox')) {
throw new Error(`Expected overlay to be removed after closing`);
}
});

it('should be able to focus on the overlay by clicking on it', () => {
const domNode = getOverlay().render(dom());
addOverlayToDOM(domNode);

getOverlayContainer(domNode).querySelector('.paypal-checkout-overlay').click();

if (!focussed) {
throw new Error(`Expected overlay to be focussed after clicking on it`);
}

focussed = null; // reset
});
});
3 changes: 3 additions & 0 deletions test/integration/tests/overlay/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* @flow */

import './happy';

0 comments on commit b64e595

Please sign in to comment.