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

When updating an alert, don't also update the question #36866

Merged
merged 16 commits into from Jan 3, 2024

Conversation

rafpaf
Copy link
Contributor

@rafpaf rafpaf commented Dec 15, 2023

Fixes #36395

Description

On master, when you edit an alert, an additional PUT request is to send to update the card. This is not needed, because you can't edit an alert without first saving the question. On this branch, this request is not done.

How to verify

On master:

  1. Set up a new card and a new alert
  2. Edit the alert
  3. Note in the DevTools Network tab the PUT request to /api/card/:id

On this branch, do the same thing and note that there is no additional request.

Demos

Checklist

  • Tests have been added/updated to cover changes in this PR

Since this PR removes unneeded functionality, I haven't written a test for this. Of course, reviewers, please let me know if you think a test would make sense here. I've now written a test, per @npfitz's request.

@rafpaf rafpaf added the backport Automatically create PR on current release branch on merge label Dec 15, 2023
@rafpaf rafpaf self-assigned this Dec 15, 2023
@metabase-bot metabase-bot bot added the .Team/AdminWebapp Admin and Webapp team label Dec 15, 2023
@rafpaf rafpaf requested review from qnkhuat, a team and npfitz and removed request for a team December 15, 2023 18:55
@rafpaf rafpaf marked this pull request as ready for review December 15, 2023 18:56
@rafpaf rafpaf removed the .Team/AdminWebapp Admin and Webapp team label Dec 15, 2023
Copy link

cypress bot commented Dec 15, 2023

55 failed tests on run #742 ↗︎

55 742 69 2 Flakiness 0

Details:

When updating an alert, don't also update the question
Project: Metabase e2e Commit: 5d78ddb0af
Status: Failed Duration: 19:53 💡
Started: Dec 21, 2023 3:26 AM Ended: Dec 21, 2023 3:46 AM
Failed  visualizations-tabular/object_detail.cy.spec.js • 6 failed tests • visualizations-tabular

View Output

Test Artifacts
Object Detail > composite keys (postgres) > can show object detail modal for items with composite keys Test Replay Screenshots
Object Detail > composite keys (postgres) > cannot navigate past the end of the list of objects with the keyboard Test Replay Screenshots
Object Detail > no primary keys (postgres) > can show object detail modal for items with no primary key Test Replay Screenshots
Object Detail > composite keys (mysql) > can show object detail modal for items with composite keys Test Replay Screenshots
Object Detail > composite keys (mysql) > cannot navigate past the end of the list of objects with the keyboard Test Replay Screenshots
Object Detail > no primary keys (mysql) > can show object detail modal for items with no primary key Test Replay Screenshots
Failed  actions/actions-on-dashboards.cy.spec.js • 25 failed tests • actions

View Output

Test Artifacts
Write Actions on Dashboards (mysql) > adding and executing actions > adds a custom query action to a dashboard and runs it Test Replay Screenshots
Write Actions on Dashboards (mysql) > adding and executing actions > adds an implicit create action to a dashboard and runs it Test Replay Screenshots
Write Actions on Dashboards (mysql) > adding and executing actions > adds an implicit update action to a dashboard and runs it Test Replay Screenshots
Write Actions on Dashboards (mysql) > adding and executing actions > adds an implicit delete action to a dashboard and runs it Test Replay Screenshots
... > adds an implicit action and runs it Test Replay Screenshots
... > adds a query action and runs it Test Replay Screenshots
Write Actions on Dashboards (mysql) > Actions Data Types > can update various data types via implicit actions Test Replay Screenshots
Write Actions on Dashboards (mysql) > Actions Data Types > can insert various data types via implicit actions Test Replay Screenshots
Write Actions on Dashboards (mysql) > Actions Data Types > does not show json, enum, or binary columns for implicit actions Test Replay Screenshots
Write Actions on Dashboards (mysql) > Actions Data Types > properly loads and updates date and time fields for implicit update actions Test Replay Screenshots
The first 10 failed tests are shown, see all 25 tests in Cypress Cloud.
Failed  actions/model-actions.cy.spec.js • 10 failed tests • actions

View Output

Test Artifacts
scenarios > models > actions > should allow to create an action with the New button Test Replay Screenshots
scenarios > models > actions > should respect permissions Test Replay Screenshots
Write actions on model detail page (postgres) > should allow public sharing of actions and execution of public actions Test Replay Screenshots
Write actions on model detail page (postgres) > should allow query action execution from the model details page Test Replay Screenshots
Write actions on model detail page (postgres) > should allow public sharing of query action and execution Test Replay Screenshots
Write actions on model detail page (postgres) > should allow public sharing of implicit action and execution Test Replay Screenshots
Write actions on model detail page (mysql) > should allow public sharing of actions and execution of public actions Test Replay Screenshots
Write actions on model detail page (mysql) > should allow query action execution from the model details page Test Replay Screenshots
Write actions on model detail page (mysql) > should allow public sharing of query action and execution Test Replay Screenshots
Write actions on model detail page (mysql) > should allow public sharing of implicit action and execution Test Replay Screenshots
Failed  admin/databases/add-new-database.cy.spec.js • 2 failed tests • mongo

View Output

Test Artifacts
admin > database > add > external databases > should add Mongo database and redirect to listing Test Replay Screenshots
admin > database > add > external databases > should add Mongo database via the connection string Test Replay Screenshots
Failed  sharing/public-sharing.cy.spec.js • 1 failed test • sharing

View Output

Test Artifacts
scenarios > admin > settings > public sharing > should see public actions Test Replay Screenshots

The first 5 failed specs are shown, see all 11 specs in Cypress Cloud.

Review all test suite changes for PR #36866 ↗︎

npfitz
npfitz previously requested changes Dec 15, 2023
Copy link
Contributor

@npfitz npfitz left a comment

Choose a reason for hiding this comment

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

The change looks good, but do you think we can add some e2e test coverage for this? We may be able to add a test in email-alert.cy.spec.js without much hassle.

@perivamsi
Copy link
Contributor

dont think this needs to be backported?

@darksciencebase darksciencebase added the .Team/AdminWebapp Admin and Webapp team label Dec 18, 2023
@rafpaf rafpaf added no-backport Do not backport this PR to any branch and removed backport Automatically create PR on current release branch on merge labels Dec 18, 2023
@rafpaf
Copy link
Contributor Author

rafpaf commented Dec 18, 2023

dont think this needs to be backported?

@perivamsi: I previously labeled this bugfix with backport, based on the advice here, but following your guidance I've now labeled this no-backport.


cy.log("Change the frequency of the alert to weekly");

cy.get(".Modal--full").within(() => {
Copy link
Contributor Author

@rafpaf rafpaf Dec 19, 2023

Choose a reason for hiding this comment

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

Another approach would be to add some attributes to this full-page modal, such as role="dialog" and aria-labelledby="Edit your alert" – or rather, the modal could have a name as a prop, and then we'd do aria-labelledby={name} – and then we could do cy.findByRole('dialog', {name: "Edit your alert"}), which is more user-centric. I'd be glad to do that, if reviewers prefer.

For now, I've gone with a simpler approach. I see the codebase already uses cy.get('.Modal--full') a few times, like here.

Related Slack thread and here's another

Copy link
Contributor

Choose a reason for hiding this comment

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

good questions!

  • cy.get() is strongly discouraged. it exists in older tests, we shouldn't copy that pattern.
  • accessible roles and other attributes that play nicely with react testing library are highly favored, but there are some existing helpers and tests that rely on a single "dialog" role being present, so if you're in a situation with multiple dialogs it could get messy.
  • the easiest and safest option from a testing standpoint is using data-testid, it makes tests nice and easy to read because you can make it very specific, it's always safe to add, it's most likely to be stable, but it doesn't add any nice accessibility feature to the application.

TLDR be very bold:
200w

Copy link
Contributor Author

Choose a reason for hiding this comment

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

accessible roles and other attributes that play nicely with react testing library are highly favored, but there are some existing helpers and tests that rely on a single "dialog" role being present, so if you're in a situation with multiple dialogs it could get messy.

I went ahead and tidied up some of the messiness around testing modals. The tidying happens in this new refactoring PR. This "When updating an alert" PR now uses that refactoring PR as its base.

Copy link
Contributor

@iethree iethree left a comment

Choose a reason for hiding this comment

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

Looks good! 🏆

Some suggestions for improving the test.

e2e/test/scenarios/sharing/alert/email-alert.cy.spec.js Outdated Show resolved Hide resolved
e2e/test/scenarios/sharing/alert/email-alert.cy.spec.js Outdated Show resolved Hide resolved
e2e/test/scenarios/sharing/alert/email-alert.cy.spec.js Outdated Show resolved Hide resolved
e2e/test/scenarios/sharing/alert/email-alert.cy.spec.js Outdated Show resolved Hide resolved
rafpaf added a commit that referenced this pull request Dec 21, 2023
@rafpaf rafpaf changed the base branch from master to rkl/refactor-modals December 21, 2023 02:28
@rafpaf rafpaf requested a review from iethree December 21, 2023 02:34
const { modifiedAlert } = this.state;

await apiUpdateQuestion();
Copy link
Contributor Author

@rafpaf rafpaf Dec 21, 2023

Choose a reason for hiding this comment

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

This is the core behavioral change in this PR: when we update an alert, we shouldn't also update the question.

In the past, it might have made sense to automatically update the question when the alert is updated. But I think it no longer makes sense to do this. The reason is that it is now impossible to update an alert if the corresponding question has not yet been saved.

This was referenced Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch .Team/AdminWebapp Admin and Webapp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update alert shouldn't call update card API
5 participants