-
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
Refactor index management client integration tests for scalability #67917
Refactor index management client integration tests for scalability #67917
Conversation
…st into its own file to increase scalability.
Pinging @elastic/es-ui (Team:Elasticsearch UI) |
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.
Thanks for working on this @cjcenizal! I think this extraction makes sense.
What do you think about taking it a step further? For example, I could see only testing the IndexTemplates tab component, rather than mounting the home component within the home_index_templates_tab.test.ts
. That could also eliminate some of the setup code (for example, here and here). Similarly, I could also see having an "indices tab" test that could further extract some of the tests in home.test.ts
.
This might be outside the scope of what you wanted to do here though 😄
…sier to rename, move around, and delete.
@alisonelizabeth Great suggestion! Can you take another look? I extracted out these tests into their own files. Note that I couldn't consume the TemplateList component because we depend upon react router to tell us which template to open in the detail panel, and the Home component contains the enclosing Route component. Maybe in a future iteration we can solve this. I left a code comment along these lines. I also decided to extract and colocate the helpers with the tests that consume them. This significantly deflated the shared helpers directory. I think this makes it easier to understand which tests use which helpers. Let me know what you think. |
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! I left a few comments in the code for info. Thanks for doing this 👍 !
import { | ||
registerTestBed, | ||
TestBed, | ||
TestBedConfig, | ||
findTestSubject, | ||
nextTick, | ||
} from '../../../../../test_utils'; | ||
// NOTE: We have to use the Home component instead of the TemplateList component because we depend | ||
// upon react router to provide the name of the template to load in the detail panel. |
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.
Something around those lines should work
const CompToTest = () => {
return (
<Switch>
<Route exact path="templates/:templateName*" component={TemplateList} />
</Switch>
);
};
const testBedConfig: TestBedConfig = {
memoryRouter: {
initialEntries: ["templates"],
componentRoutePath: "templates", // or maybe an empty ""?
},
doMountAsync: true,
};
const setup = registerTestBed(WithAppDependencies(CompToTest), testBedConfig);
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.
Thanks, Seb! I took a stab at this and every test started failing. I'm going to merge this in its current state to enable us to add tests for data streams etc. using this new organization, with the expectation that we'll address your comments separately.
|
||
actions.selectHomeTab('templatesTab'); | ||
|
||
await act(async () => { |
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.
info: This block is exactly what we want to remove everywhere. It creates latency in the tests and could be the cause of flakiness.
It should be written
act(() => {
// this is causing states updates. There can only be **one** in each act() call
// It should be synchronous if possible.
// Sometimes hook update require async, so if there is an error in console --> use async act()
actions.selectHomeTab('templatesTab');
});
// If I need a second action straightaway, we use another act()
act(() => {
actions.doSomethingElse();
});
// And we only need to call update() once after all actions
component.update();
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.
As an alternative, we could wrap the act()
inside our helpers' actions and keep the test file cleaner.
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.
Latest changes LGTM. Thanks @cjcenizal!
…NP migration of Management.
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
…ms-column * 'master' of github.com:elastic/kibana: (63 commits) remove scripts. prettire update has been done (elastic#68130) Closes elastic#68055 by detecting the local Kibana version and using that as (elastic#68198) [apm] docs: add deployment annotation example (elastic#67408) [ML] Extend population preview chart to show actual and typical value (elastic#67569) Refactor index management client integration tests for scalability (elastic#67917) Add generator function that creates multiple alerts (elastic#67713) chore(NA): remove config arg from os packages (elastic#67871) [Reporting] Move code out of Legacy (elastic#67904) [Metrics UI] Add overrides to Snapshot API to support alert previews (elastic#68125) [Security] [Cases] Manage timeline UI API (elastic#67719) [ENDPOINT][INGEST]Task/endpoint ingest update (elastic#67234) Fix code coverage for jest, upload merged reports (elastic#68149) Update documentation/examples of deprecated namespaceAgnostic field (elastic#68039) [DOCS] Updates Canvas docs with new menus (elastic#66061) chore(NA): avoids imports of server or public code into common (elastic#67231) [SIEM] Fix GetOneTimeline graphql type (elastic#68137) skip flaky suite (elastic#67838) [Uptime] Add loading message for monitor list no items (elastic#67378) [Ingest Manager] Update indexing strategy docs to use dataset.* (elastic#68068) [Ingest Manager] Fix datasource validation for streams without vars (elastic#67950) ... # Conflicts: # x-pack/plugins/index_management/__jest__/client_integration/helpers/index.ts # x-pack/plugins/index_management/__jest__/client_integration/home.test.ts # x-pack/plugins/index_management/__jest__/client_integration/home/index_templates_tab.helpers.ts
* master: (26 commits) [Console]remove completion for type for filter queries and aggs (elastic#68103) [ML] Transforms: Filter aggregation support (elastic#67591) [ES UI Shared] Monaco XJSON (elastic#67485) [Index Management] Add data streams functionality to indices tab (elastic#67940) [Discover] Fix renaming of saved search not displayed in breadcrumb (elastic#67577) [SECURITY] Rename siem plugin to security_solution (elastic#67902) [Uptime] Fix Telemetry Api flaky test (elastic#67358) [Data plugin] Add configuration property to enable / disable autocomplete (elastic#67847) remove scripts. prettire update has been done (elastic#68130) Closes elastic#68055 by detecting the local Kibana version and using that as (elastic#68198) [apm] docs: add deployment annotation example (elastic#67408) [ML] Extend population preview chart to show actual and typical value (elastic#67569) Refactor index management client integration tests for scalability (elastic#67917) Add generator function that creates multiple alerts (elastic#67713) chore(NA): remove config arg from os packages (elastic#67871) [Reporting] Move code out of Legacy (elastic#67904) [Metrics UI] Add overrides to Snapshot API to support alert previews (elastic#68125) [Security] [Cases] Manage timeline UI API (elastic#67719) [ENDPOINT][INGEST]Task/endpoint ingest update (elastic#67234) Fix code coverage for jest, upload merged reports (elastic#68149) ...
The biggest change I made in this PR was to extract the index templates tab tests into their own file. I think this increases scalability because we can test additional tabs by adding additional files.
I also think the general pattern we have for unit tests is to colocate them with tested code, so I updated the flatten_object tests to follow that pattern.
Another small change was to remove unused mocks.