-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
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.
Also docs regen
Codecov Report
@@ Coverage Diff @@
## master #52 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 19 22 +3
Lines 168 202 +34
Branches 24 40 +16
=====================================
+ Hits 168 202 +34
Continue to review full report at Codecov.
|
I was getting 100% coverage on the components but I see something is bringing coverage down - perhaps the |
e8f8d48
to
b3498cc
Compare
"@govuk-frederic/utils": "^0.0.1" | ||
}, | ||
"devDependencies": { | ||
"@govuk-react/storybook-components": "^0.2.4", |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 }) => { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 = [ |
There was a problem hiding this comment.
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
components/object-table/src/index.js
Outdated
object: PropTypes.object, | ||
hideWithNoValues: PropTypes.bool, | ||
skipEmptyValues: PropTypes.bool, | ||
skipMissingKeys: PropTypes.bool, |
There was a problem hiding this comment.
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 = [ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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) || '';
There was a problem hiding this comment.
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']); |
There was a problem hiding this comment.
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 😜
There was a problem hiding this comment.
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! 😛
It’s goooooood! Nice
@stevesims 👍 Thanks - will work through remaining feedback on this branch post-merge. |
These are now operational and have tests, stories and docs. Please let me know if any issues and I'll fix ASAP.