From 57901e9872b9f882a9b016188f2979894dc2363d Mon Sep 17 00:00:00 2001 From: baljesingh <109554253+baljesingh@users.noreply.github.com> Date: Thu, 5 Dec 2024 10:47:27 -0800 Subject: [PATCH] Add custom child iframe in teams test app for nested app auth e2e tests (#2649) * Add custom child iframe in teams test app for E2E tests * Update as per reviewer's feedback --- .../src/components/NestedAppAuthAPIs.tsx | 51 ++-- .../src/public/naa_childIframe.html | 230 ++++++++++++++++++ 2 files changed, 264 insertions(+), 17 deletions(-) create mode 100644 apps/teams-test-app/src/public/naa_childIframe.html diff --git a/apps/teams-test-app/src/components/NestedAppAuthAPIs.tsx b/apps/teams-test-app/src/components/NestedAppAuthAPIs.tsx index 60c594165f..3da60ee05a 100644 --- a/apps/teams-test-app/src/components/NestedAppAuthAPIs.tsx +++ b/apps/teams-test-app/src/components/NestedAppAuthAPIs.tsx @@ -152,36 +152,58 @@ const NestedAppAuthAPIs = (): ReactElement => { }), }); - const AddChildIframeSection = (): React.ReactElement | null => { + const AddChildIframeSection = (): React.ReactElement => { const [iframeAdded, setIframeAdded] = useState(false); const addChildIframe = (): void => { if (iframeAdded) { - console.log('Iframe already added.'); return; } const iframeContainer = document.getElementById('nestedChildIframeContainer'); if (!iframeContainer) { - console.error('Container not found: nestedChildIframeContainer'); + console.error('Iframe container not found'); return; } const childIframe = document.createElement('iframe'); - childIframe.src = `${window.location.href}?appInitializationTest=true&groupedMode=NestedAppAuthAPIs`; + childIframe.src = '/naa_childIframe.html'; childIframe.id = 'nestedAuthChildIframe'; - childIframe.width = '100%'; - childIframe.height = '400px'; + childIframe.style.width = '100%'; + childIframe.style.height = '400px'; childIframe.style.border = 'none'; iframeContainer.appendChild(childIframe); setIframeAdded(true); + + // Send payload to the iframe after it loads + childIframe.onload = () => { + const payloads = { + defaultPayloadForBridge: NestedAppAuthRequest, + defaultPayloadForTopWindow: JSON.stringify({ + id: '2', + func: 'nestedAppAuth.execute', + args: [], + data: NestedAppAuthRequest, + }), + }; + childIframe.contentWindow?.postMessage(payloads, window.location.origin); + }; }; return ( -
-

Add Nested Child Iframe

+
+

Child Iframe

{
+ />
); }; - return ( diff --git a/apps/teams-test-app/src/public/naa_childIframe.html b/apps/teams-test-app/src/public/naa_childIframe.html new file mode 100644 index 0000000000..30b44abd50 --- /dev/null +++ b/apps/teams-test-app/src/public/naa_childIframe.html @@ -0,0 +1,230 @@ + + + + + + Nested Child Iframe Content + + + +
+
+

NestedAppAuthBridge

+
+ + +
+ +
No response yet
+
+ +
+

Top Window

+
+ + +
+ +
No response yet
+
+
+ + + +