Skip to content

Commit 42356c3

Browse files
SCAL-274111 added test for hideTagFilterChips
1 parent aa08154 commit 42356c3

File tree

4 files changed

+4190
-3729
lines changed

4 files changed

+4190
-3729
lines changed

src/embed/ts-embed.spec.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
ContextMenuTriggerOptions,
2929
CustomActionTarget,
3030
CustomActionsPosition,
31+
ListPageColumns,
3132
} from '../types';
3233
import {
3334
executeAfterWait,
@@ -3456,4 +3457,74 @@ describe('Unit test case for ts embed', () => {
34563457
triggerSpy.mockReset();
34573458
});
34583459
});
3460+
3461+
describe('hideTagFilterChips functionality', () => {
3462+
beforeAll(() => {
3463+
init({
3464+
thoughtSpotHost: 'tshost',
3465+
authType: AuthType.None,
3466+
});
3467+
});
3468+
test('when hideTagFilterChips is true should automatically add Action.ManageTags to hiddenActions for AppEmbed', async () => {
3469+
const appEmbed = new AppEmbed(getRootEl(), {
3470+
frameParams: {
3471+
width: '100%',
3472+
height: '100%',
3473+
},
3474+
hideTagFilterChips: true,
3475+
});
3476+
appEmbed.render();
3477+
await waitFor(() => !!getIFrameEl()).then(() => {
3478+
const iframeSrc = getIFrameSrc();
3479+
expect(iframeSrc).toContain(encodeURIComponent(`"${Action.ManageTags}"`));
3480+
expect(iframeSrc).toContain('hideAction=');
3481+
});
3482+
});
3483+
3484+
test('when hideTagFilterChips is false should not add Action.ManageTags to hiddenActions for AppEmbed', async () => {
3485+
const appEmbed = new AppEmbed(getRootEl(), {
3486+
frameParams: {
3487+
width: '100%',
3488+
height: '100%',
3489+
},
3490+
});
3491+
appEmbed.render();
3492+
await waitFor(() => !!getIFrameEl()).then(() => {
3493+
const iframeSrc = getIFrameSrc();
3494+
expect(iframeSrc).not.toContain(encodeURIComponent(`"${Action.ManageTags}"`));
3495+
expect(iframeSrc).toContain('hideAction=');
3496+
});
3497+
});
3498+
3499+
test('should work with existing hiddenListColumns without duplicates', async () => {
3500+
const appEmbed = new AppEmbed(getRootEl(), {
3501+
...defaultViewConfig,
3502+
hideTagFilterChips: true,
3503+
hiddenListColumns: [ListPageColumns.Author, ListPageColumns.Favourite],
3504+
} as AppViewConfig);
3505+
3506+
const appInitData = await (appEmbed as any).getDefaultAppInitData();
3507+
3508+
expect(appInitData.hiddenListColumns).toContain(ListPageColumns.Author);
3509+
expect(appInitData.hiddenListColumns).toContain(ListPageColumns.Favourite);
3510+
expect(appInitData.hiddenListColumns).toContain(ListPageColumns.Tags);
3511+
3512+
const tagsCount = appInitData.hiddenListColumns.filter(
3513+
(col: ListPageColumns) => col === ListPageColumns.Tags
3514+
).length;
3515+
expect(tagsCount).toBe(1);
3516+
});
3517+
3518+
test('should not automatically add ListPageColumns.Tags to hiddenListColumns', async () => {
3519+
const appEmbed = new AppEmbed(getRootEl(), {
3520+
...defaultViewConfig,
3521+
hideTagFilterChips: false,
3522+
} as AppViewConfig);
3523+
3524+
const appInitData = await (appEmbed as any).getDefaultAppInitData();
3525+
3526+
expect(appInitData.hiddenListColumns).not.toContain(ListPageColumns.Tags);
3527+
expect(appInitData.hiddenListColumns).toEqual([]);
3528+
});
3529+
});
34593530
});

src/embed/ts-embed.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,10 @@ export class TsEmbed {
427427
message: customActionsResult.errors,
428428
});
429429
}
430-
const finalHiddenListColumns = [...(this.viewConfig.hiddenListColumns || [])];
431-
if (this.viewConfig.hideTagFilterChips) {
432-
if (!finalHiddenListColumns.includes(ListPageColumns.Tags)) {
433-
finalHiddenListColumns.push(ListPageColumns.Tags);
434-
}
435-
}
430+
const finalHiddenListColumns = [...new Set([
431+
...(this.viewConfig.hiddenListColumns || []),
432+
...(this.viewConfig.hideTagFilterChips ? [ListPageColumns.Tags] : []),
433+
])];
436434
return {
437435
customisations: getCustomisations(this.embedConfig, this.viewConfig),
438436
authToken,
@@ -662,12 +660,10 @@ export class TsEmbed {
662660
if (exposeTranslationIDs) {
663661
queryParams[Param.ExposeTranslationIDs] = exposeTranslationIDs;
664662
}
665-
const finalHiddenActions = [...(hiddenActions ?? [])];
666-
if (hideTagFilterChips) {
667-
if (!finalHiddenActions.includes(Action.ManageTags)) {
668-
finalHiddenActions.push(Action.ManageTags);
669-
}
670-
}
663+
const finalHiddenActions = [...new Set([
664+
...(hiddenActions ?? []),
665+
...(hideTagFilterChips ? [Action.ManageTags] : []),
666+
])];
671667
queryParams[Param.HideActions] = [...this.defaultHiddenActions, ...finalHiddenActions];
672668
if (Array.isArray(visibleActions)) {
673669
queryParams[Param.VisibleActions] = visibleActions;

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ export interface BaseViewConfig {
10841084
* ```
10851085
*/
10861086
customActions?: CustomAction[];
1087-
/**
1087+
/**
10881088
* Hide tag filter chips that appear when content is filtered by tags.
10891089
* When enabled, this automatically:
10901090
* - Hides tag filter indicators/chips from the UI

0 commit comments

Comments
 (0)