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

[automate-2697] stabilize project mgmt tests #3584

Merged
merged 8 commits into from
May 5, 2020

Conversation

bcmdarroch
Copy link
Contributor

@bcmdarroch bcmdarroch commented May 4, 2020

🔩 Description: What code changed, and why?

Stabilized existing tests and marked them unflaky.
Also broke up project_mgmt into project_mgmt, testing just Projects CRUD, and project_rule_mgmt, testing just Rules CRUD.

This we have Cypress coverage for the Projects GUI section and most of the Project Rules flow.

What's missing is testing the project update in the UI. I'd like to make that it's own test, since it will involve a lot of moving parts: adding some resources to projects, loading some nodes that we'll write rules for, granting a new user project permissions and then having them log in to verify permissions. I've created a new tech debt card for that work.

To run them locally, follow the e2e Readme

👍 Definition of Done

  • project mgmt and project rule mgmt pass buildkite consistently

✅ Checklist

Brenna Hewer-Darroch added 6 commits May 4, 2020 12:30
no more flaky tests :)))

Signed-off-by: Brenna Hewer-Darroch <[email protected]>
Signed-off-by: Brenna Hewer-Darroch <[email protected]>
Signed-off-by: Brenna Hewer-Darroch <[email protected]>
Signed-off-by: Brenna Hewer-Darroch <[email protected]>
Signed-off-by: Brenna Hewer-Darroch <[email protected]>
now two tests, one for project mgmt and one for project rules mgmt

Signed-off-by: Brenna Hewer-Darroch <[email protected]>
@bcmdarroch bcmdarroch force-pushed the bhd/2697/cypress_project_mgmt branch from 9819a32 to a389f7c Compare May 4, 2020 23:23
Brenna Hewer-Darroch added 2 commits May 4, 2020 17:05
Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@@ -58,24 +64,6 @@ describe('global projects filter', () => {
});
});

function cleanupProjects(id_token: string): void {
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 isn't needed since we have our handy cy.cleanupIAMObjectsByIDPrefixes (which also knows how to delete a project's rules before deleting it)


describe('project management', () => {
// we increase the default delay to mimic the average human's typing speed
Copy link
Contributor Author

Choose a reason for hiding this comment

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

decided to drop the typeDelay here. It was added as an early attempt to deflake the tests, since sometimes characters were missed when typing. but we've since found better ways to improve stability, mostly around adding expectations to ensure the page has loaded before interacting with elements.

cy.cleanupIAMObjectsByIDPrefixes(cypressPrefix, ['projects']);

// if there are projects that already exist, set the projects filter to all projects
cy.request({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

might want to turn this into a helper, like clearProjectsFilter

Choose a reason for hiding this comment

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

if we're not doing it here, that would be a helpful comment within the code so as we duplicate the work it stands out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like this is the only instance we're using it, so I'll leave this as is and updatethe comment

});

// something is occasionally resetting the projects filter to (unassigned)
itFlaky('can create a rule for the new project', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved these to project_rule_mgmt

cy.contains(projectName).should('exist');
cy.contains(projectID).should('exist');

cy.url().should('include', '/settings/projects');
});

it('addPolicies checkbox is always checked on modal open', () => {
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 is now just an assertion in can create a project with a custom ID and generate associated policies

cy.wait('@getProjects');

cy.get('app-project-list chef-td').contains(customWithoutPolsProjectID).parent()
.find('.mat-select-trigger').as('controlMenu');
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 always had trouble selecting the right element for the control menu in these tests and getting a successful interaction, but it looks like our mat-select refactor made it easier to target :)

}
});
});

// these tests are currently interdependent so mark as flaky until the above isn't
itFlaky('can create a project with a custom ID', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this up with the other create tests and changed the ID so we wouldn't run into conflicts

@bcmdarroch bcmdarroch marked this pull request as ready for review May 5, 2020 15:55
associatedPolicies.forEach((policy) => {
cy.request({
auth: { bearer: adminIdToken },
url: `/apis/iam/v2/policies/${customWithoutPolsProjectID}-${policy}`,

Choose a reason for hiding this comment

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

this is sort of hard to parse at first glance. I wonder if there's a way to make it clearer?

maybe associatedPolicies -> appendedPolicyIds
policy -> policy_id

and or maybe create a new variable above the request instead of inside it with a new var name? Like autoCreatedPolicyId or something?

🤷

Choose a reason for hiding this comment

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

maybe i'm hung up on associated over autoGenerated? 🙃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

went with a combo of yours and @msorens' suggestions

]
};
// add rule via the API to save time,
// since we test rules more thoroughly in project_rule_mgmt.spec.ts

Choose a reason for hiding this comment

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

🎉

// we throw in a should so cypress retries until introspection allows menu to be shown
cy.get('@controlMenu').should('be.visible')
// we throw in a `should` so cypress retries until introspection allows menu to be shown
cy.get('@controlMenu').scrollIntoView().should('be.visible')

Choose a reason for hiding this comment

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

oooooh scroll into vieewwwww

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah pretty slick 😎 might need to use that in some of our other tests

cy.request({
auth: { bearer: adminIdToken },
method: 'DELETE',
url: `/apis/iam/v2/projects/${customWithoutPolsProjectID}/rules/${rule.id}`

Choose a reason for hiding this comment

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

Should we check for the "Project UPdate" banner?

Choose a reason for hiding this comment

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

(I know we don't want to test the functionality of the banner here, however, and we could remove when we add the fuller update 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.

sure


cy.url().should('include', `/settings/projects/${project.id}`);
cy.get('app-project-details chef-td').contains(ruleID);
cy.get('app-pending-edits-bar').contains('Project edits pending');

Choose a reason for hiding this comment

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

is this the project update banner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I can add a comment

Copy link

@blakestier blakestier left a comment

Choose a reason for hiding this comment

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

Awesome. Thanks for adding new tests along the way! 🤗

I had some clarification questions and one idea about making this a big more readable-- I think all of your inline comments do loads to that end, though.

In general, I wonder if there's a way to make some of these expectations more readable (like

cy.get('app-project-details chef-td').contains(ruleID).parent()
      .find('.mat-select-trigger').as('controlMenu');

doesn't read in a way where I really know what is being verified 🤔) but it's a much bigger dilemma than this PR which fixes all the things and THEN makes new wonderful things.

Copy link
Contributor

@msorens msorens left a comment

Choose a reason for hiding this comment

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

Nice work!! Just a couple suggestions/questions.

cy.get('[data-cy=operator-dropdown]').select('member of');
cy.get('[data-cy=operator-dropdown]').select('equals');
cy.get('[data-cy=rule-value] input').type('Chef Policy Group Foo');
// don't create associated project policies
Copy link
Contributor

Choose a reason for hiding this comment

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

Helpful to provide a bit more context

Suggested change
// don't create associated project policies
// checkbox is selected by default; uncheck so we do NOT create associated project policies

cy.contains(customWithoutPolsProjectID).should('exist');

// verify no associated policies were generated
associatedPolicies.forEach((policy) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This confused me for a moment; would be a bit more clear with this:

Suggested change
associatedPolicies.forEach((policy) => {
associatedPolicySuffixes.forEach(suffix => {

Comment on lines +217 to +219
// navigate back to the project list page and get latest project data
cy.route('GET', '/apis/iam/v2/projects').as('getProjects');
cy.get('.breadcrumb').click();
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Did the CreateRule change the current page? I thought we were on the ListProjects page at the start of this test, but if you are clicking on a breadcrumb, then apparently not...?
  2. Assuming on the project detail page, then, and the breadcrumb click takes us back to the ListProjects page, then why is the explicit projects fetch needed? Isn't that done by the breadcrumb click navigation?

Copy link
Contributor Author

@bcmdarroch bcmdarroch May 5, 2020

Choose a reason for hiding this comment

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

The cy.route line isn't actually fetching the data, it specifies what API call Cypress should wait for on L220 (cy.wait('@getProjects');)

So we return to the list page with the breadcrumb, wait for the ListProjects call to come back, then proceed with the rest of the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants