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

feat: normalize FormValidationOverlay usage in other components #1183

Merged
merged 15 commits into from
Aug 26, 2020
Merged

Conversation

jbadan
Copy link
Contributor

@jbadan jbadan commented Aug 25, 2020

Description

  1. added unit tests for FormValidationOverlay
  2. consistent apply new prop validationOverlayProps to all components that consume FormValidationOverlay: Checkbox, FormInput, FormTextArea, Select, InputGroup, SearchInput, Select, StepInput
  3. unit tests for validationOverlayProp in all consuming components
  4. validationOverlayProp.formMessageProps also spread to FormMessage when used inside component (outside of ValidationOverlay - see Select or SearchInput). This way, if you are expecting FormMessage to receive additional classes, it will whether it's inside the dropdown or as it's own popover. This will be useful in nui-widgets-lab for override Gateway theming colors.
  5. _FormValidationOverlay (not exported to consumers) now spreads additional props to the wrapping <div> element via wrapperProps. I couldn't use ...rest because that creates a rabbithole of problems with the way Popover is cloning elements. Possibly worth a followup, but is a ton of work and creates a pretty confusing output just for continuity sake.

BREAKING CHANGES:

  1. Removed fd-list--has-message class from Select's dropdown - it was adding unnecessary padding. It was a relic from before FormMessage rendered inside a Popover
  2. validationClassName renamed and moved inside of validationOverlayProps, use like validationOverlayProps.className

There will be at least 2 additional prs for Select - 1 to add the ability to pass custom classes to each component, the second addressing #1159

@netlify
Copy link

netlify bot commented Aug 25, 2020

Deploy preview for fundamental-react ready!

Built with commit 1396409

https://deploy-preview-1183--fundamental-react.netlify.app

@jbadan jbadan marked this pull request as draft August 25, 2020 22:00
@jbadan jbadan marked this pull request as ready for review August 25, 2020 23:04
@jbadan jbadan requested review from Mike-Diaz, scottheron and a team August 25, 2020 23:05
@@ -143,8 +143,15 @@ Please ensure you are either using a visible \`FormLabel\` or an \`aria-label\`
labelProps: PropTypes.object,
/** Sets the `name` for the checkbox input */
name: PropTypes.string,
/** Additional classes to apply to validation popover */
validationClassName: PropTypes.string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should moving this prop to validationOverlayProps.className be listed as a breaking change as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100%! Good catch

document.body.innerHTML = '';
});

const getFormMessage = () => document.body.querySelector('.fd-popover__popper > div > .fd-form-message');
Copy link
Contributor

Choose a reason for hiding this comment

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

Just an idea or an alternative, I've seen tests that include

// Ensure the popper is accessible with enzyme
jest.mock('react-dom', () => {
    const original = jest.requireActual('react-dom');
    return {
        ...original,
        createPortal: (node) => node,
    };
});

so you can still access the elements via enzyme

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 like this, but I'd like to apply it globally in config/jest/setup.js so we don't have some unit tests with it/some without. It makes 450 unit tests fail at the moment so I'll probably skip it on this pr 😆


const messageNode = getFormMessage();

expect(messageNode).toBeDefined();
Copy link
Contributor

@skvale skvale Aug 25, 2020

Choose a reason for hiding this comment

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

I'm pretty sure expect(null).toBeDefined() passes. If querySelector can't find an element it returns null, so this expect will always pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well... crap haha bad unit test!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The one after this is going to have the same problem - I'll rework both

@jbadan jbadan marked this pull request as draft August 26, 2020 00:08
@jbadan jbadan marked this pull request as ready for review August 26, 2020 14:18
});
});

describe('Interactions', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skvale Looks like you solved this exact problem in tooltip in widgets recently - I copied and applied what you did there to get this working 🎉

Copy link
Contributor

@skvale skvale left a comment

Choose a reason for hiding this comment

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

LGTM

@jbadan jbadan merged commit 1baafc8 into master Aug 26, 2020
@jbadan jbadan deleted the select branch August 26, 2020 15:28
@jbadan
Copy link
Contributor Author

jbadan commented Aug 26, 2020

I forgot to merge this as a breaking change 😞

@bcullman
Copy link
Contributor

@jbadan any chance we would use git --amend to fix this?

@jbadan
Copy link
Contributor Author

jbadan commented Aug 26, 2020

@bcullman We could try... but that prop was added 1 day before and removed 1 day after. We're most likely the only ones that noticed it came and went 😆

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