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

[Time to Visualize] Add functional tests for adding visualizations from Visualize, Lens, and Maps and adjust capabilities for new modal #89245

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0e0999d
Add tests for adding visualizations from Visualize and Lens using new…
poffdeluxe Jan 20, 2021
cb031e1
Merge branch 'master' into test/add-to-dashboard-modal-actual
kibanamachine Jan 25, 2021
6c4fb61
Default Lens tests to add to library
poffdeluxe Jan 27, 2021
f17637f
Merge branch 'test/add-to-dashboard-modal-actual' of github.com:poffd…
poffdeluxe Jan 27, 2021
9a467de
Fix tests and licenses
poffdeluxe Jan 28, 2021
cfb0e87
Merge branch 'master' into test/add-to-dashboard-modal-actual
kibanamachine Jan 28, 2021
8d99df7
Add add-to-dashboard tests for maps
poffdeluxe Jan 29, 2021
7a4e5c5
Merge branch 'master' into test/add-to-dashboard-modal-actual
kibanamachine Jan 29, 2021
dc85155
Test fix
poffdeluxe Jan 29, 2021
785cf1c
wip
poffdeluxe Feb 1, 2021
3878d62
Merge branch 'master' into test/add-to-dashboard-modal-actual
poffdeluxe Feb 3, 2021
c96e686
Merge branch 'master' into test/add-to-dashboard-modal-actual
kibanamachine Feb 3, 2021
9242588
fix security tests
poffdeluxe Feb 4, 2021
a049f53
Merge branch 'test/atd-modal-security' into test/add-to-dashboard-mod…
poffdeluxe Feb 4, 2021
ff970ca
Fixing tests by resetting new dashboards
poffdeluxe Feb 4, 2021
00a289f
Merge branch 'master' into test/add-to-dashboard-modal-actual
poffdeluxe Feb 4, 2021
2b5bb2f
fix headers
poffdeluxe Feb 4, 2021
e7acb97
Merge branch 'master' into test/add-to-dashboard-modal-actual
kibanamachine Feb 4, 2021
29d1448
Merge branch 'master' into test/add-to-dashboard-modal-actual
poffdeluxe Feb 5, 2021
fd22199
Merge branch 'test/add-to-dashboard-modal-actual' of github.com:poffd…
poffdeluxe Feb 5, 2021
19b1994
remove dupe prop
poffdeluxe Feb 5, 2021
dcafedc
remove dupe dashboard capabilities from visualize plugin
poffdeluxe Feb 5, 2021
1b64837
Merge branch 'master' into test/add-to-dashboard-modal-actual
poffdeluxe Feb 8, 2021
ebb645d
Clean up dashboard privileges for read only dashboard roles
poffdeluxe Feb 8, 2021
d0706b2
Remove unused import
poffdeluxe Feb 8, 2021
c0da888
Merge branch 'master' into test/add-to-dashboard-modal-actual
kibanamachine Feb 10, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function DashboardPicker(props: DashboardPickerProps) {

return (
<EuiComboBox
data-test-subj="dashboardPickerInput"
placeholder={i18n.translate('presentationUtil.dashboardPicker.searchDashboardPlaceholder', {
defaultMessage: 'Search dashboards...',
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ export function SavedObjectSaveModalDashboard(props: SaveModalDashboardProps) {
const initialCopyOnSave = !Boolean(documentId);

const { capabilities } = pluginServices.getHooks();
const {
canAccessDashboards,
canCreateNewDashboards,
canEditDashboards,
} = capabilities.useService();

const disableDashboardOptions =
!canAccessDashboards() || (!canCreateNewDashboards && !canEditDashboards);
const { canAccessDashboards, canCreateNewDashboards } = capabilities.useService();

// Disable the dashboard options if the user can't access dashboards or if they're read-only
const disableDashboardOptions = !canAccessDashboards() || !canCreateNewDashboards();

const [dashboardOption, setDashboardOption] = useState<'new' | 'existing' | null>(
documentId || disableDashboardOptions ? null : 'existing'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
EuiSpacer,
} from '@elastic/eui';

import { pluginServices } from '../services';
import { DashboardPicker, DashboardPickerProps } from './dashboard_picker';

import './saved_object_save_modal_dashboard.scss';
Expand All @@ -37,9 +36,6 @@ export interface SaveModalDashboardSelectorProps {

export function SaveModalDashboardSelector(props: SaveModalDashboardSelectorProps) {
const { documentId, onSelectDashboard, dashboardOption, onChange, copyOnSave } = props;
const { capabilities } = pluginServices.getHooks();
const { canCreateNewDashboards, canEditDashboards } = capabilities.useService();

const isDisabled = !copyOnSave && !!documentId;

return (
Expand Down Expand Up @@ -70,50 +66,44 @@ export function SaveModalDashboardSelector(props: SaveModalDashboardSelectorProp
>
<EuiPanel color="subdued" hasShadow={false} data-test-subj="add-to-dashboard-options">
<div>
{canEditDashboards() && (
<>
{' '}
<EuiRadio
checked={dashboardOption === 'existing'}
id="existing-dashboard-option"
name="dashboard-option"
label={i18n.translate(
'presentationUtil.saveModalDashboard.existingDashboardOptionLabel',
{
defaultMessage: 'Existing',
}
)}
onChange={() => onChange('existing')}
disabled={isDisabled}
/>
<div className="savAddDashboard__searchDashboards">
<DashboardPicker
isDisabled={dashboardOption !== 'existing'}
onChange={onSelectDashboard}
/>
</div>
<EuiSpacer size="s" />
</>
)}
{canCreateNewDashboards() && (
<>
{' '}
<EuiRadio
checked={dashboardOption === 'new'}
id="new-dashboard-option"
name="dashboard-option"
label={i18n.translate(
'presentationUtil.saveModalDashboard.newDashboardOptionLabel',
{
defaultMessage: 'New',
}
)}
onChange={() => onChange('new')}
disabled={isDisabled}
<>
<EuiRadio
checked={dashboardOption === 'existing'}
id="existing-dashboard-option"
name="dashboard-option"
label={i18n.translate(
'presentationUtil.saveModalDashboard.existingDashboardOptionLabel',
{
defaultMessage: 'Existing',
}
)}
onChange={() => onChange('existing')}
disabled={isDisabled}
/>
<div className="savAddDashboard__searchDashboards">
<DashboardPicker
isDisabled={dashboardOption !== 'existing'}
onChange={onSelectDashboard}
/>
<EuiSpacer size="s" />
</>
)}
</div>
<EuiSpacer size="s" />
</>
<>
<EuiRadio
checked={dashboardOption === 'new'}
id="new-dashboard-option"
name="dashboard-option"
label={i18n.translate(
'presentationUtil.saveModalDashboard.newDashboardOptionLabel',
{
defaultMessage: 'New',
}
)}
onChange={() => onChange('new')}
disabled={isDisabled}
/>
<EuiSpacer size="s" />
</>
<EuiRadio
checked={dashboardOption === null}
id="add-to-library-option"
Expand Down
1 change: 0 additions & 1 deletion src/plugins/presentation_util/public/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface PresentationDashboardsService {
export interface PresentationCapabilitiesService {
canAccessDashboards: () => boolean;
canCreateNewDashboards: () => boolean;
canEditDashboards: () => boolean;
}

export interface PresentationUtilServices {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ export const capabilitiesServiceFactory: CapabilitiesServiceFactory = ({ coreSta
return {
canAccessDashboards: () => Boolean(dashboard.show),
canCreateNewDashboards: () => Boolean(dashboard.createNew),
canEditDashboards: () => !Boolean(dashboard.hideWriteControls),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const VisualizeListing = () => {
const calloutMessage = (
<>
<FormattedMessage
data-test-subj="visualize-dashboard-flow-prompt"
id="visualize.visualizeListingDashboardFlowDescription"
defaultMessage="Building a dashboard? Create content directly from the {dashboardApp} using a new integrated workflow."
values={{
Expand Down
147 changes: 147 additions & 0 deletions test/functional/apps/visualize/_add_to_dashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* 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 'test/functional/ftr_provider_context';
import expect from '@kbn/expect';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const dashboardExpect = getService('dashboardExpect');
const testSubjects = getService('testSubjects');
const listingTable = getService('listingTable');

const PageObjects = getPageObjects([
'common',
'dashboard',
'header',
'visualize',
'visEditor',
'discover',
'timePicker',
'timeToVisualize',
]);

describe('Add to Dashboard', function describeIndexTests() {
it('adding a new metric to a new dashboard', async function () {
await PageObjects.visualize.navigateToNewAggBasedVisualization();
await PageObjects.visualize.clickMetric();
await PageObjects.visualize.clickNewSearch();
await PageObjects.timePicker.setDefaultAbsoluteRange();

await testSubjects.click('visualizeSaveButton');

await PageObjects.timeToVisualize.saveFromModal('My New Vis 1', {
addToDashboard: 'new',
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(1);

await PageObjects.timeToVisualize.resetNewDashboard();
});

it('adding a existing metric to a new dashboard', async function () {
await PageObjects.visualize.navigateToNewAggBasedVisualization();
await PageObjects.visualize.clickMetric();
await PageObjects.visualize.clickNewSearch();
await PageObjects.timePicker.setDefaultAbsoluteRange();

await testSubjects.click('visualizeSaveButton');

// Save this new viz to library
await PageObjects.timeToVisualize.saveFromModal('My New Vis 1', {
addToDashboard: null,
});

await testSubjects.click('visualizeSaveButton');

// All the options should be disabled
await PageObjects.timeToVisualize.ensureDashboardOptionsAreDisabled();

// Save a new copy of this viz to a new dashboard
await PageObjects.timeToVisualize.saveFromModal('My New Vis 1 Copy', {
addToDashboard: 'new',
saveAsNew: true,
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(1);

await PageObjects.timeToVisualize.resetNewDashboard();
});

it('adding a new metric to an existing dashboard', async function () {
await PageObjects.common.navigateToApp('dashboard');

await PageObjects.dashboard.clickNewDashboard();
await PageObjects.dashboard.addVisualizations(['Visualization AreaChart']);
await PageObjects.dashboard.saveDashboard('My Wonderful Dashboard');
await PageObjects.dashboard.gotoDashboardLandingPage();
await listingTable.searchAndExpectItemsCount('dashboard', 'My Wonderful Dashboard', 1);

await PageObjects.visualize.navigateToNewAggBasedVisualization();
await PageObjects.visualize.clickMetric();
await PageObjects.visualize.clickNewSearch();
await PageObjects.timePicker.setDefaultAbsoluteRange();

await testSubjects.click('visualizeSaveButton');

await PageObjects.timeToVisualize.saveFromModal('My New Vis 2', {
addToDashboard: 'existing',
dashboardId: 'My Wonderful Dashboard',
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(2);
});

it('adding a existing metric to an existing dashboard', async function () {
await PageObjects.common.navigateToApp('dashboard');

await PageObjects.dashboard.clickNewDashboard();
await PageObjects.dashboard.addVisualizations(['Visualization AreaChart']);
await PageObjects.dashboard.saveDashboard('My Very Cool Dashboard');
await PageObjects.dashboard.gotoDashboardLandingPage();
await listingTable.searchAndExpectItemsCount('dashboard', 'My Very Cool Dashboard', 1);

await PageObjects.visualize.navigateToNewAggBasedVisualization();
await PageObjects.visualize.clickMetric();
await PageObjects.visualize.clickNewSearch();
await PageObjects.timePicker.setDefaultAbsoluteRange();

await testSubjects.click('visualizeSaveButton');

// Save this new viz to library
await PageObjects.timeToVisualize.saveFromModal('My New Vis 2', {
addToDashboard: null,
});

await testSubjects.click('visualizeSaveButton');

// All the options should be disabled
await PageObjects.timeToVisualize.ensureDashboardOptionsAreDisabled();

// Save a new copy of this viz to an existing dashboard
await PageObjects.timeToVisualize.saveFromModal('My New Vis 2 Copy', {
addToDashboard: 'existing',
dashboardId: 'My Very Cool Dashboard',
saveAsNew: true,
});

await PageObjects.dashboard.waitForRenderComplete();
await dashboardExpect.metricValuesExist(['14,004']);
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.eql(2);
});
});
}
1 change: 1 addition & 0 deletions test/functional/apps/visualize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./_lab_mode'));
loadTestFile(require.resolve('./_linked_saved_searches'));
loadTestFile(require.resolve('./_visualize_listing'));
loadTestFile(require.resolve('./_add_to_dashboard.ts'));

if (isOss) {
loadTestFile(require.resolve('./_tile_map'));
Expand Down
2 changes: 2 additions & 0 deletions test/functional/page_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { VisualizePageProvider } from './visualize_page';
import { VisualizeEditorPageProvider } from './visualize_editor_page';
import { VisualizeChartPageProvider } from './visualize_chart_page';
import { TileMapPageProvider } from './tile_map_page';
import { TimeToVisualizePageProvider } from './time_to_visualize_page';
import { TagCloudPageProvider } from './tag_cloud_page';
import { VegaChartPageProvider } from './vega_chart_page';
import { SavedObjectsPageProvider } from './management/saved_objects_page';
Expand All @@ -51,6 +52,7 @@ export const pageObjects = {
visEditor: VisualizeEditorPageProvider,
visChart: VisualizeChartPageProvider,
tileMap: TileMapPageProvider,
timeToVisualize: TimeToVisualizePageProvider,
tagCloud: TagCloudPageProvider,
vegaChart: VegaChartPageProvider,
savedObjects: SavedObjectsPageProvider,
Expand Down
Loading