Skip to content

Commit

Permalink
functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Nov 29, 2023
1 parent 15b06af commit 24bdc5d
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import * as React from 'react';

import { EuiButtonEmpty } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { ChromeDocTitle } from '@kbn/core-chrome-browser';
import { NotFoundPrompt } from '@kbn/shared-ux-prompt-not-found';

const defaultTitle = i18n.translate('share.urlService.redirect.components.Error.title', {
Expand All @@ -26,22 +28,28 @@ const defaultBody = i18n.translate('share.urlService.redirect.components.Error.b
export interface ErrorProps {
title?: string;
body?: string;
docTitle: ChromeDocTitle;
error: Error;
}

export const RedirectEmptyPrompt: React.FC<ErrorProps> = ({
title = defaultTitle,
body = defaultBody,
...props
docTitle,
error,
}) => {
// eslint-disable-next-line no-console
console.error('Short URL Redirect Error', props.error);
console.error('Short URL Redirect Error', error);

// Using the current URL containing "/app/r/", make a URL to the root basePath
// by trimming that part to end up at the Home app or project home.
const currentUrl = window.location.href;
const newUrl = currentUrl.replace(/\/app\/r\/.*/, '');

docTitle.change(
i18n.translate('share.urlService.redirect.components.docTitle', { defaultMessage: 'Not Found' })
);

return (
<NotFoundPrompt
title={<h2>{title}</h2>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,30 @@ import * as React from 'react';
import useObservable from 'react-use/lib/useObservable';

import { EuiPageTemplate } from '@elastic/eui';
import type { CustomBrandingStart } from '@kbn/core-custom-branding-browser';
import type { ThemeServiceSetup } from '@kbn/core/public';
import type { CustomBrandingSetup } from '@kbn/core-custom-branding-browser';
import type { ChromeDocTitle, ThemeServiceSetup } from '@kbn/core/public';
import { KibanaThemeProvider } from '@kbn/react-kibana-context-theme';

import type { RedirectManager } from '../redirect_manager';
import { RedirectEmptyPrompt } from './empty_prompt';
import { Spinner } from './spinner';

export interface PageProps {
customBranding: CustomBrandingStart;
docTitle: ChromeDocTitle;
customBranding: CustomBrandingSetup;
manager: Pick<RedirectManager, 'error$'>;
theme: ThemeServiceSetup;
}

export const Page: React.FC<PageProps> = ({ manager, theme, customBranding }) => {
export const Page: React.FC<PageProps> = ({ manager, customBranding, docTitle, theme }) => {
const error = useObservable(manager.error$);
const hasCustomBranding = useObservable(customBranding.hasCustomBranding$);

if (error) {
return (
<KibanaThemeProvider theme={{ theme$: theme.theme$ }}>
<EuiPageTemplate>
<RedirectEmptyPrompt error={error} />
<RedirectEmptyPrompt docTitle={docTitle} error={error} />
</EuiPageTemplate>
</KibanaThemeProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ export class RedirectManager {
chromeless: true,
mount: async (params) => {
const { render } = await import('./render');
const [coreStart] = await core.getStartServices();

const unmount = render(params.element, {
manager: this,
theme: core.theme,
customBranding: core.customBranding,
docTitle: coreStart.chrome.docTitle,
theme: core.theme,
});
this.onMount(params.history.location);
return () => {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/share/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@kbn/react-kibana-context-theme",
"@kbn/core-analytics-browser",
"@kbn/shared-ux-error-boundary",
"@kbn/shared-ux-prompt-not-found",
],
"exclude": [
"target/**/*",
Expand Down
32 changes: 18 additions & 14 deletions test/functional/apps/sharing/_short_urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,38 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getPageObjects, getService }: FtrProviderContext) {
const PageObjects = getPageObjects(['common']);
const browser = getService('browser');
const log = getService('log');
const testSubjects = getService('testSubjects');
const retry = getService('retry');

describe('Short URLs', () => {
it('opening a missing short URL shows empty prompt', async () => {
await PageObjects.common.navigateToApp('home');
const PageObjects = getPageObjects(['common']);
const browser = getService('browser');
const log = getService('log');
const testSubjects = getService('testSubjects');
const retry = getService('retry');

log.info('Navigating to Home...');
await retry.try(async () => {
const title = await browser.getTitle();
expect(title).to.be('Home - Elastic');
});
it('shows Page for missing short URL', async () => {
await PageObjects.common.navigateToApp('home');

log.info('Changing URL to missing short URL...');
// go to 404
const currentUrl = await browser.getCurrentUrl();
log.info('Changing URL to missing short URL...');
const newUrl = currentUrl.replace(/\/app\/home/, '/app/r/s/foofoo');
await browser.get(newUrl);

// check the page for 404 contents
log.info('Checking page title...');
await retry.try(async () => {
const title = await browser.getTitle();
expect(title).to.be('Not Found - Elastic');
});

await retry.try(async () => {
await testSubjects.existOrFail('redirectErrorEmptyPromptBody');
});

// click "back to home" button
log.info('Clicking the prompt button...');
await testSubjects.click('redirectErrorEmptyPromptButton');

// check the page
await retry.try(async () => {
const title = await browser.getTitle();
expect(title).to.be('Home - Elastic');
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
require.resolve('../../common/management'),
require.resolve('../../common/platform_security'),
require.resolve('../../common/reporting'),
require.resolve('../../common/sharing'),
],
junit: {
reportName: 'Serverless Observability Functional Tests - Common Group 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
require.resolve('../../common/management'),
require.resolve('../../common/platform_security'),
require.resolve('../../common/reporting'),
require.resolve('../../common/sharing'),
],
junit: {
reportName: 'Serverless Search Functional Tests - Common Group 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
require.resolve('../../common/management'),
require.resolve('../../common/platform_security'),
require.resolve('../../common/reporting'),
require.resolve('../../common/sharing'),
],
junit: {
reportName: 'Serverless Security Functional Tests - Common Group 1',
Expand Down

0 comments on commit 24bdc5d

Please sign in to comment.