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

[Rollup] Add unit tests for Job table #31561

Merged
merged 10 commits into from
Feb 21, 2019
Merged

Conversation

sebelga
Copy link
Contributor

@sebelga sebelga commented Feb 20, 2019

This PR adds unit test coverage for the Rollup job table.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@cjcenizal cjcenizal added Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more Feature:Rollups labels Feb 20, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Awesome work! I had a few suggestions but overall this looks great to me. I love the pattern you came up with for creating helpers for finding different test subjects.


return '';
},
render: job => (
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Nice improvement!


import { Pager } from '@elastic/eui';

import { registerTestBed } from '../../../../../__jest__/utils';
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can move this __jest__ directory into the public directory, since it seems unlikely that we'll be writing server-side React in the near future? Then it will be closer to the code which consumes it, and we also won't need to go up so many parent directories.

Copy link
Contributor Author

@sebelga sebelga Feb 21, 2019

Choose a reason for hiding this comment

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

As I quickly explained over slack, this seems to be a pattern in other plugins to have the __jest__ folder at the root level. See for example license_management that also has a util file there. I think we should stick to that convention for consistency, what do you think?

});

it('should set the correct job value in each row cell', () => {
const fields = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename this unformattedFields to emphasize that the fields display the original fields without doing any formatting on them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I understand the benefit of it. It could be named fieldIds or fieldNames to be more correct and match the implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, the comment on line 75 points out that this array isn't all of the fields, it's just the ones which are rendered without any special formatting. We test other fields here in different ways when they're rendered with formatting, e.g. status and groups. So we can make the code more self-explanatory by naming this array something which communicates its role within the test, which IMO would be unformattedFields or fieldsRenderedWithoutFormatting -- because it contains only the fields which aren't formatted. We could name it something else, but I think the ideal name would be one which makes the comment on line 75 unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand now what you mean 😊 Thanks for the explanation 👍

: field.replace(/^\w/, char => char.toUpperCase());
}
return text;
}, '');
Copy link
Contributor

Choose a reason for hiding this comment

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

It makes me raise an eyebrow when our tests replicate the logic in the code being tested but I don't really have a better suggestion. I suppose we could hardcode our fixtures instead of dynamically generating them? 🤷‍♂️

Copy link
Contributor Author

@sebelga sebelga Feb 21, 2019

Choose a reason for hiding this comment

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

Yeah, I understand. But I guess what we are doing here is preventing an unexpected change on the component rendered. Just like a snapshot would do. What do you mean by hardcoding our fixtures ?

Copy link
Contributor

@cjcenizal cjcenizal Feb 21, 2019

Choose a reason for hiding this comment

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

Sorry, I phrased that wrong. What I meant to say was that we could just hardcode our assertion here:

expect(cellGroupsText).toEqual('Histogram, terms');

That way we're not duplicating the implementation, and it's easier to read and understand what we expect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, that makes sense.

@sebelga
Copy link
Contributor Author

sebelga commented Feb 21, 2019

Thanks for the review @cjcenizal ! I added a few comments, let me know your thoughts

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@sebelga sebelga merged commit 51fde91 into elastic:master Feb 21, 2019
@sebelga sebelga deleted the test/rollup_table branch February 21, 2019 13:41
@sebelga sebelga added the non-issue Indicates to automation that a pull request should not appear in the release notes label Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Rollups non-issue Indicates to automation that a pull request should not appear in the release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.2.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants