• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thoughtspot / visual-embed-sdk / #1933

06 Jun 2025 01:26PM UTC coverage: 93.519% (-0.3%) from 93.827%
#1933

Pull #215

yinstardev
logger test failure
Pull Request #215: SCAL-256749 present-event

1096 of 1250 branches covered (87.68%)

Branch coverage included in aggregate %.

22 of 25 new or added lines in 3 files covered. (88.0%)

15 existing lines in 3 files now uncovered.

2656 of 2762 relevant lines covered (96.16%)

67.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.76
/src/utils/processData.ts
1
import { getEmbedConfig } from '../embed/embedConfig';
15✔
2
import {
15✔
3
    disableAutoLogin,
4
    notifyAuthFailure,
5
    notifyAuthSuccess,
6
    notifyLogout,
7
} from '../embed/base';
8
import { AuthFailureType } from '../auth';
15✔
9
import { AuthType, CustomActionPayload, EmbedEvent } from '../types';
15✔
10
import { AnswerService } from './graphql/answerService/answerService';
15✔
11
import { resetCachedAuthToken } from '../authToken';
15✔
12
import { ERROR_MESSAGE } from '../errors';
15✔
13
import { logger } from '../utils/logger';
14

15✔
15
/**
16
 * Default handler for exitPresentMode event - exits fullscreen
17
 */
18
function handleExitPresentMode(): void {
19
    const isInFullscreen = !!(
20
        document.fullscreenElement ||
NEW
21
        (document as any).webkitFullscreenElement ||
×
NEW
22
        (document as any).mozFullScreenElement ||
×
23
        (document as any).msFullscreenElement
24
    );
25

26
    if (!isInFullscreen) {
27
        // Document is not in fullscreen, nothing to do
28
        return;
29
    }
30

15✔
31
    // Trying to exit fullscreen with vendor prefixes
6✔
32
    const exitFullscreenMethods = [
6✔
33
        'exitFullscreen',
34
        'webkitExitFullscreen',
12✔
35
        'mozCancelFullScreen', 
36
        'msExitFullscreen'
18✔
37
    ];
38

6✔
39
    let fullscreenExited = false;
40
    
41
    for (const method of exitFullscreenMethods) {
42
        if (typeof (document as any)[method] === 'function') {
43
            try {
44
                const result = (document as any)[method]();
45
                // Handle promise-based methods
46
                if (result && typeof result.catch === 'function') {
47
                    result.catch((error: any) => {
48
                        logger.warn(`Failed to exit fullscreen using ${method}:`, error);
49
                    });
50
                }
2✔
51
                fullscreenExited = true;
52
                break;
53
            } catch (error) {
2✔
54
                logger.warn(`Failed to exit fullscreen using ${method}:`, error);
55
            }
56
        }
8!
57
    }
58

59
    if (!fullscreenExited) {
60
        logger.warn('Exit fullscreen API is not supported by this browser.');
61
    }
62
}
63

64
/**
65
 * Process the ExitPresentMode event and handle default fullscreen exit
66
 * @param e - The event data
67
 */
68
function processExitPresentMode(e: any) {
69
    handleExitPresentMode();
70
    return e;
71
}
72

6✔
73
/**
6✔
74
 *
3✔
75
 * @param e
76
 * @param thoughtSpotHost
2✔
77
 */
78
export function processCustomAction(e: any, thoughtSpotHost: string) {
79
    const { session, embedAnswerData, contextMenuPoints } = e.data as CustomActionPayload;
3✔
80
    const answerService = new AnswerService(
81
        session,
6✔
82
        embedAnswerData || {},
6✔
83
        thoughtSpotHost,
84
        contextMenuPoints?.selectedPoints,
85
    );
86
    return {
87
        ...e,
88
        answerService,
89
    };
90
}
15✔
91

92
/**
93
 * Responds to AuthInit sent from host signifying successful authentication in host.
10✔
94
 * @param e
95
 * @returns {any}
10✔
96
 */
10✔
97
function processAuthInit(e: any) {
10!
98
    notifyAuthSuccess();
10✔
99

100
    // Expose only allowed details (eg: userGUID) back to SDK users.
3✔
101
    return {
3✔
102
        ...e,
7✔
103
        data: {
104
            userGUID: e.data?.userGUID || e.payload?.userGUID,
5✔
105
        },
5✔
106
    };
107
}
10✔
108

10✔
109
/**
110
 *
111
 * @param e
112
 * @param containerEl
113
 */
114
function processNoCookieAccess(e: any, containerEl: Element) {
115
    const {
116
        loginFailedMessage,
117
        suppressNoCookieAccessAlert,
1✔
118
        ignoreNoCookieAccess,
119
        suppressErrorAlerts,
1✔
120
    } = getEmbedConfig();
1✔
121
    if (!ignoreNoCookieAccess) {
1✔
122
        if (!suppressNoCookieAccessAlert && !suppressErrorAlerts) {
1✔
123
            // eslint-disable-next-line no-alert
1✔
124
            alert(ERROR_MESSAGE.THIRD_PARTY_COOKIE_BLOCKED_ALERT);
125
        }
126
        // eslint-disable-next-line no-param-reassign
127
        containerEl.innerHTML = loginFailedMessage;
128
    }
129
    notifyAuthFailure(AuthFailureType.NO_COOKIE_ACCESS);
130
    return e;
131
}
132

133
/**
15✔
134
 *
135
 * @param e
136
 * @param containerEl
137
 */
138
export function processAuthFailure(e: any, containerEl: Element) {
139
    const {
67!
140
        loginFailedMessage, authType, disableLoginFailurePage, autoLogin,
141
    } = getEmbedConfig();
6✔
142
    
143
    const isEmbeddedSSO = authType === AuthType.EmbeddedSSO;
2✔
144
    const isTrustedAuth = authType === AuthType.TrustedAuthToken || authType === AuthType.TrustedAuthTokenCookieless;
145
    const isEmbeddedSSOInfoFailure = isEmbeddedSSO && e?.data?.type === AuthFailureType.UNAUTHENTICATED_FAILURE;
6✔
146
    if (autoLogin && isTrustedAuth) {
147
        // eslint-disable-next-line no-param-reassign
5✔
148
        containerEl.innerHTML = loginFailedMessage;
149
        notifyAuthFailure(AuthFailureType.IDLE_SESSION_TIMEOUT);
1✔
150
    } else if (authType !== AuthType.None && !disableLoginFailurePage && !isEmbeddedSSOInfoFailure) {
UNCOV
151
        // eslint-disable-next-line no-param-reassign
×
152
        containerEl.innerHTML = loginFailedMessage;
153
        notifyAuthFailure(AuthFailureType.OTHER);
154
    }
47✔
155
    resetCachedAuthToken();
156
    return e;
157
}
158

159
/**
160
 *
161
 * @param e
162
 * @param containerEl
163
 */
164
function processAuthLogout(e: any, containerEl: Element) {
165
    const { loginFailedMessage } = getEmbedConfig();
166
    // eslint-disable-next-line no-param-reassign
167
    containerEl.innerHTML = loginFailedMessage;
168
    resetCachedAuthToken();
169
    disableAutoLogin();
170
    notifyLogout();
171
    return e;
172
}
173

174
/**
175
 *
176
 * @param type
177
 * @param e
178
 * @param thoughtSpotHost
179
 * @param containerEl
180
 */
181
export function processEventData(
182
    type: EmbedEvent,
183
    e: any,
184
    thoughtSpotHost: string,
185
    containerEl: Element,
186
): any {
187
    switch (type) {
188
        case EmbedEvent.CustomAction:
189
            return processCustomAction(e, thoughtSpotHost);
190
        case EmbedEvent.AuthInit:
191
            return processAuthInit(e);
192
        case EmbedEvent.NoCookieAccess:
193
            return processNoCookieAccess(e, containerEl);
194
        case EmbedEvent.AuthFailure:
195
            return processAuthFailure(e, containerEl);
196
        case EmbedEvent.AuthLogout:
197
            return processAuthLogout(e, containerEl);
198
        case EmbedEvent.ExitPresentMode:
199
            return processExitPresentMode(e);
200
        default:
201
    }
202
    return e;
203
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc