-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
OBPIH-851: Add base form fields components #278
Conversation
const delimiter = attributes.delimiter || ';'; | ||
|
||
return ( | ||
<div className="col-md-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.
there might be exceptions out of this, but let's see along the way. If so, we'll parametrize this later on.
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.
can you elaborate what you mean by "exceptions"?
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.
Oh wait are you talking about the CSS there? Yeah I assume we'll need to make that parameterizable at some point. Or just get rid of the div altogether and let the page wrap the inputs with divs using whatever column width they want.
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.
And if you do need the div
in the component we might just want to go with a col-md-12
so that we at least we have the ability to nest it in another div to change the width. I.e. we could nest this input component in a col-md-4
ourselves and the component would fill that div.
<div class='col-md-4'>
<howeverYouReferenceAComponent/>
</div>
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.
Yup this was about the css part. I think for now it looks alright with forms. We can extend capabilities and customizability of these components in future tickets.
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.
Looks good. Just asked a few questions to gain a better understanding of what's going on.
const delimiter = attributes.delimiter || ';'; | ||
|
||
return ( | ||
<div className="col-md-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.
can you elaborate what you mean by "exceptions"?
] | ||
], | ||
"moduleNameMapper": { | ||
"\\.(css|scss)$": "<rootDir>/src/js/tests/__mocks__/styleMock.js" |
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.
Ok, I'm probably going to start asking more questions now so I can absorb some of this. Can you explain what is going on here? From the docs it seems like we're stubbing out any css/scss files. But why is that needed? To prevent styles from contaminating the DOM (i.e. hiding a DOM element that is being tested)?
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.
if you want to test component that imports some css with jest it will fail, because jest it's handling only javascript and you need to mock any other file types
return ( | ||
<BaseField | ||
{...props} | ||
renderInput={renderInput} |
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.
So let me try to get a better understanding of react components. Every react component has some type of render method. Is renderInput
a convention or do input
components need to use renderInput
? This return is associated with the CheckboxField so I assume this is defining the component while renderInput
is added to perform rendering operations on any type of event (mouseclick, etc). Where do we define which events get passed to this component? I assume that's where redux comes in?
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.
renderInput it's just a parameter, there is no convention here I named it this way because it's actually rendering an "input". BaseField is adding some shared code to all of the fields (label, validation messages, etc.) and using this function to renter the input. It's done this way to have small and reusable 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.
Sorry, that's exactly what I meant by "convention". So not necessarily a strict React standard but rather a convention that you've adopted.
const delimiter = attributes.delimiter || ';'; | ||
|
||
return ( | ||
<div className="col-md-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.
Oh wait are you talking about the CSS there? Yeah I assume we'll need to make that parameterizable at some point. Or just get rid of the div altogether and let the page wrap the inputs with divs using whatever column width they want.
}; | ||
|
||
return ( | ||
<BaseReactField |
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.
What's the different between BaseReactField
and BaseField
?
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.
BaseReactField is rendering BaseField it's some kind of child parent relation
const delimiter = attributes.delimiter || ';'; | ||
|
||
return ( | ||
<div className="col-md-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.
And if you do need the div
in the component we might just want to go with a col-md-12
so that we at least we have the ability to nest it in another div to change the width. I.e. we could nest this input component in a col-md-4
ourselves and the component would fill that div.
<div class='col-md-4'>
<howeverYouReferenceAComponent/>
</div>
{ | ||
"rules": { | ||
"react/prop-types": 0, | ||
"no-undef": 0 |
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 appears like you are disabling noisy linting rules that you don't want to see while running tests? Is that correct? And is this just for test code? Is there a default set of linting rules defined somewhere?
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, this is just for tests, the main eslint file in in the root directory
@@ -1,5 +1,3 @@ | |||
/* eslint-disable no-undef,react/prop-types */ |
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.
Ah, I see. So you just moved this to a global lint config so you don't need to specify it on each test.
@@ -0,0 +1 @@ | |||
module.exports = {}; |
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.
Can you explain what this does within the context of mocking CSS files? Does this just clear exports so that nothing is able to contaminate the DOM during tests?
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.
you can check this link for details: https://stackoverflow.com/questions/41841968/react-js-jest-causing-syntaxerror-unexpected-token
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.
Thank you
@@ -0,0 +1,46 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP |
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.
Can you explain why snapshots should be treated as code? It seems like it's an artifact of the testing process and should be discarded afterwards?
https://facebook.github.io/jest/docs/en/snapshot-testing.html#1-treat-snapshots-as-code
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.
they should be part of the code, because the test will compare the rendered component with the snapshot and fail if there was any differences
No description provided.