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

[Cloud Security] 10973 migrate flaky e2e tests to jest #208345

Merged
merged 10 commits into from
Jan 30, 2025

Conversation

alexreal1314
Copy link
Contributor

@alexreal1314 alexreal1314 commented Jan 27, 2025

Summary

This PR tries to fix the following issues - which are flaky FTR tests:

There will be an RFC document which is going to be released to help us better understand and decide which tests are more suitable to make as E2E tests and which as unit tests.

Checklist

Closes

this PR closes the above mentioned issues in relation for this ticket - https://github.com/elastic/security-team/issues/10973

@alexreal1314 alexreal1314 force-pushed the 10973-migrate-flaky-e2e-tests-to-jest branch 4 times, most recently from 89b295b to 25177ad Compare January 29, 2025 09:09
@alexreal1314 alexreal1314 added ci:cloud-deploy Create or update a Cloud deployment and removed ci:cloud-deploy Create or update a Cloud deployment labels Jan 29, 2025
@alexreal1314 alexreal1314 marked this pull request as ready for review January 29, 2025 19:24
@alexreal1314 alexreal1314 requested review from a team as code owners January 29, 2025 19:24
@alexreal1314 alexreal1314 self-assigned this Jan 29, 2025
@alexreal1314 alexreal1314 added the Team:Cloud Security Cloud Security team related label Jan 29, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-cloud-security-posture (Team:Cloud Security)

@alexreal1314 alexreal1314 changed the title 10973 migrate flaky e2e tests to jest [Cloud Security] 10973 migrate flaky e2e tests to jest Jan 29, 2025
@alexreal1314 alexreal1314 added backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes labels Jan 29, 2025
@elasticmachine
Copy link
Contributor

elasticmachine commented Jan 29, 2025

💔 Build Failed

Failed CI Steps

History

cc @alexreal1314

@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Jan 30, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@alexreal1314 alexreal1314 force-pushed the 10973-migrate-flaky-e2e-tests-to-jest branch from 2edd63d to c1c07e2 Compare January 30, 2025 09:03
@alexreal1314 alexreal1314 merged commit cd9096c into main Jan 30, 2025
8 checks passed
@alexreal1314 alexreal1314 deleted the 10973-migrate-flaky-e2e-tests-to-jest branch January 30, 2025 14:23

it('Vulnerabilities - `Add Wiz integration`: should have link element to CNVM integration installation page', async () => {
await waitFor(() =>
expect(screen.getByText(/Already using a\s+cloud security product?/i)).toBeInTheDocument()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexreal1314 checking the exact text makes the test quite brittle. Every change to the wording would mean a failing test. Ideally, we should adda test id for every selector we use in the tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxcold agree, I'll convert it to test id in the next PR that should fix some more flaky tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxcold I see your point about avoiding brittle tests due to wording changes, and I agree that test IDs can provide a stable way to locate elements. However, I believe there’s value in also asserting visible text, especially for key user-facing elements.

Relying solely on test IDs can make tests less reflective of the real user experience since test IDs are not part of what the user actually interacts with. By checking for meaningful text in assertions (like in this case with getByText), we ensure that the UI presents the correct messaging, which is a crucial part of user expectations.

A balanced approach could be to use test IDs for structural assertions (e.g., ensuring an element exists or checking attributes like href), while still verifying key text content where appropriate. In this case, the assertion for the message ensures that users see the correct prompt, while the button's testId allows for stable selection.

What do you think about maintaining a mix of both approaches based on what’s being tested rather than applying test IDs universally?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@opauloh I think tests should avoid testing implementation details. For me the litmus test of a good test is when I change the implementation and the test is still green if the business logic didn't change. In the case of the wording, you will be updating test with every wording change. Another way to check if it makes sense is to push it to the absurd level: imagine we test for every visible text in Kibana, does it make sense to you? I believe it will make tests maintenance unbearable.

Plus you don't test for what's really important when it comes to texts anyway. Does it have typos? Does it provide outdated information that is not relevant anymore? etc.
Maybe in the future with the help of AI we will be testing texts in the way it makes sense, eg. screen.prompt('check that text promoting connecting existing 3p product integration is present ') But we are not there yet :)

* 2.0.
*/

export const testSubjectIds = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice initiative concentrating the test subject ids!


it('Vulnerabilities - `Add Wiz integration`: should have link element to CNVM integration installation page', async () => {
await waitFor(() =>
expect(screen.getByText(/Already using a\s+cloud security product?/i)).toBeInTheDocument()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxcold I see your point about avoiding brittle tests due to wording changes, and I agree that test IDs can provide a stable way to locate elements. However, I believe there’s value in also asserting visible text, especially for key user-facing elements.

Relying solely on test IDs can make tests less reflective of the real user experience since test IDs are not part of what the user actually interacts with. By checking for meaningful text in assertions (like in this case with getByText), we ensure that the UI presents the correct messaging, which is a crucial part of user expectations.

A balanced approach could be to use test IDs for structural assertions (e.g., ensuring an element exists or checking attributes like href), while still verifying key text content where appropriate. In this case, the assertion for the message ensures that users see the correct prompt, while the button's testId allows for stable selection.

What do you think about maintaining a mix of both approaches based on what’s being tested rather than applying test IDs universally?

This was referenced Feb 2, 2025
@alexreal1314 alexreal1314 added backport:8.18 and removed backport:skip This commit does not require backporting labels Feb 11, 2025
alexreal1314 added a commit that referenced this pull request Feb 12, 2025
…210746)

# Backport

This will backport the following commits from `main` to `8.x`:
 - #208345)


### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Feb 13, 2025
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

13 similar comments
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 208345 locally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport missing Added to PRs automatically when the are determined to be missing a backport. backport:8.18 release_note:skip Skip the PR/issue when compiling release notes Team:Cloud Security Cloud Security team related Team:Fleet Team label for Observability Data Collection Fleet team v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants