Skip to content

Commit 720da9d

Browse files
Reload global function
1 parent debcb9b commit 720da9d

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

src/embed/base.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import * as index from '../index';
1010
import * as base from './base';
1111
import * as embedConfigInstance from './embedConfig';
1212
import * as resetService from '../utils/resetServices';
13+
import * as processTrigger from '../utils/processTrigger';
14+
import { reloadIframe } from './base';
1315

1416
import {
1517
executeAfterWait,
@@ -128,6 +130,32 @@ describe('Base TS Embed', () => {
128130
);
129131
});
130132

133+
test('should call reload with the provided iframe', () => {
134+
// Arrange
135+
const iFrameElement = document.createElement('iframe');
136+
const html = '<body>Foo</body>';
137+
iFrameElement.src = `data:text/html;charset=utf-8,${encodeURI(html)}`;
138+
const spyReload = jest.spyOn(processTrigger, 'reload');
139+
140+
// Act
141+
reloadIframe(iFrameElement);
142+
143+
// Assert
144+
expect(spyReload).toHaveBeenCalledWith(iFrameElement);
145+
});
146+
147+
test('should warn when called without an iframe element', () => {
148+
// Arrange
149+
const warnSpy = jest.spyOn(logger, 'warn').mockImplementation(() => {});
150+
151+
// Act
152+
(reloadIframe as any)(undefined);
153+
154+
// Assert
155+
expect(warnSpy).toHaveBeenCalledWith('reloadIframe called with no iFrame element.');
156+
});
157+
158+
131159
test('should call the executeTML API and import TML for cookiless auth', async () => {
132160
jest.spyOn(authTokenService, 'getAuthenticationToken').mockResolvedValue('mockAuthToken');
133161
jest.spyOn(tokenizedFetchInstance, 'tokenizedFetch').mockResolvedValueOnce({

src/embed/base.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { uploadMixpanelEvent, MIXPANEL_EVENT } from '../mixpanel-service';
3535
import { getEmbedConfig, setEmbedConfig } from './embedConfig';
3636
import { getQueryParamString, getValueFromWindow, storeValueInWindow } from '../utils';
3737
import { resetAllCachedServices } from '../utils/resetServices';
38+
import { reload } from '../utils/processTrigger';
3839

3940
const CONFIG_DEFAULTS: Partial<EmbedConfig> = {
4041
loginFailedMessage: 'Not logged in',
@@ -459,3 +460,17 @@ export function reset(): void {
459460
setAuthEE(null);
460461
authPromise = null;
461462
}
463+
464+
/**
465+
* Reloads the ThoughtSpot iframe.
466+
* @param iFrame
467+
* @group Global methods
468+
* @version SDK: 1.43.1
469+
*/
470+
export const reloadIframe = (iFrame: HTMLIFrameElement) => {
471+
if (!iFrame) {
472+
logger.warn('reloadIframe called with no iFrame element.');
473+
return;
474+
}
475+
reload(iFrame);
476+
};

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
exportTML,
2727
executeTMLInput,
2828
exportTMLInput,
29+
reloadIframe,
2930
} from './embed/base';
3031
import { PinboardEmbed, LiveboardViewConfig, LiveboardEmbed } from './embed/liveboard';
3132
import { SearchEmbed, SearchViewConfig } from './embed/search';
@@ -83,6 +84,7 @@ export {
8384
executeTML,
8485
exportTML,
8586
executeTMLInput,
87+
reloadIframe,
8688
exportTMLInput,
8789
getEmbedConfig as getInitConfig,
8890
getSessionInfo,

src/react/all-types-export.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export {
2222
init,
2323
logout,
2424
prefetch,
25+
reloadIframe,
2526
getInitConfig,
2627
getSessionInfo,
2728
uploadMixpanelEvent,

0 commit comments

Comments
 (0)