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

OBPIH-851: Add base form fields components #278

Merged
merged 3 commits into from
May 19, 2018
Merged

OBPIH-851: Add base form fields components #278

merged 3 commits into from
May 19, 2018

Conversation

pmuchowski
Copy link
Contributor

No description provided.

const delimiter = attributes.delimiter || ';';

return (
<div className="col-md-4">
Copy link
Collaborator

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.

Copy link
Member

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"?

Copy link
Member

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.

Copy link
Member

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> 

Copy link
Collaborator

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.

Copy link
Member

@jmiranda jmiranda left a 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">
Copy link
Member

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"
Copy link
Member

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)?

Copy link
Contributor Author

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}
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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">
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

@pmuchowski pmuchowski May 18, 2018

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">
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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 */
Copy link
Member

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 = {};
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

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
Copy link
Member

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

Copy link
Contributor Author

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

@jmiranda jmiranda merged commit 7b5fdb6 into develop May 19, 2018
@jmiranda jmiranda deleted the OBPIH-851 branch May 19, 2018 02:42
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.

None yet

4 participants