Skip to content

Commit a619520

Browse files
SCAL-256912 added test to increase the coverage
1 parent 82d1efe commit a619520

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

src/embed/ts-embed.spec.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,3 +3849,85 @@ describe('Unit test case for ts embed', () => {
38493849
});
38503850
});
38513851
});
3852+
3853+
3854+
describe('Additional Coverage Tests', () => {
3855+
beforeAll(() => {
3856+
init({
3857+
thoughtSpotHost: 'tshost',
3858+
authType: AuthType.None,
3859+
});
3860+
});
3861+
3862+
test('should handle getAuthTokenForCookielessInit with non-cookieless auth', async () => {
3863+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
3864+
const token = await searchEmbed['getAuthTokenForCookielessInit']();
3865+
expect(token).toBe('');
3866+
});
3867+
3868+
test('should call setIFrameHeight', async () => {
3869+
// Test lines 1049-1051
3870+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
3871+
await searchEmbed.render();
3872+
await executeAfterWait(() => {
3873+
searchEmbed['setIFrameHeight'](500);
3874+
expect(getIFrameEl().style.height).toBe('500px');
3875+
});
3876+
});
3877+
3878+
test('should test getIframeCenter calculation', async () => {
3879+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
3880+
await searchEmbed.render();
3881+
await executeAfterWait(() => {
3882+
const center = searchEmbed['getIframeCenter']();
3883+
expect(center).toHaveProperty('iframeCenter');
3884+
expect(center).toHaveProperty('iframeHeight');
3885+
expect(center).toHaveProperty('viewPortHeight');
3886+
});
3887+
});
3888+
3889+
test('should handle preRender with replaceExistingPreRender=true', async () => {
3890+
createRootEleForEmbed();
3891+
const embed1 = new LiveboardEmbed('#tsEmbedDiv', {
3892+
preRenderId: 'test-replace',
3893+
liveboardId: 'lb1',
3894+
});
3895+
await embed1.preRender();
3896+
3897+
const embed2 = new LiveboardEmbed('#tsEmbedDiv', {
3898+
preRenderId: 'test-replace',
3899+
liveboardId: 'lb2',
3900+
});
3901+
await embed2.preRender(false, true); // replaceExistingPreRender = true
3902+
3903+
expect(document.getElementById('tsEmbed-pre-render-wrapper-test-replace')).toBeTruthy();
3904+
});
3905+
3906+
test('should test getIframeSrc base implementation', () => {
3907+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
3908+
expect(searchEmbed.getIframeSrc()).toBe('');
3909+
});
3910+
3911+
test('should handle createEmbedEventResponder with OnBeforeGetVizDataIntercept', async () => {
3912+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
3913+
const mockPort: any = { postMessage: jest.fn() };
3914+
3915+
const responder = searchEmbed['createEmbedEventResponder'](
3916+
mockPort,
3917+
EmbedEvent.OnBeforeGetVizDataIntercept,
3918+
);
3919+
3920+
responder({ data: 'test' });
3921+
expect(mockPort.postMessage).toHaveBeenCalled();
3922+
});
3923+
3924+
test('should clean up message event listeners', async () => {
3925+
const removeEventListenerSpy = jest.spyOn(window, 'removeEventListener');
3926+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
3927+
await searchEmbed.render();
3928+
3929+
searchEmbed['unsubscribeToMessageEvents']();
3930+
3931+
expect(removeEventListenerSpy).toHaveBeenCalledWith('message', expect.any(Function));
3932+
});
3933+
});

0 commit comments

Comments
 (0)