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

Added Close Index Component Integration Test For Index Management #114020

Merged
merged 14 commits into from
Dec 10, 2021

Conversation

cuff-links
Copy link
Contributor

Summary

This PR adds a component integration test that checks that we are able to click the close index button and check the last request to ensure that it was made to the close index API.

@cuff-links cuff-links added Feature:Index Management Index and index templates UI test-jest-integration v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more release_note:skip Skip the PR/issue when compiling release notes auto-backport Deprecated - use backport:version if exact versions are needed v7.15.1 labels Oct 5, 2021
@cuff-links cuff-links requested review from cjcenizal and removed request for cjcenizal October 5, 2021 21:46
@cuff-links cuff-links changed the title Added Close Index CIT test Added Close Index Component Integration Test For Index Management Oct 5, 2021
@cuff-links
Copy link
Contributor Author

@elasticmachine merge upstream

@cuff-links cuff-links marked this pull request as ready for review October 8, 2021 00:51
@cuff-links cuff-links requested a review from a team as a code owner October 8, 2021 00:51
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-management (Team:Stack Management)

@cuff-links
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Member

@sabarasaba sabarasaba left a 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 @cuff-links! Changes LGTM, just had a suggestions for simplifying the button selector and maybe abstracting the clicking logic into a new action:

Comment on lines 170 to 172
const closeIndexButton = contextMenu
.find('button[data-test-subj="indexTableContextMenuButton"]')
.at(0);
Copy link
Member

Choose a reason for hiding this comment

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

I think we could simplify this a little bit by just using a selector like:

Suggested change
const closeIndexButton = contextMenu
.find('button[data-test-subj="indexTableContextMenuButton"]')
.at(0);
const closeIndexButton = find('indexContextMenu.indexTableContextMenuButton').at(0);

Also, what do you think about abstracting this into another action that allows us to click a context menu option like:

enum ContextMenuOptions {
  ToggleIndex = 0,
  RefreshIndex = 2,
  ClearIndexCache = 3,
  FlushIndex = 4,
}

const clickContextMenuOption = async (option: ContextMenuOption) => {
  const { find } = testBed;
  await act(async () => {
    find('indexContextMenu.indexTableContextMenuButton').at(option).simulate('click');
  });
};

And then in the test we could just do:

 await clickContextMenuOption(ContextMenuOptions.ToggleIndex);

Copy link
Contributor

@yuliacech yuliacech left a comment

Choose a reason for hiding this comment

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

Great work adding those tests, @cuff-links! I think the best way to solve for selecting the correct button is to add specific data-test-subj values in this file. For example for "close index" button:

items.push({
        "data-test-subj": 'closeIndexButton',
        name: i18n.translate('xpack.idxMgmt.indexActionsMenu.closeIndexLabel', {
          defaultMessage: 'Close {selectedIndexCount, plural, one {index} other {indices} }',
          values: { selectedIndexCount },
        }),
        onClick: () => {
          if (hasSystemIndex) {
            this.closePopover();
            this.setState({ renderConfirmModal: this.renderConfirmCloseModal });
            return;
          }
          this.closePopoverAndExecute(closeIndices);
        },
      });

That would make other tests easier to work with too. WDYT?

@cuff-links
Copy link
Contributor Author

Great work adding those tests, @cuff-links! I think the best way to solve for selecting the correct button is to add specific data-test-subj values in this file. For example for "close index" button:

items.push({
        "data-test-subj": 'closeIndexButton',
        name: i18n.translate('xpack.idxMgmt.indexActionsMenu.closeIndexLabel', {
          defaultMessage: 'Close {selectedIndexCount, plural, one {index} other {indices} }',
          values: { selectedIndexCount },
        }),
        onClick: () => {
          if (hasSystemIndex) {
            this.closePopover();
            this.setState({ renderConfirmModal: this.renderConfirmCloseModal });
            return;
          }
          this.closePopoverAndExecute(closeIndices);
        },
      });

That would make other tests easier to work with too. WDYT?

I tried applying that data test subject but it did not get added to the element. The only time that the data test subject got added was if you change line 244. But that breaks several of the tests. I think perhaps handling it the way @sabarasaba mentioned may work well.

Copy link
Member

@sabarasaba sabarasaba left a comment

Choose a reason for hiding this comment

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

Latest LGTM @cuff-links! I left just one small nit 🚀

Comment on lines 58 to 62
const contextMenu = find('indexContextMenu');
contextMenu
.find('button[data-test-subj="indexTableContextMenuButton"]')
.at(option)
.simulate('click');
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think we can still simplify this like:

Suggested change
const contextMenu = find('indexContextMenu');
contextMenu
.find('button[data-test-subj="indexTableContextMenuButton"]')
.at(option)
.simulate('click');
find('indexContextMenu.indexTableContextMenuButton').at(option).simulate('click');

@yuliacech
Copy link
Contributor

I tried applying that data test subject but it did not get added to the element. The only time that the data test subject got added was if you change line 244. But that breaks several of the tests. I think perhaps handling it the way @sabarasaba mentioned may work well.

Hi @cuff-links, thanks for considering my suggestions!
Yes, the code on line 244 needs to be deleted as it overwrites any data-test-subj that are added initially. Which tests get broken when specific values are added? Maybe those tests will also benefit from using the specific value instead of relying on the order? For example, the current solution won't work when testing for opening an index, because a closed index has other actions allowed than a closed one. The tests could also break if any new actions are added, that would disturb the order. Maybe we could have a look at the code together over zoom?

@yuliacech
Copy link
Contributor

Hi @cuff-links, I was thinking about your comment that some tests get broken with the value of data-test-subj changes and checked those. I think the code quality could benefit if these tests are easier to maintain. I opened a PR to help out and fix those. Let me know what you think!

@cuff-links
Copy link
Contributor Author

Unrelated test failure. Gonna have jenkins retest.

@cuff-links
Copy link
Contributor Author

jenkins test this

@cuff-links
Copy link
Contributor Author

@yuliacech Updated with your PR's changes. Think we are good to go.

@kibanamachine
Copy link
Contributor

kibanamachine commented Oct 16, 2021

💔 Build Failed

Failed CI Steps


Test Failures

Kibana Pipeline / jest / Jest Tests.x-pack/plugins/index_management/__jest__/client_integration/home. index actions from detail panel should be able to flush index

Link to Jenkins

Standard Out

Failed Tests Reporter:
  - Test has not failed recently on tracked branches


Stack Trace

TypeError: indices.forEach is not a function
    at INDEX_MANAGEMENT_RELOAD_INDICES_SUCCESS (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/x-pack/plugins/index_management/public/application/store/reducers/indices.js:45:15)
    at /var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/redux-actions/lib/handleAction.js:50:64
    at /var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/redux-actions/node_modules/reduce-reducers/lib/index.js:32:22
    at Array.reduce (<anonymous>)
    at /var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/redux-actions/node_modules/reduce-reducers/lib/index.js:31:21
    at /var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/redux-actions/lib/handleActions.js:42:12
    at combination (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/redux/lib/redux.js:536:29)
    at combination (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/redux/lib/redux.js:536:29)
    at dispatch (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/redux/lib/redux.js:296:22)
    at /var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/redux-thunk/lib/index.js:14:16
    at dispatch (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/redux/lib/redux.js:667:28)
    at /var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/x-pack/plugins/index_management/public/application/store/actions/reload_indices.js:29:12

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@yuliacech yuliacech left a comment

Choose a reason for hiding this comment

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

Thanks for updating this, @cuff-links! code changes LGTM 👍

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@cuff-links cuff-links merged commit 3129b98 into elastic:main Dec 10, 2021
@kibanamachine
Copy link
Contributor

The following labels were identified as gaps in your version labels and will be added automatically:

  • v8.1.0

If any of these should not be on your pull request, please manually remove them.

kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Dec 10, 2021
…astic#114020)

* Added close index test.

* Fixed linting issues.

* Fixed linting issues.

* Abstracted out the index action option selection method and cleaned up test.

* Merged Yulia's changes into this PR and updated the test to consume the new data test subjects.

* Adjusted assertion to check for second to last request since there is a refresh done after the close index call.

* Fixed linting issue.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💔 Backport failed

Status Branch Result
8.0
7.15 Commit could not be cherrypicked due to conflicts

Successful backport PRs will be merged automatically after passing CI.

To backport manually run:
node scripts/backport --pr 114020

kibanamachine added a commit that referenced this pull request Dec 10, 2021
…14020) (#121043)

* Added close index test.

* Fixed linting issues.

* Fixed linting issues.

* Abstracted out the index action option selection method and cleaned up test.

* Merged Yulia's changes into this PR and updated the test to consume the new data test subjects.

* Adjusted assertion to check for second to last request since there is a refresh done after the close index call.

* Fixed linting issue.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: John Dorlus <silne.dorlus@elastic.co>
cuff-links pushed a commit to cuff-links/kibana that referenced this pull request Dec 21, 2021
…astic#114020)

* Added close index test.

* Fixed linting issues.

* Fixed linting issues.

* Abstracted out the index action option selection method and cleaned up test.

* Merged Yulia's changes into this PR and updated the test to consume the new data test subjects.

* Adjusted assertion to check for second to last request since there is a refresh done after the close index call.

* Fixed linting issue.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
cuff-links pushed a commit that referenced this pull request Dec 21, 2021
…14020) (#121722)

* Added close index test.

* Fixed linting issues.

* Fixed linting issues.

* Abstracted out the index action option selection method and cleaned up test.

* Merged Yulia's changes into this PR and updated the test to consume the new data test subjects.

* Adjusted assertion to check for second to last request since there is a refresh done after the close index call.

* Fixed linting issue.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
TinLe pushed a commit to TinLe/kibana that referenced this pull request Dec 22, 2021
…astic#114020)

* Added close index test.

* Fixed linting issues.

* Fixed linting issues.

* Abstracted out the index action option selection method and cleaned up test.

* Merged Yulia's changes into this PR and updated the test to consume the new data test subjects.

* Adjusted assertion to check for second to last request since there is a refresh done after the close index call.

* Fixed linting issue.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Index Management Index and index templates UI release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more test-jest-integration v7.15.1 v8.0.0 v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants