Skip to content

Commit

Permalink
Fix how sample data test install state is determined in test (#178529)
Browse files Browse the repository at this point in the history
## Summary
Closes #112103

Make sample data install status available to be read by test util, as
documented by @gsoldevila in the issue referenced above. The issue
happens because there's a slight delay that really can't be walked
around where the install status in this particular instance is still
'installed' but the call to mark the sample data completes so there's
that flicker where the `remove` element is displayed momentarily because
the component doesn't quite received the update to the sample data's
install status immediately.

The proposed fix opts to complement the current way of determining if
any sample data is installed using the newly introduced `data-status`
attribute, here we wait till the result of clicking the remove button
actually triggers a change in the value of the install state of said
sample data, which in turn is reflected in the value of `data-status`
alongside checking that the remove button exists.

### Checklist
<!--
Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials -->
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
<!--
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
-->

(cherry picked from commit 910188e)
  • Loading branch information
eokoneyo committed Mar 13, 2024
1 parent 4117bf9 commit f319a02
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 86 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 22 additions & 8 deletions packages/home/sample_data_card/src/footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 <RemoveFooter onRemove={(id) => onAction(id, UNINSTALLED_STATUS)} {...sampleDataSet} />;
}
const renderContent = useCallback(() => {
if (sampleDataSet.status === INSTALLED_STATUS) {
return (
<RemoveFooter onRemove={(id) => onAction(id, UNINSTALLED_STATUS)} {...sampleDataSet} />
);
}

if (sampleDataSet.status === UNINSTALLED_STATUS) {
return <InstallFooter onInstall={(id) => onAction(id, INSTALLED_STATUS)} {...sampleDataSet} />;
}
if (sampleDataSet.status === UNINSTALLED_STATUS) {
return (
<InstallFooter onInstall={(id) => onAction(id, INSTALLED_STATUS)} {...sampleDataSet} />
);
}

return <DisabledFooter {...sampleDataSet} />;
return <DisabledFooter {...sampleDataSet} />;
}, [onAction, sampleDataSet]);

return (
// the data-status attribute is added to solve issues with failing test,
// see https://github.com/elastic/kibana/issues/112103
<div data-status={sampleDataSet.status} style={{ display: 'contents' }}>
{renderContent()}
</div>
);
};
5 changes: 4 additions & 1 deletion test/functional/page_objects/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 1 addition & 2 deletions x-pack/test/functional_execution_context/tests/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit f319a02

Please sign in to comment.