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

test(cypress): notification history tests #2816

Merged
merged 12 commits into from
Oct 18, 2021

Conversation

karel-rehor
Copy link
Contributor

Adds tests of the Notification history page accessible from a Notification Rule

  • New group notification history
    • Shows and filters history
    • Refreshes history
    • Switches between local and UTC time
  • Support commands
    • In Utils timestamp calculator
    • In commands
      • More general replacement for createRule
      • Modified LP writing commands to make use of named buckets, e.g. can write notification records directly to _monitoring bucket.

@karel-rehor karel-rehor requested a review from a team as a code owner October 6, 2021 14:45
@ui-ci-bot-influx
Copy link

ui-ci-bot-influx commented Oct 6, 2021

Metric Score Level
performance 58 🔴
accessibility 96 🟢
seo 90 🟢
pwa null 💩
best-practices 100 🟢

Compare your scores with master branch

Copy link
Contributor

@genehynson genehynson left a comment

Choose a reason for hiding this comment

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

left some comments. I appreciate the thoroughness of these tests! I think we should consider using testIDs instead of css class names though and need to be carful that we're handling cypress chainable promises correctly

cy.writeLPData({lines: [lp], offset: offset, namedBucket: '_monitoring'})
}

beforeEach('Generate alert records', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I've seen flaky tests in the past from beforeEach functions that don't handle async functions & promises. I think we should refactor this to use cypress chaining (cy.xyz().then(() => cy.abc().then(() => ...) to make sure the beforeEach doesn't finish prematurely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generalized this to a localInit() method that returns CypressChainable. It's at the start of the chain. It handles a lot of local data. It is probably too specific to warrant being generalized into a command.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, looks much better. You could move it back into a beforeEach to avoid having to call it in each test. As long as the code within the beforeEach returns a Cypress chainable object, it will wait for completion before starting the test. But this implementation is fine too.

}
})
// verify first row
cy.get('[class$=ScrollContainer] > div:nth-of-type(1)').within(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason we aren't using testIDs here? I find being dependent on CSS class names to be an issue because those change pretty often. We're working on a pretty major overhaul of Clockface which will probably change most CSS class names and this test will have to be completely re-written. If we use testIDs, we don't have that issue

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 agree, data-testid values are preferable because theoretically less prone to change. However, when investigating the Check Statuses page, I could find no data-testid attributes below data-testid='page-contents'. Coming from QA, I'm hesitant to modify code in the application under test, in other words to insert data-testid attributes into the page. However, if you have no problem with this, I'll go ahead and do it and then modify the test code accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think we should add the testID attributes if you don't mind. Most of the Clockface components come with generic testIDs for free. But if one is missing, adding it to the component here in the UI repo is the right move. Sorry to suggest so much refactoring...but I know this Clockface overhaul is coming soon and a lot of these CSS classes will change so it's important that we use testIDs for new tests

// ...To Check
cy.getByTestID('overlay').should('not.exist')
cy.get(
'[class$=ScrollContainer] > div:nth-of-type(4) .event-row--field:nth-of-type(3) > a'
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a great example where a testID should be used. It's really hard to tell what you're trying to click on here just by reading through the test code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. But will need to add the data-testid attributes myself. See response to comment on line 545.

rec.statusTimestamp
},_message="${rec.message.replace(/ /g, ' ')}",dead="true"`

cy.writeLPData({lines: [lp], offset: offset, namedBucket: '_monitoring'})
Copy link
Contributor

Choose a reason for hiding this comment

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

change to return cy.writeLPData(...). because cy.writeLPData is async, we need to return the chainable object here to handle the promise correctly

},
'20m'
)
writeMonitoringRecord(
Copy link
Contributor

Choose a reason for hiding this comment

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

this function is technically async because cy.writeLPData is async. So we need to chain off of it like writeMonitoringRecord(...).then(() => ...

Comment on lines 717 to 718
// N.B. if local === utc then skip
if (new Date().getTimezoneOffset() !== 0) {
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 this we could modify package.json scripts to set the TZ variable like this: cypress-io/cypress#1043 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied this change. First run of monitor-ci failed on the local to UTC switch test. Second run passed. So, I'm a bit suspicious of whether this will be a stable change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah rats ok. We have a new ability in our pipeline to run tests 20x so we could do that to check for flakiness before merging.

cypress/support/commands.ts Outdated Show resolved Hide resolved
@genehynson
Copy link
Contributor

@karel-rehor I did some work today to get the pipeline to set the TZ variable. I merged everything in so you should be good to try and run this again. I also think we should probably undo the changes to package.json so that developers can experience the tests running in their local timezone when running locally. I was able to set the TZ variable in the pipeline definition itself, outside of this configuration. Let me know if it doesn't work. Thanks!

@karel-rehor
Copy link
Contributor Author

karel-rehor commented Oct 15, 2021

@genehynson - I've rerun this five or six times today and each run has passed. I've just restored the beforeEach block and removed the localInit() function, which felt a bit of a hack and an anti-pattern. It looks like The TZ variable in the pipeline works. It has been removed from scripts in package.json. Still, it could be run in the 20 times loop you've mentioned to be sure of stability, before merging,.

Copy link
Contributor

@genehynson genehynson left a comment

Choose a reason for hiding this comment

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

thanks again for this work! lgtm. I checked into our Cypress dashboard and it looks like it is not reporting these new tests as flaky (yay!) so you are good to merge without needing to run it 20x.

@karel-rehor karel-rehor merged commit defe1c4 into influxdata:master Oct 18, 2021
@karel-rehor karel-rehor deleted the cypress/alert-expr branch October 18, 2021 07:44
Dfldr pushed a commit that referenced this pull request Oct 26, 2021
* chore: update create check for e2e test

* test: start cypress notification history tests

* test: add asserts, and refresh notification history test

* test: tidy new notification history test

* test: improve chaining of async calls in notification tests and set timezone for tests

* test: add data test ids to event table

* chore: lint and prettify recently changed files

* chore: remove TZ argument from package.json scripts

* chore: restore beforeEach with return val
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.

3 participants