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

[Discover 2.0 Testing] Create View List of Saved Queries Test (Test-Id 124: View list of Saved query) #9166

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ArgusLi
Copy link
Contributor

@ArgusLi ArgusLi commented Jan 9, 2025

Description

Adds a Cypress test suite for filtering in the Discover page.

Issues Resolved

Closes #8976.

Screenshot

newUICompressed.mp4
oldUICompressed.mp4

Testing the changes

With OSD running, run yarn run cypress open. In E2E specs, you will see 2 new test specs saved_queries.spec.js and saved_queries_old_ui.spec.js. Run saved_queries.spec.js if data.savedQueriesNewUI.enabled: true in the OSD config, else run saved_queries_old_ui.spec.js.

Changelog

  • test: Add cypress integration test for the old and new UI view saved queries.

@ArgusLi ArgusLi changed the title [Discover 2.0 Testing] Create View Saved Queries Test (Test-Id 124: List Saved Queries) [Discover 2.0 Testing] Create View List of Saved Queries Test (Test-Id 124: View list of Saved query) Jan 9, 2025
cy.saveQuery(config.saveName);
});
});
it('should see all saved queries', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need ... for ${config.testName}?

EDIT: Nevermind, it looks like this it is not part of the testConfigurations.forEach(). If so could we add a blank line between 87 and 88 just to make that a bit cle4ar (nitpick comment)

});
it('should see all saved queries', () => {
cy.getElementByTestId('saved-query-management-popover-button').click({
force: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

why is force: true needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had some issues where sometimes just clicking wouldn't open the popover. I will add a comment here to explain.

Copy link
Contributor

Choose a reason for hiding this comment

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

if it was not working but the element not obstructed, i wonder if this works:

cy.getElementByTestId('saved-query-management-popover-button').should('be.visible').click()

(This will ensure it is visible in the DOM before clicking. i wonder if you are attempting to click it before it is visible)

Copy link
Contributor Author

@ArgusLi ArgusLi Jan 10, 2025

Choose a reason for hiding this comment

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

I tried again without the force and it's working now. I think this one leftover from when I was trying to debug an issue. Removing the force.

cy.getElementByTestId('saved-query-management-open-button').click();

//Wait for queries to load
cy.wait(2000);
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of arbitrary 2000, could we wait for some element to be loaded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was left over from when I copied your structure for saved search. It doesn't seem needed for saved queries. Removing.

@@ -0,0 +1,105 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have enough context here, so would love for @ananzh or @LDrago27 's response, but for old_ui, does file need to be in a separate folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a specific flag for saved_queries specifically, my first thought is that it makes sense to just separate the files based on the ui version for now, but if there are any other specs that use the same flag, then putting them into separate folders would be a good idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

i think we split up the running of tests with different configs based on folder structure, so it might be problematic for this to be in the same folder as the new-ui. but again i'll defer to @LDrago27 and @ananzh

default:
throw new Error(`getQueryString encountered unsupported language: ${language}`);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

(I can do this)

But it looks like this and some other functions are exactly the same as mine. I will make some refactor in the future to put them in shared.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've separated this function because I will be needing to make some changes to it and its associated functions for the specific queries in following saved queries tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ArgusLi Lets move all the utils inside to this path /cypress/utils/apps/query_enhancements. That will help us to consolidate the utils method in one place.

@@ -125,33 +125,49 @@ Cypress.Commands.add(
}
);

Cypress.Commands.add('saveQuery', (name, description) => {
Cypress.Commands.add('saveQueryOldUI', (name, description = ' ') => {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we rename this to something else? I dont' have enough context, but what constitutes a 'new ui' vs old ui? I don't like OldUi because in a few months/years, what we consider now to be newUi will become oldUi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The flag is data.savedQueriesNewUI.enabled: false, which is why I named it as such. I agree though. Would love to discuss this offline with @LDrago27.

cy.whenTestIdNotFound('saved-query-management-popover', () => {
cy.getElementByTestId('saved-query-management-popover-button').click();
});
cy.getElementByTestId('saved-query-management-save-button').click();

cy.getElementByTestId('saveQueryFormTitle').type(name);
cy.getElementByTestId('saveQueryFormDescription').type(description);

cy.getElementByTestId('savedQueryFormSaveButton').click({ force: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

why is force needed? Typically, this is only needed if the element is hidden by some other element in the UI (like a popover). if so, then it is valid that it is needed but a comment should be there signifying why it's needed. Else we can just get rid of force: true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is actually left over from some testing. Will reverify and check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Confirmed. Removing.

cy.getElementByTestId('saveQueryFormTitle').type(name);
cy.getElementByTestId('saveQueryFormDescription').type(description);

cy.getElementByTestId('savedQueryFormSaveButton').click({ force: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

same forc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is actually left over from some testing. Will reverify and check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Confirmed, removing.

cy.getElementByTestId('editDatasourceDeleteIcon').click();
cy.getElementByTestId('confirmModalConfirmButton').click();
cy.getElementByTestId('editDatasourceDeleteIcon').click({ force: true });
cy.getElementByTestId('confirmModalConfirmButton').click({ force: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

if we remove deleteDataSourceByName from the other places, these changes don't need to be here. But IF i'm wrong and deleteDataSourceByName needs to be there, two things:

  • lets get rid of cy.wait(2000) and replace it with waiting for some element to exist.
  • Lets get rid of force: true unless its really needed (and if so, add a comment why)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me try again. The reason why this was here is because of some really weird behaviour from Cypress. The deleteSourceByName was initially in the afterEach block, but I changed it to the after block instead. When it was in the afterEach block, when the first saved query was created, it executed perfectly, but would fail the next time it was run after the next saved query was created.

I tried getting the element without a chained click, which would lead to Cypress' timeout and retry logic, but for some reason it still failed. I tried using waitForLoader but that didn't work either, which is when I shifted to the wait. But after that, it still failed when clicking the editDatasourceDeleteIcon button - the button was selected, and was clicked, but no action actually happened. Which is why I had to use force: true. The same thing happened for confirmModalConfirmButton.

But none of these will happen now given it is only run once in the after block so I'll try and see if removing them will work now.

Copy link
Contributor Author

@ArgusLi ArgusLi Jan 10, 2025

Choose a reason for hiding this comment

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

Yup, because it's only run once now, it works without these forces and waits. Removing the wait and forces.

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 61.01%. Comparing base (82689bb) to head (b411dd0).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...lugins/data/public/ui/saved_query_form/helpers.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9166   +/-   ##
=======================================
  Coverage   61.01%   61.01%           
=======================================
  Files        3812     3813    +1     
  Lines       91385    91396   +11     
  Branches    14438    14439    +1     
=======================================
+ Hits        55762    55769    +7     
- Misses      32065    32068    +3     
- Partials     3558     3559    +1     
Flag Coverage Δ
Linux_1 29.08% <ø> (+<0.01%) ⬆️
Linux_2 56.45% <ø> (ø)
Linux_3 38.02% <0.00%> (-0.01%) ⬇️
Linux_4 29.03% <ø> (ø)
Windows_1 29.09% <ø> (+<0.01%) ⬆️
Windows_2 56.40% <ø> (ø)
Windows_3 38.03% <0.00%> (+<0.01%) ⬆️
Windows_4 29.03% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Argus Li <[email protected]>
}
};

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Update the comments to indicate it is for saved queries instead of saved search

Signed-off-by: Argus Li <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Saved Queries] TESTID-124: View list of Saved query
3 participants