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

[EuiDataGrid] Reorganize & add unit tests for row height utils #5354

Merged
merged 5 commits into from
Nov 9, 2021

Conversation

cee-chen
Copy link
Contributor

@cee-chen cee-chen commented Nov 3, 2021

Summary

This PR:

  • (f5b67bf) Reorganizes RowHeightUtils into sections separated by comment blocks (no code should have changed, just their locations)
  • (0ab53a6) Fixes a minor source code any type
  • (f5b67bf) Adds unit tests for the RowHeightUtils with full code coverage:

Checklist

N/A, tech debt/internal-only changes

});

describe('resetGrid', () => {
it('invokes grid.resetAfterRowIndex at the last cached/visible row', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The one thing I couldn't really figure out how to clearly unit test was the Math.min(this.lastUpdatedRow, visibleRowIndex) line 😬 that was partially due to setTimeout shenanigans - if we think it's important (I still get a little worried about us resetting grid at Infinity) I'd definitely appreciate pointers!

Copy link
Contributor

@chandlerprall chandlerprall Nov 8, 2021

Choose a reason for hiding this comment

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

This is what I extended this case into to cover the min logic; tests that resetAfterRowIndex is only called once, and with the expected, lowest, value

        it('invokes grid.resetAfterRowIndex at the last cached/visible row', () => {
          rowHeightUtils.setRowHeight(99, 'a', 34, 99);
          rowHeightUtils.setRowHeight(101, 'a', 34, 101);
          rowHeightUtils.resetGrid();
          expect(mockGrid.resetAfterRowIndex).toHaveBeenCalledTimes(1);
          expect(mockGrid.resetAfterRowIndex).toHaveBeenCalledWith(99);

          mockGrid.resetAfterRowIndex.mockReset();

          rowHeightUtils.setRowHeight(99, 'a', 34, 99);
          rowHeightUtils.setRowHeight(97, 'a', 34, 97);
          rowHeightUtils.resetGrid();
          expect(mockGrid.resetAfterRowIndex).toHaveBeenCalledTimes(1);
          expect(mockGrid.resetAfterRowIndex).toHaveBeenCalledWith(97);
        });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome, I'll add this in!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ea65334

I opted to split this out into a separate test block for clearer test naming/documentation

@cee-chen
Copy link
Contributor Author

cee-chen commented Nov 3, 2021

jenkins test this

- For easier dev readability

- Leave generic/shared utils at top of the class

NB: no actual code should have changed in this commit, just locations
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5354/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5354/

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Woo! What a great, comprehensive addition of tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants