Skip to content

Commit

Permalink
functional test for short url 404
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Nov 29, 2023
1 parent e5813ec commit c285b77
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 8 deletions.
1 change: 1 addition & 0 deletions .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ enabled:
- test/functional/apps/kibana_overview/config.ts
- test/functional/apps/management/config.ts
- test/functional/apps/saved_objects_management/config.ts
- test/functional/apps/sharing/config.ts
- test/functional/apps/status_page/config.ts
- test/functional/apps/visualize/group1/config.ts
- test/functional/apps/visualize/group2/config.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import * as React from 'react';

import { EuiButtonEmpty } from '@elastic/eui';
import { HttpStart } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { NotFoundPrompt } from '@kbn/shared-ux-prompt-not-found';

Expand All @@ -28,7 +27,6 @@ export interface ErrorProps {
title?: string;
body?: string;
error: Error;
http: HttpStart;
}

export const RedirectEmptyPrompt: React.FC<ErrorProps> = ({
Expand All @@ -39,14 +37,19 @@ export const RedirectEmptyPrompt: React.FC<ErrorProps> = ({
// eslint-disable-next-line no-console
console.error('Short URL Redirect Error', props.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\/.*/, '');

return (
<NotFoundPrompt
title={<h2>{title}</h2>}
body={<p data-test-subj="redirectErrorEmptyPromptBody">{body}</p>}
actions={
<EuiButtonEmpty
iconType="arrowLeft"
href={props.http.basePath.get()}
href={newUrl}
data-test-subj="redirectErrorEmptyPromptButton"
>
{i18n.translate('share.urlService.redirect.components.Error.homeButton', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useObservable from 'react-use/lib/useObservable';

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

import type { RedirectManager } from '../redirect_manager';
Expand All @@ -20,20 +20,19 @@ import { Spinner } from './spinner';

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

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

if (error) {
return (
<KibanaThemeProvider theme={{ theme$: theme.theme$ }}>
<EuiPageTemplate>
<RedirectEmptyPrompt error={error} http={http} />
<RedirectEmptyPrompt error={error} />
</EuiPageTemplate>
</KibanaThemeProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export class RedirectManager {
const { render } = await import('./render');
const unmount = render(params.element, {
manager: this,
http: core.http,
theme: core.theme,
customBranding: core.customBranding,
});
Expand Down
47 changes: 47 additions & 0 deletions test/functional/apps/sharing/_short_urls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 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');

log.info('Navigating to Home...');
await retry.try(async () => {
const title = await browser.getTitle();
expect(title).to.be('Home - Elastic');
});

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

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

log.info('Clicking the prompt button...');
await testSubjects.click('redirectErrorEmptyPromptButton');

await retry.try(async () => {
const title = await browser.getTitle();
expect(title).to.be('Home - Elastic');
});
});
});
}
18 changes: 18 additions & 0 deletions test/functional/apps/sharing/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 { FtrConfigProviderContext } from '@kbn/test';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const functionalConfig = await readConfigFile(require.resolve('../../config.base.js'));

return {
...functionalConfig.getAll(),
testFiles: [require.resolve('.')],
};
}
15 changes: 15 additions & 0 deletions test/functional/apps/sharing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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 { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('Sharing features', () => {
loadTestFile(require.resolve('./_short_urls'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

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');

log.info('Navigating to Home...');
await retry.try(async () => {
const title = await browser.getTitle();
expect(title).to.be('Home - Elastic');
});

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

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

log.info('Clicking the prompt button...');
await testSubjects.click('redirectErrorEmptyPromptButton');

await retry.try(async () => {
const title = await browser.getTitle();
expect(title).to.be('Home - Elastic');
});
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { FtrProviderContext } from '../../../ftr_provider_context';

export default ({ loadTestFile }: FtrProviderContext) => {
describe('Sharing features', function () {
loadTestFile(require.resolve('./_short_urls'));
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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,6 +17,7 @@ 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,6 +17,7 @@ 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 c285b77

Please sign in to comment.