Skip to content

Commit

Permalink
start on fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eokoneyo committed Feb 26, 2025
1 parent e629608 commit 75afcd9
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 79 deletions.
152 changes: 111 additions & 41 deletions src/platform/plugins/shared/share/public/components/share_tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,31 @@ const service = new UrlService<BrowserShortUrlClientFactoryCreateParams, Browser
});

const mockShareContext: IShareContext = {
shareMenuItems: [],
allowEmbed: true,
shareMenuItems: [
{
shareType: 'link',
config: {
shortUrlService: service.shortUrls.get(null),
},
},
{
shareType: 'embed',
config: {
shortUrlService: service.shortUrls.get(null),
anonymousAccess: { getCapabilities: jest.fn(), getState: jest.fn() },
},
},
],
allowShortUrl: true,
anonymousAccess: { getCapabilities: jest.fn(), getState: jest.fn() },
urlService: service,
theme: themeServiceMock.createStartContract(),
objectTypeMeta: { title: 'title' },
objectTypeMeta: {
title: 'title',
config: {
embed: {
disabled: false,
},
},
},
objectType: 'type',
sharingData: { title: 'title', url: 'url' },
isDirty: false,
Expand All @@ -72,9 +90,22 @@ const PNG = 'PNG' as const;

describe('Share modal tabs', () => {
describe('link tab', () => {
it('should not render the link tab when the disableShareUrl prop is true', async () => {
it('should not render the link tab when it is configured as disabled', async () => {
const disabledLinkShareContext = {
...mockShareContext,
objectTypeMeta: {
...mockShareContext.objectTypeMeta,
config: {
...mockShareContext.objectTypeMeta.config,
link: {
disabled: true,
},
},
},
};

const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, disabledShareUrl: true }}>
<ShareMenuProvider shareContext={{ ...disabledLinkShareContext }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
Expand All @@ -84,33 +115,55 @@ describe('Share modal tabs', () => {

describe('export tab', () => {
it('should render export tab when there are share menu items that are not disabled', async () => {
const testItem = [
{
shareMenuItem: { name: 'test', disabled: false },
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
];
const shareContextWithConfiguredExportItem: IShareContext = {
...mockShareContext,
shareMenuItems: [
...mockShareContext.shareMenuItems,
{
id: 'test-export',
shareType: 'integration',
groupId: 'export',
config: {
name: 'test',
disabled: false,
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
},
],
};

const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItem }}>
<ShareMenuProvider shareContext={{ ...shareContextWithConfiguredExportItem }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy();
});
it('should not render export tab when the license is disabled', async () => {
const testItems = [
{
shareMenuItem: { name: 'test', disabled: true },
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
];

it('should not render export tab when it has only one item configured as disabled', async () => {
const shareContextWithConfiguredExportItem: IShareContext = {
...mockShareContext,
shareMenuItems: [
...mockShareContext.shareMenuItems,
{
id: 'test-export',
shareType: 'integration',
groupId: 'export',
config: {
name: 'test',
disabled: true,
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
},
],
};

const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItems }}>
<ShareMenuProvider shareContext={{ ...shareContextWithConfiguredExportItem }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
Expand All @@ -119,22 +172,39 @@ describe('Share modal tabs', () => {
});

it('would render the export tab when there is at least one export type which is not disabled', async () => {
const testItem = [
{
shareMenuItem: { name: 'test', disabled: false },
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
{
shareMenuItem: { name: 'test', disabled: true },
label: PNG,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
];
const shareContextWithConfiguredExportItem: IShareContext = {
...mockShareContext,
shareMenuItems: [
...mockShareContext.shareMenuItems,
{
id: 'test-csv-export',
shareType: 'integration',
groupId: 'export',
config: {
name: 'test',
disabled: false,
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
},
{
id: 'test-png-export',
shareType: 'integration',
groupId: 'export',
config: {
name: 'test',
disabled: true,
label: PNG,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
},
],
};

const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItem }}>
<ShareMenuProvider shareContext={{ ...shareContextWithConfiguredExportItem }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,24 @@ export const ShareMenuTabs = () => {

const tabs: Array<IModalTabDeclaration<any>> = [];

// do not show the link tab if the share url is disabled
// Do not show the link tab if the share url is disabled
if (!objectTypeMeta?.config.link?.disabled) {
tabs.push(linkTab);
}

// do not show the export tab if the license is disabled
// Do not show the export tab if there's no export type enabled
if (
shareMenuItems.some(
(shareItem) => shareItem.shareType === 'integration' && shareItem.groupId === 'export'
(shareItem) =>
shareItem.shareType === 'integration' &&
shareItem.groupId === 'export' &&
!shareItem.config.disabled
)
) {
tabs.push(exportTab);
}

// embed is disabled in the serverless offering, hence the need to check that we received it
// Embed is disabled in the serverless offering, hence the need to check that we received it
if (
shareMenuItems.some(({ shareType }) => shareType === 'embed') &&
!objectTypeMeta?.config?.embed?.disabled
Expand Down
3 changes: 2 additions & 1 deletion src/platform/plugins/shared/share/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { BrowserShortUrlClientFactoryCreateParams } from './url_service/sho
export type Setup = jest.Mocked<SharePublicSetup>;
export type Start = jest.Mocked<SharePublicStart>;

const url = new UrlService<BrowserShortUrlClientFactoryCreateParams, BrowserShortUrlClient>({
export const url = new UrlService<BrowserShortUrlClientFactoryCreateParams, BrowserShortUrlClient>({
navigate: async () => {},
getUrl: async ({ app, path }, { absolute }) => {
return `${absolute ? 'http://localhost:8888' : ''}/app/${app}${path}`;
Expand All @@ -40,6 +40,7 @@ const url = new UrlService<BrowserShortUrlClientFactoryCreateParams, BrowserShor
const createSetupContract = (): Setup => {
const setupContract: Setup = {
register: jest.fn(),
registerShareIntegration: jest.fn(),
url,
navigate: jest.fn(),
setAnonymousAccessServiceProvider: jest.fn(),
Expand Down
Loading

0 comments on commit 75afcd9

Please sign in to comment.