Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jest.config.sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
coveragePathIgnorePatterns: ['/node_modules/', '/test/'],
coverageThreshold: {
'./src/': {
branches: 88,
branches: 87,
functions: 88,
lines: 96,
},
Expand Down
1 change: 0 additions & 1 deletion src/embed/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ export const init = (embedConfig: EmbedConfig): AuthEventEmitter => {
const { password, ...configToTrack } = getEmbedConfig();
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_CALLED_INIT, {
...configToTrack,
usedCustomizationSheet: embedConfig.customizations?.style?.customCSSUrl != null,
usedCustomizationVariables: embedConfig.customizations?.style?.customCSS?.variables != null,
usedCustomizationRules:
embedConfig.customizations?.style?.customCSS?.rules_UNSTABLE != null,
Expand Down
22 changes: 0 additions & 22 deletions src/embed/embed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,3 @@ describe('test view config', () => {
});
});
});

describe('Custom CSS Url', () => {
beforeEach(() => {
document.body.innerHTML = getDocumentBody();
});

test('passing customCssUrl should set the correct query params on the iframe', async (done) => {
init({
thoughtSpotHost,
authType: AuthType.None,
customCssUrl: 'bla.com/foo.css',
});

const embed = new SearchEmbed(getRootEl(), defaultViewConfig);
embed.render();
executeAfterWait(() => {
const iframe = getIFrameEl();
expect(iframe.src.includes('customCssUrl=bla.com/foo.css')).toBe(true);
done();
});
});
});
11 changes: 0 additions & 11 deletions src/embed/ts-embed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ beforeAll(() => {
const customisations = {
style: {
customCSS: {},
customCSSUrl: 'http://localhost:3000',
},
content: {},
};

const customisationsView = {
style: {
customCSS: {},
customCSSUrl: 'http://localhost:8000',
},
content: {
strings: {
Expand Down Expand Up @@ -95,7 +93,6 @@ describe('Unit test case for ts embed', () => {
init({
thoughtSpotHost: 'tshost',
customizations: customisations,
customCssUrl: 'http://localhost:5000',
authType: AuthType.TrustedAuthTokenCookieless,
getAuthToken: () => Promise.resolve('test_auth_token2'),
});
Expand Down Expand Up @@ -136,7 +133,6 @@ describe('Unit test case for ts embed', () => {
thoughtSpotHost: 'tshost',
authType: AuthType.None,
customizations: customisations,
customCssUrl: 'http://localhost:5000',
});
});

Expand Down Expand Up @@ -199,9 +195,6 @@ describe('Unit test case for ts embed', () => {
reorderedHomepageModules: [],
},
});
expect(getIFrameSrc()).toContain(
`customCssUrl=${customisationsView.style.customCSSUrl}`,
);
});

test('hide home page modules from view Config should be part of app_init payload', async () => {
Expand Down Expand Up @@ -601,7 +594,6 @@ describe('Unit test case for ts embed', () => {
init({
thoughtSpotHost: 'tshost',
customizations: customisations,
customCssUrl: 'http://localhost:5000',
authType: AuthType.TrustedAuthTokenCookieless,
getAuthToken: () => Promise.resolve('test_auth_token1'),
});
Expand Down Expand Up @@ -655,7 +647,6 @@ describe('Unit test case for ts embed', () => {
init({
thoughtSpotHost: 'tshost',
customizations: customisations,
customCssUrl: 'http://localhost:5000',
authType: AuthType.TrustedAuthTokenCookieless,
getAuthToken: () => Promise.reject(),
});
Expand Down Expand Up @@ -790,7 +781,6 @@ describe('Unit test case for ts embed', () => {
init({
thoughtSpotHost: 'tshost',
customizations: customisations,
customCssUrl: 'http://localhost:5000',
authType: AuthType.TrustedAuthToken,
username: 'tsadmin',
getAuthToken: () => Promise.resolve('test_auth_token3'),
Expand Down Expand Up @@ -819,7 +809,6 @@ describe('Unit test case for ts embed', () => {
init({
thoughtSpotHost: 'tshost',
customizations: customisations,
customCssUrl: 'http://localhost:5000',
authType: AuthType.TrustedAuthToken,
username: 'tsadmin',
getAuthToken: () => Promise.resolve('test_auth_token4'),
Expand Down
7 changes: 0 additions & 7 deletions src/embed/ts-embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,6 @@ export class TsEmbed {
return queryParams;
}

// TODO remove embedConfig.customCssUrl
const cssUrlParam = customizations?.style?.customCSSUrl || this.embedConfig.customCssUrl;

if (cssUrlParam) {
queryParams[Param.CustomCSSUrl] = cssUrlParam;
}

if (disabledActions?.length) {
queryParams[Param.DisableActions] = disabledActions;
}
Expand Down
9 changes: 0 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ export interface customCssInterface {
* Styles within the {@link CustomisationsInterface}.
*/
export interface CustomStyles {
customCSSUrl?: string;
customCSS?: customCssInterface;
}

Expand Down Expand Up @@ -449,13 +448,6 @@ export interface EmbedConfig {
*/
queueMultiRenders?: boolean;

/**
* Dynamic CSS URL to be injected in the loaded application.
* You would also need to set `style-src` in the CSP settings.
* @version SDK: 1.6.0 | ThoughtSpot: ts8.nov.cl, 8.4.1.sw
* @default ''
*/
customCssUrl?: string;
/**
* [AuthServer|Basic] Detect if third-party party cookies are enabled by doing an
* additional call. This is slower and should be avoided. Listen to the
Expand Down Expand Up @@ -3080,7 +3072,6 @@ export enum Param {
ViewPortHeight = 'viewPortHeight',
ViewPortWidth = 'viewPortWidth',
VisibleActions = 'visibleAction',
CustomCSSUrl = 'customCssUrl',
DisableLoginRedirect = 'disableLoginRedirect',
visibleVizs = 'pinboardVisibleVizs',
LiveboardV2Enabled = 'isPinboardV2Enabled',
Expand Down
5 changes: 0 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export const getCustomisations = (
embedConfig: EmbedConfig,
viewConfig: ViewConfig,
): CustomisationsInterface => {
const customCssUrlFromEmbedConfig = embedConfig.customCssUrl;
const customizationsFromViewConfig = viewConfig.customizations;
const customizationsFromEmbedConfig = embedConfig.customizations
|| ((embedConfig as any).customisations as CustomisationsInterface);
Expand All @@ -219,10 +218,6 @@ export const getCustomisations = (
...customizationsFromEmbedConfig?.style?.customCSS,
...customizationsFromViewConfig?.style?.customCSS,
},
customCSSUrl:
customizationsFromViewConfig?.style?.customCSSUrl
|| customizationsFromEmbedConfig?.style?.customCSSUrl
|| customCssUrlFromEmbedConfig,
},
content: {
...customizationsFromEmbedConfig?.content,
Expand Down
18 changes: 18 additions & 0 deletions src/utils/graphql/answerService/answerService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AnswerService } from './answerService';
import {
getAnswerData, removeColumns, addFilter, addColumns,
} from './answer-queries';
import * as queries from './answer-queries';
import * as authTokenInstance from '../../../authToken';
import * as tokenizedFetch from '../../../tokenizedFetch';
import * as embedConfigInstance from '../../../embed/embedConfig';
Expand Down Expand Up @@ -34,6 +35,23 @@ describe('Answer service tests', () => {
beforeEach(() => {
fetchMock.resetMocks();
});

test('should call executeQuery with correct parameters to add columns', async () => {
const service = createAnswerService();
const executeQuerySpy = jest.spyOn(service, 'executeQuery').mockResolvedValue({
id: { genNo: 2 },

});

const columnIds = ['col1', 'col2'];
const result = await service.addColumns(columnIds);

expect(executeQuerySpy).toHaveBeenCalledWith(queries.addColumns, {
columns: columnIds.map((colId) => ({ logicalColumnId: colId })),
});
expect(result.id.genNo).toBe(2);
});

test('Execute query should execute the supplied graphql on the session', async () => {
fetchMock.mockResponseOnce(JSON.stringify({
data: {
Expand Down
38 changes: 38 additions & 0 deletions src/utils/graphql/graphql-request.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'jest-fetch-mock';
import { getSourceDetail } from './sourceService';
import * as tokenizedFetchUtil from '../../tokenizedFetch';
import { graphqlQuery } from './graphql-request';

const getSourceDetailQuery = `
query GetSourceDetail($ids: [GUID!]!) {
getSourceDetailById(ids: $ids, type: LOGICAL_TABLE) {
id
name
}
}
`;

const thoughtSpotHost = 'TSHOST';

describe('graphQl tests', () => {
test('should call tokenizedFetch with correct parameters when graphqlQuery is called', async () => {
jest.spyOn(tokenizedFetchUtil, 'tokenizedFetch');

const details = await graphqlQuery({
query: getSourceDetailQuery,
variables: {
ids: [2],
},
thoughtSpotHost,
});

expect(tokenizedFetchUtil.tokenizedFetch).toBeCalledWith('TSHOST/prism/?op=GetSourceDetail', {
body: '{"operationName":"GetSourceDetail","query":"\\n query GetSourceDetail($ids: [GUID!]!) {\\n getSourceDetailById(ids: $ids, type: LOGICAL_TABLE) {\\n id\\n name\\n }\\n } \\n","variables":{"ids":[2]}}',
credentials: 'include',
headers: {
accept: '*/*', 'accept-language': 'en-us', 'content-type': 'application/json;charset=UTF-8', 'x-requested-by': 'ThoughtSpot',
},
method: 'POST',
});
});
});
19 changes: 19 additions & 0 deletions src/utils/processTrigger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,23 @@ describe('Unit test for processTrigger', () => {
expect(messageChannelMock.port1.close).toBeCalled();
expect(triggerPromise).rejects.toEqual(res.data.error);
});

test('should close channel.port1 when timeout exceeds TRIGGER_TIMEOUT', async () => {
const messageType = HostEvent.Search;
const thoughtSpotHost = 'http://localhost:3000';
const data = {};
mockMessageChannel();

const triggerPromise = _processTriggerInstance.processTrigger(
iFrame,
messageType,
thoughtSpotHost,
data,
);

jest.advanceTimersByTime(_processTriggerInstance.TRIGGER_TIMEOUT);

expect(messageChannelMock.port1.close).toBeCalled();
await expect(triggerPromise).resolves.toBeInstanceOf(Error);
});
});
2 changes: 1 addition & 1 deletion src/utils/processTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function postIframeMessage(
return iFrame.contentWindow.postMessage(message, thoughtSpotHost, [channel?.port2]);
}

const TRIGGER_TIMEOUT = 30000;
export const TRIGGER_TIMEOUT = 30000;

/**
*
Expand Down