From daffde599273833cba301fc197b98584678231dd Mon Sep 17 00:00:00 2001 From: "Eyo O. Eyo" <7893459+eokoneyo@users.noreply.github.com> Date: Wed, 13 Mar 2024 18:36:36 +0100 Subject: [PATCH] [8.13] Fix how sample data test install state is determined in test (#178529) (#178601) # Backport This will backport the following commits from `main` to `8.13`: - [Fix how sample data test install state is determined in test (#178529)](https://github.com/elastic/kibana/pull/178529) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) \r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n","sha":"910188e4e0baf6b2dbfbab88f4f4466a077f87c2","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","backport:skip","Team:SharedUX","v8.13.0","v8.14.0"],"number":178529,"url":"https://github.com/elastic/kibana/pull/178529","mergeCommit":{"message":"Fix how sample data test install state is determined in test (#178529)\n\n## Summary\r\nCloses https://github.com/elastic/kibana/issues/112103\r\n\r\nMake sample data install status available to be read by test util, as\r\ndocumented by @gsoldevila in the issue referenced above. The issue\r\nhappens because there's a slight delay that really can't be walked\r\naround where the install status in this particular instance is still\r\n'installed' but the call to mark the sample data completes so there's\r\nthat flicker where the `remove` element is displayed momentarily because\r\nthe component doesn't quite received the update to the sample data's\r\ninstall status immediately.\r\n\r\nThe proposed fix opts to complement the current way of determining if\r\nany sample data is installed using the newly introduced `data-status`\r\nattribute, here we wait till the result of clicking the remove button\r\nactually triggers a change in the value of the install state of said\r\nsample data, which in turn is reflected in the value of `data-status`\r\nalongside checking that the remove button exists.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n","sha":"910188e4e0baf6b2dbfbab88f4f4466a077f87c2"}},"sourceBranch":"main","suggestedTargetBranches":["8.13"],"targetPullRequestStates":[{"branch":"8.13","label":"v8.13.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.14.0","labelRegex":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/178529","number":178529,"mergeCommit":{"message":"Fix how sample data test install state is determined in test (#178529)\n\n## Summary\r\nCloses https://github.com/elastic/kibana/issues/112103\r\n\r\nMake sample data install status available to be read by test util, as\r\ndocumented by @gsoldevila in the issue referenced above. The issue\r\nhappens because there's a slight delay that really can't be walked\r\naround where the install status in this particular instance is still\r\n'installed' but the call to mark the sample data completes so there's\r\nthat flicker where the `remove` element is displayed momentarily because\r\nthe component doesn't quite received the update to the sample data's\r\ninstall status immediately.\r\n\r\nThe proposed fix opts to complement the current way of determining if\r\nany sample data is installed using the newly introduced `data-status`\r\nattribute, here we wait till the result of clicking the remove button\r\nactually triggers a change in the value of the install state of said\r\nsample data, which in turn is reflected in the value of `data-status`\r\nalongside checking that the remove button exists.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n","sha":"910188e4e0baf6b2dbfbab88f4f4466a077f87c2"}}]}] BACKPORT--> --- .../sample_data_card.test.tsx.snap | 165 ++++++++++-------- .../sample_data_card/src/footer/index.tsx | 30 +++- test/functional/page_objects/home_page.ts | 5 +- .../tests/browser.ts | 3 +- 4 files changed, 117 insertions(+), 86 deletions(-) diff --git a/packages/home/sample_data_card/src/__snapshots__/sample_data_card.test.tsx.snap b/packages/home/sample_data_card/src/__snapshots__/sample_data_card.test.tsx.snap index 269499f65547a..76a56fb33c5e4 100644 --- a/packages/home/sample_data_card/src/__snapshots__/sample_data_card.test.tsx.snap +++ b/packages/home/sample_data_card/src/__snapshots__/sample_data_card.test.tsx.snap @@ -57,56 +57,61 @@ exports[`SampleDataCard installed renders with app links 1`] = ` class="emotion-euiCard__footer" >
- -
-
+
+
+ +
+
@@ -171,47 +176,52 @@ exports[`SampleDataCard installed renders without app links 1`] = ` class="emotion-euiCard__footer" >
- -
-
-
+
- - View data + + View data + - - + +
@@ -265,27 +275,32 @@ exports[`SampleDataCard not installed renders 1`] = ` class="emotion-euiCard__footer" >
- + +
diff --git a/packages/home/sample_data_card/src/footer/index.tsx b/packages/home/sample_data_card/src/footer/index.tsx index 3ef415d07c507..eaf00c8198b7e 100644 --- a/packages/home/sample_data_card/src/footer/index.tsx +++ b/packages/home/sample_data_card/src/footer/index.tsx @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import React from 'react'; +import React, { useCallback } from 'react'; import { SampleDataSet, InstalledStatus } from '@kbn/home-sample-data-types'; import { INSTALLED_STATUS, UNINSTALLED_STATUS } from '../constants'; @@ -28,13 +28,27 @@ export interface Props { * Displays the appropriate Footer component based on the status of the Sample Data Set. */ export const Footer = ({ sampleDataSet, onAction }: Props) => { - if (sampleDataSet.status === INSTALLED_STATUS) { - return onAction(id, UNINSTALLED_STATUS)} {...sampleDataSet} />; - } + const renderContent = useCallback(() => { + if (sampleDataSet.status === INSTALLED_STATUS) { + return ( + onAction(id, UNINSTALLED_STATUS)} {...sampleDataSet} /> + ); + } - if (sampleDataSet.status === UNINSTALLED_STATUS) { - return onAction(id, INSTALLED_STATUS)} {...sampleDataSet} />; - } + if (sampleDataSet.status === UNINSTALLED_STATUS) { + return ( + onAction(id, INSTALLED_STATUS)} {...sampleDataSet} /> + ); + } - return ; + return ; + }, [onAction, sampleDataSet]); + + return ( + // the data-status attribute is added to solve issues with failing test, + // see https://github.com/elastic/kibana/issues/112103 +
+ {renderContent()} +
+ ); }; diff --git a/test/functional/page_objects/home_page.ts b/test/functional/page_objects/home_page.ts index 1901f12073438..4225f52b16994 100644 --- a/test/functional/page_objects/home_page.ts +++ b/test/functional/page_objects/home_page.ts @@ -48,9 +48,12 @@ export class HomePageObject extends FtrService { async isSampleDataSetInstalled(id: string) { const sampleDataCard = await this.testSubjects.find(`sampleDataSetCard${id}`); + const installStatus = await ( + await sampleDataCard.findByCssSelector('[data-status]') + ).getAttribute('data-status'); const deleteButton = await sampleDataCard.findAllByTestSubject(`removeSampleDataSet${id}`); this.log.debug(`Sample data installed: ${deleteButton.length > 0}`); - return deleteButton.length > 0; + return installStatus === 'installed' && deleteButton.length > 0; } async isWelcomeInterstitialDisplayed() { diff --git a/x-pack/test/functional_execution_context/tests/browser.ts b/x-pack/test/functional_execution_context/tests/browser.ts index 63f575b798b93..f7d265316decb 100644 --- a/x-pack/test/functional_execution_context/tests/browser.ts +++ b/x-pack/test/functional_execution_context/tests/browser.ts @@ -12,8 +12,7 @@ import { assertLogContains, isExecutionContextLog, readLogFile } from '../test_u export default function ({ getService, getPageObjects }: FtrProviderContext) { const PageObjects = getPageObjects(['common', 'dashboard', 'header', 'home', 'timePicker']); - // FLAKY: https://github.com/elastic/kibana/issues/112103 - describe.skip('Browser apps', () => { + describe('Browser apps', () => { let logs: Ecs[]; const retry = getService('retry');