[Share Modal] Fix disabled license to not show export tab (#188439)

## Summary

Closes https://github.com/elastic/kibana/issues/184871

This PR adds a check for if the license is disabled for reporting and
does not show the Export tab in the share modal. It might be good to
have a message in the export tab to show the users that they need to
update their license but that might need some feedback from
@elastic/kibana-design. This can be accomplished in another PR but this
PR is just to avoid the nasty error to the users who might be in this
situation.

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Rachel Shen 2024-07-18 11:44:18 -06:00 committed by GitHub
parent ebc3d14828
commit 4960bb38ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 112 additions and 2 deletions

View file

@ -0,0 +1,103 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React from 'react';
import { ShareMenuTabs } from './share_tabs';
import { ShareTabsContext } from './context';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { KibanaLocation, LocatorGetUrlParams, UrlService } from '../../common/url_service';
import {
BrowserShortUrlClient,
BrowserShortUrlClientHttp,
} from '../url_service/short_urls/short_url_client';
import {
BrowserShortUrlClientFactoryCreateParams,
BrowserShortUrlClientFactory,
} from '../url_service/short_urls/short_url_client_factory';
import { themeServiceMock } from '@kbn/core-theme-browser-mocks';
import { i18nServiceMock } from '@kbn/core-i18n-browser-mocks';
import { toastsServiceMock } from '@kbn/core-notifications-browser-mocks/src/toasts_service.mock';
const navigate = jest.fn(async () => {});
const getUrl = jest.fn(
async (location: KibanaLocation, params: LocatorGetUrlParams): Promise<string> => {
return `${params.absolute ? 'https://example.com' : ''}/xyz/${location.app}/${location.path}`;
}
);
const http: BrowserShortUrlClientHttp = {
basePath: {
get: () => '/xyz',
},
fetch: jest.fn(async () => {
return {} as any;
}),
};
const service = new UrlService<BrowserShortUrlClientFactoryCreateParams, BrowserShortUrlClient>({
baseUrl: '/xyz',
version: '1.2.3',
navigate,
getUrl,
shortUrls: ({ locators }) =>
new BrowserShortUrlClientFactory({
http,
locators,
}),
});
const mockShareContext = {
allowEmbed: true,
allowShortUrl: true,
anonymousAccess: { getCapabilities: jest.fn(), getState: jest.fn() },
urlService: service,
isEmbedded: true,
theme: themeServiceMock.createStartContract(),
objectTypeMeta: { title: 'title' },
objectType: 'type',
sharingData: { title: 'title', url: 'url' },
isDirty: false,
onClose: jest.fn(),
toasts: toastsServiceMock.createStartContract(),
i18n: i18nServiceMock.createStartContract(),
};
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: jest.fn() },
];
const wrapper = mountWithIntl(
<ShareTabsContext.Provider value={{ ...mockShareContext, shareMenuItems: testItem }}>
<ShareMenuTabs />
</ShareTabsContext.Provider>
);
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: jest.fn() },
];
const wrapper = mountWithIntl(
<ShareTabsContext.Provider value={{ ...mockShareContext, shareMenuItems: testItems }}>
<ShareMenuTabs />
</ShareTabsContext.Provider>
);
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: jest.fn() },
{ shareMenuItem: { name: 'test', disabled: true }, label: PNG, generateExport: jest.fn() },
];
const wrapper = mountWithIntl(
<ShareTabsContext.Provider value={{ ...mockShareContext, shareMenuItems: testItem }}>
<ShareMenuTabs />
</ShareTabsContext.Provider>
);
expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy();
});
});

View file

@ -34,7 +34,10 @@ export const ShareMenuTabs = () => {
tabs.push(linkTab);
if (shareMenuItems.length > 0) {
const enabledItems = shareMenuItems.filter(({ shareMenuItem }) => !shareMenuItem?.disabled);
// do not show the export tab if the license is disabled
if (enabledItems.length > 0) {
tabs.push(exportTab);
}

View file

@ -21,6 +21,10 @@
"@kbn/react-kibana-mount",
"@kbn/shared-ux-tabbed-modal",
"@kbn/core-theme-browser",
"@kbn/test-jest-helpers",
"@kbn/core-theme-browser-mocks",
"@kbn/core-i18n-browser-mocks",
"@kbn/core-notifications-browser-mocks",
],
"exclude": [
"target/**/*",

View file

@ -96,7 +96,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
// open the share menu and check that reporting is disabled
await PageObjects.lens.clickShareModal();
expect(await PageObjects.lens.isShareActionEnabled(`export`));
expect(await testSubjects.exists('export')).to.be(false);
await PageObjects.lens.closeShareModal();
});