-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Dashboard] [Controls] Fix unsaved changes bug on empty dashboard #155648
[Dashboard] [Controls] Fix unsaved changes bug on empty dashboard #155648
Conversation
💚 Build Succeeded
Metrics [docs]Async chunks
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
To update your PR or re-run it, just comment with: cc @Heenawter |
Pinging @elastic/kibana-presentation (Team:Presentation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Tested this locally, and it works as described. Nice catch!
Closes #155777 ## Summary The `"replaces panel with incoming embeddable if id matches existing panel"` test was **not** the flaky one, even though it was the one that showed the failure; it was actually one of the previous `"pulls state <...>"` tests that was failing, which was pretty confusing to catch 🤦 Basically, because we are [running the unsaved changes check on load now](#155648), depending on the timing of the `debounce` on the `checkForUnsavedChangesSubject$` subscription it would sometimes run for the `"pulls state <...>"` tests (but not always) - so whenever it **would** run, because the mocked `loadDashboardStateFromSavedObject` was only returning a partial Dashboard input, this would result in trying to get the property of `undefined` when checking for filter changes, panel changes, etc. This is fixed by ensuring that the `loadDashboardStateFromSavedObject` returns a complete Dashboard input, with all the required keys, for all of the relevant tests. Note that, since you can't test Jest unit tests using the flaky test runner, I was able to run it multiple times by surrounding all the tests with the following in order to ensure that it was no longer flaky: ```typescript for (const i of Array(x) .fill(null) .map((_, i) => i)) { describe(`test run ${i}`, () => { <...> // all the tests go here }); }; ``` I did this with `x = 200`, and the entire test suite passed 200 times in a row 👍 ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
Closes elastic#155777 ## Summary The `"replaces panel with incoming embeddable if id matches existing panel"` test was **not** the flaky one, even though it was the one that showed the failure; it was actually one of the previous `"pulls state <...>"` tests that was failing, which was pretty confusing to catch 🤦 Basically, because we are [running the unsaved changes check on load now](elastic#155648), depending on the timing of the `debounce` on the `checkForUnsavedChangesSubject$` subscription it would sometimes run for the `"pulls state <...>"` tests (but not always) - so whenever it **would** run, because the mocked `loadDashboardStateFromSavedObject` was only returning a partial Dashboard input, this would result in trying to get the property of `undefined` when checking for filter changes, panel changes, etc. This is fixed by ensuring that the `loadDashboardStateFromSavedObject` returns a complete Dashboard input, with all the required keys, for all of the relevant tests. Note that, since you can't test Jest unit tests using the flaky test runner, I was able to run it multiple times by surrounding all the tests with the following in order to ensure that it was no longer flaky: ```typescript for (const i of Array(x) .fill(null) .map((_, i) => i)) { describe(`test run ${i}`, () => { <...> // all the tests go here }); }; ``` I did this with `x = 200`, and the entire test suite passed 200 times in a row 👍 ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) (cherry picked from commit 5779773)
# Backport This will backport the following commits from `main` to `8.8`: - [[Dashboard] Fix flaky Dashboard create tests (#156085)](#156085) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Hannah Mudge","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-04-28T14:14:12Z","message":"[Dashboard] Fix flaky Dashboard create tests (#156085)\n\nCloses https://github.com/elastic/kibana/issues/155777\r\n\r\n## Summary\r\n\r\nThe `\"replaces panel with incoming embeddable if id matches existing\r\npanel\"` test was **not** the flaky one, even though it was the one that\r\nshowed the failure; it was actually one of the previous `\"pulls state\r\n<...>\"` tests that was failing, which was pretty confusing to catch 🤦\r\n\r\nBasically, because we are [running the unsaved changes check on load\r\nnow](#155648), depending on the\r\ntiming of the `debounce` on the `checkForUnsavedChangesSubject# Backport This will backport the following commits from `main` to `8.8`: - [[Dashboard] Fix flaky Dashboard create tests (#156085)](#156085) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT \r\nsubscription it would sometimes run for the `\"pulls state <...>\"` tests\r\n(but not always) - so whenever it **would** run, because the mocked\r\n`loadDashboardStateFromSavedObject` was only returning a partial\r\nDashboard input, this would result in trying to get the property of\r\n`undefined` when checking for filter changes, panel changes, etc.\r\n\r\nThis is fixed by ensuring that the `loadDashboardStateFromSavedObject`\r\nreturns a complete Dashboard input, with all the required keys, for all\r\nof the relevant tests. Note that, since you can't test Jest unit tests\r\nusing the flaky test runner, I was able to run it multiple times by\r\nsurrounding all the tests with the following in order to ensure that it\r\nwas no longer flaky:\r\n\r\n```typescript\r\nfor (const i of Array(x)\r\n .fill(null)\r\n .map((_, i) => i)) {\r\n describe(`test run ${i}`, () => {\r\n <...> // all the tests go here\r\n });\r\n};\r\n```\r\n\r\nI did this with `x = 200`, and the entire test suite passed 200 times in\r\na row 👍\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"57797731905b0303eec9059e398388826c88fa5f","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Presentation","loe:days","release_note:skip","impact:critical","v8.8.0","v8.9.0"],"number":156085,"url":"https://github.com/elastic/kibana/pull/156085","mergeCommit":{"message":"[Dashboard] Fix flaky Dashboard create tests (#156085)\n\nCloses https://github.com/elastic/kibana/issues/155777\r\n\r\n## Summary\r\n\r\nThe `\"replaces panel with incoming embeddable if id matches existing\r\npanel\"` test was **not** the flaky one, even though it was the one that\r\nshowed the failure; it was actually one of the previous `\"pulls state\r\n<...>\"` tests that was failing, which was pretty confusing to catch 🤦\r\n\r\nBasically, because we are [running the unsaved changes check on load\r\nnow](#155648), depending on the\r\ntiming of the `debounce` on the `checkForUnsavedChangesSubject# Backport This will backport the following commits from `main` to `8.8`: - [[Dashboard] Fix flaky Dashboard create tests (#156085)](#156085) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT \r\nsubscription it would sometimes run for the `\"pulls state <...>\"` tests\r\n(but not always) - so whenever it **would** run, because the mocked\r\n`loadDashboardStateFromSavedObject` was only returning a partial\r\nDashboard input, this would result in trying to get the property of\r\n`undefined` when checking for filter changes, panel changes, etc.\r\n\r\nThis is fixed by ensuring that the `loadDashboardStateFromSavedObject`\r\nreturns a complete Dashboard input, with all the required keys, for all\r\nof the relevant tests. Note that, since you can't test Jest unit tests\r\nusing the flaky test runner, I was able to run it multiple times by\r\nsurrounding all the tests with the following in order to ensure that it\r\nwas no longer flaky:\r\n\r\n```typescript\r\nfor (const i of Array(x)\r\n .fill(null)\r\n .map((_, i) => i)) {\r\n describe(`test run ${i}`, () => {\r\n <...> // all the tests go here\r\n });\r\n};\r\n```\r\n\r\nI did this with `x = 200`, and the entire test suite passed 200 times in\r\na row 👍\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"57797731905b0303eec9059e398388826c88fa5f"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156085","number":156085,"mergeCommit":{"message":"[Dashboard] Fix flaky Dashboard create tests (#156085)\n\nCloses https://github.com/elastic/kibana/issues/155777\r\n\r\n## Summary\r\n\r\nThe `\"replaces panel with incoming embeddable if id matches existing\r\npanel\"` test was **not** the flaky one, even though it was the one that\r\nshowed the failure; it was actually one of the previous `\"pulls state\r\n<...>\"` tests that was failing, which was pretty confusing to catch 🤦\r\n\r\nBasically, because we are [running the unsaved changes check on load\r\nnow](#155648), depending on the\r\ntiming of the `debounce` on the `checkForUnsavedChangesSubject# Backport This will backport the following commits from `main` to `8.8`: - [[Dashboard] Fix flaky Dashboard create tests (#156085)](#156085) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT \r\nsubscription it would sometimes run for the `\"pulls state <...>\"` tests\r\n(but not always) - so whenever it **would** run, because the mocked\r\n`loadDashboardStateFromSavedObject` was only returning a partial\r\nDashboard input, this would result in trying to get the property of\r\n`undefined` when checking for filter changes, panel changes, etc.\r\n\r\nThis is fixed by ensuring that the `loadDashboardStateFromSavedObject`\r\nreturns a complete Dashboard input, with all the required keys, for all\r\nof the relevant tests. Note that, since you can't test Jest unit tests\r\nusing the flaky test runner, I was able to run it multiple times by\r\nsurrounding all the tests with the following in order to ensure that it\r\nwas no longer flaky:\r\n\r\n```typescript\r\nfor (const i of Array(x)\r\n .fill(null)\r\n .map((_, i) => i)) {\r\n describe(`test run ${i}`, () => {\r\n <...> // all the tests go here\r\n });\r\n};\r\n```\r\n\r\nI did this with `x = 200`, and the entire test suite passed 200 times in\r\na row 👍\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"57797731905b0303eec9059e398388826c88fa5f"}}]}] BACKPORT--> Co-authored-by: Hannah Mudge <[email protected]>
Summary
Before
When loading a dashboard with no panels but at least one control, the
diffingMiddleware
was not being fired - this caused a bug where making selections in the control (which were not saved into the dashboard) would not trigger unsaved changes on reload/refresh:Screen.Recording.2023-04-24.at.10.29.11.AM.mov
After
This was because, when the dashboard had no children, no Redux state changes were being dispatched to the Dashboard container which meant that the middleware was never triggered - this is fixed by adding
startWith(null)
(reference) to thecheckForUnsavedChangesSubject$
subscription so that it always fires on load.Screen.Recording.2023-04-24.at.11.01.24.AM.mov
Checklist
For maintainers