Skip to content

Commit cbdb831

Browse files
authored
Add ability to load test app in its own iframe for testappception (#2512)
* Button to create iframe * use types * initialization parameter
1 parent e707dba commit cbdb831

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

apps/teams-test-app/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { BrowserRouter, Route, Routes } from 'react-router-dom';
66

77
import { isTestBackCompat } from './components/utils/isTestBackCompat';
88
import { SecondRoute } from './pages/SecondRoute';
9-
import { TestApp } from './pages/TestApp';
9+
import { appInitializationTestQueryParameter, TestApp } from './pages/TestApp';
1010

1111
const urlParams = new URLSearchParams(window.location.search);
1212

@@ -29,7 +29,7 @@ if (!urlParams.has('customInit') || !urlParams.get('customInit')) {
2929
// we do it by adding appInitializationTest=true to query string
3030
if (
3131
(urlParams.has('customInit') && urlParams.get('customInit')) ||
32-
(urlParams.has('appInitializationTest') && urlParams.get('appInitializationTest'))
32+
(urlParams.has(appInitializationTestQueryParameter) && urlParams.get(appInitializationTestQueryParameter))
3333
) {
3434
console.info('Not calling appInitialization because part of App Initialization Test run');
3535
} else {

apps/teams-test-app/src/pages/TestApp.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,32 @@ import VideoAPIs from '../components/VideoEffectsApis';
6666
import VisualMediaAPIs from '../components/VisualMediaAPIs';
6767
import WebStorageAPIs from '../components/WebStorageAPIs';
6868

69+
export const appInitializationTestQueryParameter = 'appInitializationTest';
70+
6971
export const TestApp: React.FC = () => {
7072
const dialogWindowRef = React.useRef<IAppWindow | null>(null);
73+
const [iframeUrl, setIframeUrl] = React.useState<URL | null>(null);
74+
75+
const loadCurrentUrl = (): void => {
76+
setIframeUrl(new URL(window.location.href + `?${appInitializationTestQueryParameter}=true`));
77+
};
7178

7279
return (
7380
<>
7481
<button id="button_reload" onClick={() => window.location.reload()}>
7582
Reload This App
7683
</button>
84+
<button id="button_iframe" onClick={loadCurrentUrl}>
85+
Load Current URL in child Iframe for initialization testing
86+
</button>
7787
<div className="App-container">
88+
{iframeUrl !== null && (
89+
<div>
90+
IFRAME: <br></br>
91+
{/*eslint-disable-next-line @microsoft/sdl/react-iframe-missing-sandbox -- always use the sandbox attribute, but this is a test app and we fully control the content going into it, so it's okay not to here. */}
92+
<iframe src={iframeUrl.toString()} width="100%" height="500px" />
93+
</div>
94+
)}
7895
<AppAPIs />
7996
<AppInitializationAPIs />
8097
<AppInstallDialogAPIs />

0 commit comments

Comments
 (0)