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

Feature/import new components #52

Merged
merged 47 commits into from
Aug 7, 2018
Merged

Conversation

gavinorland
Copy link
Collaborator

These are now operational and have tests, stories and docs. Please let me know if any issues and I'll fix ASAP.

gavinorland and others added 30 commits August 6, 2018 12:03
These tests can be further improved, but for the time being they are showing the problem with Table being rendered.
Will further develop tests
Also further develop tests and stories. More work is needed though. Each scenario needs to be covered in tests, usage covered in stories and documentation needs to be done.
Avoids potential HOC styling issue
The conditional seemed to simply return an empty array when the value was already an empty array. Moved check for flag into existing conditional.
skipEmptyRows defaults to false
Stories developed
Tests passing - but coverage to be increased
I had removed this because it produces a console error. I've been unable to yet track down why Table renders a '0' before its tbody in these conditions - something to look at later. But this is necessary for code coverage.
These are at 100% coverage but more could be tested.
@gavinorland gavinorland requested a review from stevesims August 6, 2018 14:00
@codecov
Copy link

codecov bot commented Aug 6, 2018

Codecov Report

Merging #52 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #52   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          19     22    +3     
  Lines         168    202   +34     
  Branches       24     40   +16     
=====================================
+ Hits          168    202   +34
Impacted Files Coverage Δ
packages/utils/src/tableUtils/index.js 100% <100%> (ø)
components/array-object-table/src/index.js 100% <100%> (ø)
components/object-table/src/index.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 060244e...51b732b. Read the comment docs.

@gavinorland
Copy link
Collaborator Author

gavinorland commented Aug 6, 2018

I was getting 100% coverage on the components but I see something is bringing coverage down - perhaps the index file - will take a look. - Yes, I have to get some tests in for the utils code - will try to do that ASAP.

@gavinorland gavinorland force-pushed the feature/import-new-components branch from e8f8d48 to b3498cc Compare August 6, 2018 17:18
"@govuk-frederic/utils": "^0.0.1"
},
"devDependencies": {
"@govuk-react/storybook-components": "^0.2.4",
Copy link
Owner

Choose a reason for hiding this comment

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

is this really right?
i.e. govuk-react?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure if that is right, actually, but that's how it is for all the components in Frederic and that's where that package is. I'm not sure if there should be a duplicate of it in Frederic or if it should be elsewhere.

stevesims
stevesims previously approved these changes Aug 7, 2018
Copy link
Owner

@stevesims stevesims left a comment

Choose a reason for hiding this comment

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

Some suggestions for changes, but they don't have to be done before this is merged in - they can be addressed later

"author": "Gavin Orland",
"license": "MIT",
"homepage": "https://github.com/stevesims/govuk-frederic#readme",
"description": "govuk-frederic: Frederic project specific components.",
Copy link
Owner

Choose a reason for hiding this comment

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

Should the description for this package file not be about what ArrayObjectTable is and does?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, ideally - this is something that needs doing for all Fred components (and govuk-react ones!). Added #54.

* <ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows hideWithNoValues/>;
* ```
* */
const ArrayObjectTable = ({ fields = [], array = [], hideWithNoValues = false, skipEmptyRows = false, title, ...props }) => {
Copy link
Owner

Choose a reason for hiding this comment

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

might be better/nicer to use defaultProps for hideWithNoValues and skipEmptyRows

* */
const ArrayObjectTable = ({ fields = [], array = [], hideWithNoValues = false, skipEmptyRows = false, title, ...props }) => {
let rows = rowsFromArray(array, fields, skipEmptyRows);
if (!rows.length && !hideWithNoValues) rows = rowsFromArray([{}], fields, false);
Copy link
Owner

Choose a reason for hiding this comment

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

euw - single line if statements with no curlies around stuff should be against our linting rules!


stories.addDecorator(WithDocsCustom(ReadMe));
stories.addDecorator(withKnobs);

Copy link
Owner

Choose a reason for hiding this comment

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

two lines of whitespace should be against our linting rules, i believe

Copy link
Owner

Choose a reason for hiding this comment

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

(i'm not against using two lines like this to help enforce a division, but rules iz rulez)

import Component from '.';

describe('ArrayObjectTable', () => {
let fields = [
Copy link
Owner

Choose a reason for hiding this comment

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

i'm not keen on this style of declaring variables at the top of the describe, and then using them inside individual tests below.

for instance, fields here ends up getting redefined later - i can guess that's going to be the case as it's defined with a let, but have to trawl down below to see where that happens. redefining fields in a test below also means that other tests after it's redefined need to be aware that it's been redefined.

if there are constant definitions of things to be used through multiple tests then i'd prefer to see them raised outside the describe block and declared as const, preferably given a slightly more descriptive variable name if there's going to be different versions used

similarly there's not much advantage on declaring a single wrapper here - better for that to be const wrapper = inside all the individual tests below. indeed allowing wrapper to persist through multiple tests means that the order of the tests below becomes important - which makes them harder to reason about

additionally if we wish to test different areas of functionality of a component, we can use multiple describe blocks inside the test file

object: PropTypes.object,
hideWithNoValues: PropTypes.bool,
skipEmptyValues: PropTypes.bool,
skipMissingKeys: PropTypes.bool,
Copy link
Owner

Choose a reason for hiding this comment

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

this prop isn't used

import Component from '.';

describe('ObjectTable', () => {
let fields = [
Copy link
Owner

Choose a reason for hiding this comment

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

same comments WRT how the ArrayObjectTable test file is structured apply here too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@stevesims I think I will raise an issue to look at this test structuring in another branch.

"author": "Gavin Orland",
"license": "MIT",
"homepage": "https://github.com/stevesims/govuk-frederic#readme",
"description": "govuk-frederic: Frederic project specific components",
Copy link
Owner

Choose a reason for hiding this comment

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

should have better description 😁

// TODO: ALL THE DOCS
// TODO: SOME TESTS
// Empty values and keys are treated the same
export const rowsFromObject = (object, fields, skipEmptyValues, defaultTransform) => {
Copy link
Owner

Choose a reason for hiding this comment

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

i'd have been inclined to have defaultTransform = value => `${value}` here
which would let line 34 below be

(table, { key, heading, names, transform = defaultTransform }) => {

and then allow lines 41-57 to be replaced with just:

const result = transform(object[key], object) || '';

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've made this change, great spot, thanks!

{ key: 'two', title: 'Two' },
];
const result = titlesFromFields(fields);
expect(result).toEqual(['One', 'Two']);
Copy link
Owner

Choose a reason for hiding this comment

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

on a general coding style point i prefer to see whitespace after variable declarations - one day i'll get around to setting a linting rule to enforce that 😜

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#5 becomes ever more pressing! 😛

@gavinorland
Copy link
Collaborator Author

@stevesims 👍 Thanks - will work through remaining feedback on this branch post-merge.

@gavinorland gavinorland merged commit 350a2d5 into master Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants