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

[Index Management] Fix bug in mappings fields #158912

Merged

Conversation

ElenaStoeva
Copy link
Contributor

Fixes #156202

Summary

This PR fixes the bug in Mappings fields from the Component template wizard by changing the Subtype parameter so that it handles the case when the value in the Subtype dropdown menu is cleared, similarly to what is done in the Type parameter.

How to test:

  1. Navigate to Index Management, go to Component templates tab.
  2. Start the wizard to create a new component template.
  3. Go to the Mappings step and add a field of type Numeric or Range, and click on the Subtype dropdown menu.
  4. Verify that pressing backspace in the Subtype dropdown menu doesn't make the page to crash.
  5. After adding the mapping field, click the pencil icon to edit this field and in the flyout click in the Numeric/Range type dropdown.
  6. Verify that pressing backspace doesn't make the page to crash.

@ElenaStoeva ElenaStoeva added Feature:Index Management Index and index templates UI 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 labels Jun 2, 2023
@ElenaStoeva ElenaStoeva self-assigned this Jun 2, 2023
@ElenaStoeva ElenaStoeva marked this pull request as ready for review June 2, 2023 13:34
@ElenaStoeva ElenaStoeva requested a review from a team as a code owner June 2, 2023 13:34
@elasticmachine
Copy link
Contributor

Pinging @elastic/platform-deployment-management (Team:Deployment Management)

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 a lot for fixing the form, @ElenaStoeva! Would it be possible to add a test for this bug?

@ElenaStoeva
Copy link
Contributor Author

ElenaStoeva commented Jun 2, 2023

Thanks a lot for fixing the form, @ElenaStoeva! Would it be possible to add a test for this bug?

Thanks for the review @yuliacech!

Regarding the tests, I see that there are already integration tests for the Numeric and Range type fields, but I'm not sure how exactly we would write a test for this bug. We would need to simulate typing a backspace but I still don't know if that would be possible and how much effort it would require. Do you have any idea?

@yuliacech
Copy link
Contributor

Hi @ElenaStoeva, I think you would need to add a new action to the template_form_helpers file here. To simulate the backspace, it would look something like this find("input-data-test-subj").simulate('keydown', { key: 'Backspace' }). There is a similar test for example here and the correct key for the backspace press can be found on this page.

@ElenaStoeva
Copy link
Contributor Author

Hi @ElenaStoeva, I think you would need to add a new action to the template_form_helpers file here. To simulate the backspace, it would look something like this find("input-data-test-subj").simulate('keydown', { key: 'Backspace' }). There is a similar test for example here and the correct key for the backspace press can be found on this page.

Thanks for the suggestion @yuliacech!
I tried adding the following integration test in x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/datatypes/date_range_datatype.test.tsx:

  test('should not allow clearing the Data Range subtype dropdown', async () => {
    const defaultMappings = {
      properties: {
        myField: {
          type: 'double_range',
        },
      },
    };

    await act(async () => {
      testBed = setup({ value: defaultMappings, onChange: onChangeHandler });
    });
    testBed.component.update();

    const {
      component,
      find,
      exists,
      actions: { startEditField },
    } = testBed;

    // Open the flyout to edit the field
    await startEditField('myField');

    // Press Backspace at the Subtype dropdown
    await act(async () => {
      find('fieldSubType').simulate('keydown', { key: 'Backspace' });
    });
    component.update();

    // Verify that page didn't crash
    expect(exists('mappingsEditorFieldEdit.editFieldUpdateButton'));

    // Verify that Update button is disabled - no change has been made
    expect(find('mappingsEditorFieldEdit.editFieldUpdateButton').props().disabled).toBe(true);
  });

but I noticed that it always passes - even when the fix for the bug is not present, so this test might not be very useful.

I also tried adding a functional test but this turned out to be tricky - for some reason the webdriver under the hood is not able to interact with the SubType dropdown menu when I try to click on it or set its value:

ElementNotInteractableError: element not interactable
   (Session info: chrome=114.0.5735.106)
       at Object.throwDecodedError (node_modules/selenium-webdriver/lib/error.js:524:15)
       at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:601:13)
       at Executor.execute (node_modules/selenium-webdriver/lib/http.js:529:28)
       at processTicksAndRejections (node:internal/process/task_queues:96:5)
       at Task.exec (prevent_parallel_calls.ts:28:20)

I can spend some more time to try to find some way to simulate pressing Backspace but I wonder if it would be worth the time given that this is very specific case that we already tested manually and I'm not sure if it would be beneficial to add a whole test for it. What do you think?

@ElenaStoeva
Copy link
Contributor Author

Hey @yuliacech, I found a workaround for the error in the functional tests so I added them with ea77b4b. Without the fix from this PR, these two tests are failing so they should be catching this bug in the future.
Let me know if you have an suggestion on the tests.

@ElenaStoeva
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
indexManagement 525.9KB 526.0KB +22.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
securitySolution 413 417 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
securitySolution 497 501 +4
total +6

History

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

cc @ElenaStoeva

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.

Amazing effort, @ElenaStoeva! Thanks a lot for looking into the tests for the bug as well 👍

@ElenaStoeva ElenaStoeva merged commit c994f40 into elastic:main Jun 7, 2023
@ElenaStoeva ElenaStoeva deleted the index-management-bug-mappings-fields branch June 7, 2023 08:46
@kibanamachine kibanamachine added v8.9.0 backport:skip This commit does not require backporting labels Jun 7, 2023
ElenaStoeva added a commit that referenced this pull request Jun 22, 2023
Fixes #159403

## Summary

The recently added functional test for the index template wizard in
Index Management (added with
#158912) seems to be flaky. It
fails when trying to navigate the "Add field" button on the "Mappings
step" because it's still on the previous step of the index template
wizard (the "Index settings" step). This PR adds checks on each step of
the wizard to make sure that it is on the right page before proceeding
to the next one.

Flaky test runner results:
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2436

Co-authored-by: Kibana Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting 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 v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Index Management] Mappings form crashes when backspace is pressed
5 participants