Skip to content

Commit fd15268

Browse files
[functional tests] test url field formatter on dashboard and discover (#70736)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent c3cacba commit fd15268

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

test/functional/apps/dashboard/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default function ({ getService, loadTestFile }) {
4949
after(unloadCurrentData);
5050

5151
loadTestFile(require.resolve('./empty_dashboard'));
52+
loadTestFile(require.resolve('./url_field_formatter'));
5253
loadTestFile(require.resolve('./embeddable_rendering'));
5354
loadTestFile(require.resolve('./create_and_add_embeddables'));
5455
loadTestFile(require.resolve('./edit_embeddable_redirects'));
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import expect from '@kbn/expect';
21+
import { WebElementWrapper } from 'test/functional/services/lib/web_element_wrapper';
22+
import { FtrProviderContext } from '../../ftr_provider_context';
23+
24+
export default function ({ getService, getPageObjects }: FtrProviderContext) {
25+
const { common, dashboard, settings, timePicker, visChart } = getPageObjects([
26+
'common',
27+
'dashboard',
28+
'settings',
29+
'timePicker',
30+
'visChart',
31+
]);
32+
const esArchiver = getService('esArchiver');
33+
const kibanaServer = getService('kibanaServer');
34+
const testSubjects = getService('testSubjects');
35+
const browser = getService('browser');
36+
const fieldName = 'clientip';
37+
38+
const clickFieldAndCheckUrl = async (fieldLink: WebElementWrapper) => {
39+
const fieldValue = await fieldLink.getVisibleText();
40+
await fieldLink.click();
41+
const windowHandlers = await browser.getAllWindowHandles();
42+
expect(windowHandlers.length).to.equal(2);
43+
await browser.switchToWindow(windowHandlers[1]);
44+
const currentUrl = await browser.getCurrentUrl();
45+
const fieldUrl = common.getHostPort() + '/app/' + fieldValue;
46+
expect(currentUrl).to.equal(fieldUrl);
47+
};
48+
49+
describe('Changing field formatter to Url', () => {
50+
before(async function () {
51+
await esArchiver.load('dashboard/current/kibana');
52+
await kibanaServer.uiSettings.replace({
53+
defaultIndex: '0bf35f60-3dc9-11e8-8660-4d65aa086b3c',
54+
});
55+
await common.navigateToApp('settings');
56+
await settings.clickKibanaIndexPatterns();
57+
await settings.clickIndexPatternLogstash();
58+
await settings.filterField(fieldName);
59+
await settings.openControlsByName(fieldName);
60+
await settings.setFieldFormat('url');
61+
await settings.controlChangeSave();
62+
});
63+
64+
it('applied on dashboard', async () => {
65+
await common.navigateToApp('dashboard');
66+
await dashboard.loadSavedDashboard('dashboard with everything');
67+
await dashboard.waitForRenderComplete();
68+
const fieldLink = await visChart.getFieldLinkInVisTable(`${fieldName}: Descending`, 1);
69+
await clickFieldAndCheckUrl(fieldLink);
70+
});
71+
72+
it('applied on discover', async () => {
73+
await common.navigateToApp('discover');
74+
await timePicker.setAbsoluteRange(
75+
'Sep 19, 2017 @ 06:31:44.000',
76+
'Sep 23, 2018 @ 18:31:44.000'
77+
);
78+
await testSubjects.click('docTableExpandToggleColumn');
79+
const fieldLink = await testSubjects.find(`tableDocViewRow-${fieldName}-value`);
80+
await clickFieldAndCheckUrl(fieldLink);
81+
});
82+
83+
afterEach(async function () {
84+
const windowHandlers = await browser.getAllWindowHandles();
85+
if (windowHandlers.length > 1) {
86+
await browser.closeCurrentWindow();
87+
await browser.switchToWindow(windowHandlers[0]);
88+
}
89+
});
90+
});
91+
}

test/functional/page_objects/visualize_chart_page.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,20 @@ export function VisualizeChartPageProvider({ getService, getPageObjects }: FtrPr
302302
return element.getVisibleText();
303303
}
304304

305+
public async getFieldLinkInVisTable(fieldName: string, rowIndex: number = 1) {
306+
const tableVis = await testSubjects.find('tableVis');
307+
const $ = await tableVis.parseDomContent();
308+
const headers = $('span[ng-bind="::col.title"]')
309+
.toArray()
310+
.map((header: any) => $(header).text());
311+
const fieldColumnIndex = headers.indexOf(fieldName);
312+
return await find.byCssSelector(
313+
`[data-test-subj="paginated-table-body"] tr:nth-of-type(${rowIndex}) td:nth-of-type(${
314+
fieldColumnIndex + 1
315+
}) a`
316+
);
317+
}
318+
305319
/**
306320
* If you are writing new tests, you should rather look into getTableVisContent method instead.
307321
* @deprecated Use getTableVisContent instead.

0 commit comments

Comments
 (0)