Skip to content

Commit

Permalink
added a listener for testing host to test manual initialization on te…
Browse files Browse the repository at this point in the history
…st app (#2544)

* added listener for test host to test manual initialization

* update

* Resolve some comments
  • Loading branch information
KangxuanYe authored Oct 16, 2024
1 parent 4e7dee4 commit 4442e1b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions apps/teams-test-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if (
(urlParams.has('customInit') && urlParams.get('customInit')) ||
(urlParams.has(appInitializationTestQueryParameter) && urlParams.get(appInitializationTestQueryParameter))
) {
window.addEventListener('message', handleMessageFromMockedHost);
console.info('Not calling appInitialization because part of App Initialization Test run');
} else {
if (isTestBackCompat()) {
Expand All @@ -42,6 +43,35 @@ if (
}
}

function handleMessageFromMockedHost(msg: MessageEvent): void {
if (!msg.data) {
console.warn('Unrecognized message format received by app, message being ignored. Message: %o', msg);
return;
}
console.log(`Received message from test host: ${msg.data}`);
// Handle messages that are correctly formatted and for func values we recognize
switch (msg.data) {
case 'app.initialize':
app.initialize();
break;
case 'app.notifySuccess':
app.notifySuccess();
break;
case 'app.notifyFailure':
app.notifyFailure({ reason: app.FailedReason.Other, message: 'Failed on test app on purpose' });
break;
case 'app.notifyExpectedFailure':
app.notifyExpectedFailure({ reason: app.ExpectedFailureReason.Other, message: 'Failed on test app on purpose' });
break;
case 'app.notifyAppLoaded':
app.notifyAppLoaded();
break;
// Add more cases for other API calls as needed
default:
console.warn('Unknown API call or response:', msg);
}
}

export const noHostSdkMsg = ' was called, but there was no response from the Host SDK.';

/**
Expand Down

0 comments on commit 4442e1b

Please sign in to comment.