From 83b4b4568cd4264e7f02e209634cedbd29cc2f12 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Mon, 14 Oct 2019 09:37:05 +0200 Subject: [PATCH] Fix visualize app chart type test (#47807) * Add method to detect oss in settings pages - if it's not OSS, than 'Maps' is added to the expected chart types Co-authored-by: liza-mae --- .../{_chart_types.js => _chart_types.ts} | 19 +++++++++++++----- test/functional/page_objects/common_page.js | 20 ++++++++++++++++++- 2 files changed, 33 insertions(+), 6 deletions(-) rename test/functional/apps/visualize/{_chart_types.js => _chart_types.ts} (74%) diff --git a/test/functional/apps/visualize/_chart_types.js b/test/functional/apps/visualize/_chart_types.ts similarity index 74% rename from test/functional/apps/visualize/_chart_types.js rename to test/functional/apps/visualize/_chart_types.ts index 79ea326ad982..5a3c54ccff1f 100644 --- a/test/functional/apps/visualize/_chart_types.js +++ b/test/functional/apps/visualize/_chart_types.ts @@ -18,18 +18,22 @@ */ import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService, getPageObjects }) { +// eslint-disable-next-line import/no-default-export +export default function({ getService, getPageObjects }: FtrProviderContext) { const log = getService('log'); const PageObjects = getPageObjects(['common', 'visualize']); + let isOss = true; - describe('chart types', function () { - before(function () { + describe('chart types', function() { + before(async function() { log.debug('navigateToApp visualize'); - return PageObjects.visualize.navigateToNewVisualization(); + isOss = await PageObjects.common.isOss(); + await PageObjects.visualize.navigateToNewVisualization(); }); - it('should show the correct chart types', async function () { + it('should show the correct chart types', async function() { const expectedChartTypes = [ 'Area', 'Controls', @@ -50,6 +54,11 @@ export default function ({ getService, getPageObjects }) { 'Vega', 'Vertical Bar', ]; + if (!isOss) { + expectedChartTypes.push('Maps'); + expectedChartTypes.sort(); + } + log.debug('oss= ' + isOss); // find all the chart types and make sure there all there const chartTypes = await PageObjects.visualize.getChartTypes(); diff --git a/test/functional/page_objects/common_page.js b/test/functional/page_objects/common_page.js index bcd9cb3c11d8..5320ba978cbe 100644 --- a/test/functional/page_objects/common_page.js +++ b/test/functional/page_objects/common_page.js @@ -19,7 +19,7 @@ import { delay } from 'bluebird'; import expect from '@kbn/expect'; - +import fetch from 'node-fetch'; import getUrl from '../../../src/test_utils/get_url'; export function CommonPageProvider({ getService, getPageObjects }) { @@ -405,6 +405,24 @@ export function CommonPageProvider({ getService, getPageObjects }) { return await jsonElement.getVisibleText(); } } + + /** + * Helper to detect an OSS licensed Kibana + * Useful for functional testing in cloud environment + */ + async isOss() { + const baseUrl = this.getEsHostPort(); + const username = config.get('servers.elasticsearch.username'); + const password = config.get('servers.elasticsearch.password'); + const response = await fetch(baseUrl + '/_xpack', { + method: 'get', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Basic ' + Buffer.from(username + ':' + password).toString('base64') + }, + }); + return response.status !== 200; + } } return new CommonPage();