Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.16] Account for disabledShareUrl prop for rendered sharing options (#206592) #206769

Merged
merged 1 commit into from
Jan 15, 2025
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
125 changes: 71 additions & 54 deletions src/plugins/share/public/components/share_tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import React from 'react';
import { ShareMenuTabs } from './share_tabs';
import { ShareMenuProvider } from './context';
import { ShareMenuProvider, type IShareContext } from './context';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { KibanaLocation, LocatorGetUrlParams, UrlService } from '../../common/url_service';
import {
Expand Down Expand Up @@ -48,7 +48,9 @@ const service = new UrlService<BrowserShortUrlClientFactoryCreateParams, Browser
locators,
}),
});
const mockShareContext = {

const mockShareContext: IShareContext = {
shareMenuItems: [],
allowEmbed: true,
allowShortUrl: true,
anonymousAccess: { getCapabilities: jest.fn(), getState: jest.fn() },
Expand All @@ -62,66 +64,81 @@ const mockShareContext = {
toasts: toastsServiceMock.createStartContract(),
i18n: i18nServiceMock.createStartContract(),
};

const mockGenerateExport = jest.fn();
const mockGenerateExportUrl = jest.fn().mockImplementation(() => 'generated-export-url');
const CSV = 'CSV' as const;
const PNG = 'PNG' as const;

describe('Share modal tabs', () => {
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 wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItem }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy();
describe('link tab', () => {
it('should not render the link tab when the disableShareUrl prop is true', async () => {
const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, disabledShareUrl: true }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
expect(wrapper.find('[data-test-subj="link"]').exists()).toBeFalsy();
});
});
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,
},
];

const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItems }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
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 wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItem }}>
<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,
},
];

expect(wrapper.find('[data-test-subj="export"]').exists()).toBeFalsy();
});
const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItems }}>
<ShareMenuTabs />
</ShareMenuProvider>
);

expect(wrapper.find('[data-test-subj="export"]').exists()).toBeFalsy();
});

it('should render export tab is at least one 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 wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItem }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy();
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 wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItem }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy();
});
});
});
16 changes: 11 additions & 5 deletions src/plugins/share/public/components/share_tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ export const ShareMenu: FC<{ shareContext: IShareContext }> = ({ shareContext })
export const ShareMenuTabs = () => {
const shareContext = useShareTabsContext();

const { allowEmbed, objectTypeMeta, onClose, shareMenuItems, anchorElement } = shareContext;
const { allowEmbed, objectTypeMeta, onClose, shareMenuItems, anchorElement, disabledShareUrl } =
shareContext;

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

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

const enabledItems = shareMenuItems.filter(({ shareMenuItem }) => !shareMenuItem?.disabled);

Expand All @@ -40,15 +46,15 @@ export const ShareMenuTabs = () => {
tabs.push(embedTab);
}

return (
return Boolean(tabs.length) ? (
<TabbedModal
tabs={tabs}
modalWidth={498}
onClose={onClose}
modalTitle={objectTypeMeta.title}
defaultSelectedTabId="link"
defaultSelectedTabId={tabs[0].id}
anchorElement={anchorElement}
data-test-subj="shareContextModal"
/>
);
) : null;
};
Loading