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

fix(PasswordFiled): fix password readonly visibility #2677

Merged

Conversation

serge-st
Copy link
Contributor

Summary

This change can resolve #2676 by disabling password visibility every time the password field is set to readonly and or disabled

Copy link

changeset-bot bot commented Dec 29, 2023

🦋 Changeset detected

Latest commit: 363653c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 93 packages
Name Type
@commercetools-uikit/password-field Patch
@commercetools-uikit/fields Patch
@commercetools-frontend/ui-kit Patch
@commercetools-uikit/design-system Patch
@commercetools-uikit/calendar-time-utils Patch
@commercetools-uikit/calendar-utils Patch
@commercetools-uikit/hooks Patch
@commercetools-uikit/i18n Patch
@commercetools-uikit/localized-utils Patch
@commercetools-uikit/utils Patch
@commercetools-uikit/accessible-hidden Patch
@commercetools-uikit/avatar Patch
@commercetools-uikit/card Patch
@commercetools-uikit/collapsible-motion Patch
@commercetools-uikit/collapsible-panel Patch
@commercetools-uikit/collapsible Patch
@commercetools-uikit/constraints Patch
@commercetools-uikit/data-table-manager Patch
@commercetools-uikit/data-table Patch
@commercetools-uikit/field-errors Patch
@commercetools-uikit/field-label Patch
@commercetools-uikit/grid Patch
@commercetools-uikit/icons Patch
@commercetools-uikit/label Patch
@commercetools-uikit/link Patch
@commercetools-uikit/loading-spinner Patch
@commercetools-uikit/messages Patch
@commercetools-uikit/notifications Patch
@commercetools-uikit/pagination Patch
@commercetools-uikit/primary-action-dropdown Patch
@commercetools-uikit/stamp Patch
@commercetools-uikit/tag Patch
@commercetools-uikit/text Patch
@commercetools-uikit/tooltip Patch
@commercetools-uikit/view-switcher Patch
@commercetools-uikit/accessible-button Patch
@commercetools-uikit/flat-button Patch
@commercetools-uikit/icon-button Patch
@commercetools-uikit/link-button Patch
@commercetools-uikit/primary-button Patch
@commercetools-uikit/secondary-button Patch
@commercetools-uikit/secondary-icon-button Patch
@commercetools-uikit/async-creatable-select-field Patch
@commercetools-uikit/async-select-field Patch
@commercetools-uikit/creatable-select-field Patch
@commercetools-uikit/date-field Patch
@commercetools-uikit/date-range-field Patch
@commercetools-uikit/date-time-field Patch
@commercetools-uikit/localized-multiline-text-field Patch
@commercetools-uikit/localized-text-field Patch
@commercetools-uikit/money-field Patch
@commercetools-uikit/multiline-text-field Patch
@commercetools-uikit/number-field Patch
@commercetools-uikit/radio-field Patch
@commercetools-uikit/search-select-field Patch
@commercetools-uikit/select-field Patch
@commercetools-uikit/text-field Patch
@commercetools-uikit/time-field Patch
@commercetools-uikit/async-creatable-select-input Patch
@commercetools-uikit/async-select-input Patch
@commercetools-uikit/checkbox-input Patch
@commercetools-uikit/creatable-select-input Patch
@commercetools-uikit/date-input Patch
@commercetools-uikit/date-range-input Patch
@commercetools-uikit/date-time-input Patch
@commercetools-uikit/input-utils Patch
@commercetools-uikit/localized-money-input Patch
@commercetools-uikit/localized-multiline-text-input Patch
@commercetools-uikit/localized-rich-text-input Patch
@commercetools-uikit/localized-text-input Patch
@commercetools-uikit/money-input Patch
@commercetools-uikit/multiline-text-input Patch
@commercetools-uikit/number-input Patch
@commercetools-uikit/password-input Patch
@commercetools-uikit/radio-input Patch
@commercetools-uikit/rich-text-input Patch
@commercetools-uikit/rich-text-utils Patch
@commercetools-uikit/search-select-input Patch
@commercetools-uikit/search-text-input Patch
@commercetools-uikit/select-input Patch
@commercetools-uikit/select-utils Patch
@commercetools-uikit/selectable-search-input Patch
@commercetools-uikit/text-input Patch
@commercetools-uikit/time-input Patch
@commercetools-uikit/toggle-input Patch
@commercetools-uikit/spacings-inline Patch
@commercetools-uikit/spacings-inset-squish Patch
@commercetools-uikit/spacings-inset Patch
@commercetools-uikit/spacings-stack Patch
@commercetools-uikit/buttons Patch
@commercetools-uikit/inputs Patch
@commercetools-uikit/spacings Patch
visual-testing-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Dec 29, 2023

@serge-dynamic is attempting to deploy a commit to the commercetools Team on Vercel.

A member of the Team first needs to authorize it.

@ddouglasz
Copy link
Contributor

ddouglasz commented Dec 29, 2023

Hello @serge-st
Thank you for catching this and also providing a solution. Please kindly add a test and changeset, otherwise, the work is 👌🏽

I will be happy to help if you have any further questions 🙂

@serge-st
Copy link
Contributor Author

serge-st commented Jan 2, 2024

Hello @ddouglasz!

Thanks for the prompt reply.

I added changeset and updated the tests in my latest commit.

Copy link
Contributor

@ddouglasz ddouglasz left a comment

Choose a reason for hiding this comment

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

Thank you for the tests 🙌🏾.
I just have some few observation to make it uniform with the other test.

@@ -141,13 +141,27 @@ describe('when disabled', () => {
const { getByLabelText } = renderPasswordField({ isDisabled: true });
expect(getByLabelText('PasswordField')).toBeDisabled();
});
it('should set the input type to password', () => {
const { container } = renderPasswordField({ isDisabled: true });
Copy link
Contributor

@ddouglasz ddouglasz Jan 2, 2024

Choose a reason for hiding this comment

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

We still need to give it some value, otherwise, the test will pass just all cases since we are testing a particular scenario:

  1. when there is value
  2. when readOnly and disabled
  3. when input type is text
Suggested change
const { container } = renderPasswordField({ isDisabled: true });
const { getByLabelText } = renderPasswordField({ value: 'foo', isDisabled: true });

@@ -141,13 +141,27 @@ describe('when disabled', () => {
const { getByLabelText } = renderPasswordField({ isDisabled: true });
expect(getByLabelText('PasswordField')).toBeDisabled();
});
it('should set the input type to password', () => {
const { container } = renderPasswordField({ isDisabled: true });
expect(container.querySelector('input')).toHaveAttribute(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(container.querySelector('input')).toHaveAttribute(
expect(getByLabelText('PasswordField')).toHaveAttribute(

});

describe('when readOnly', () => {
it('should disable the input', () => {
const { getByLabelText } = renderPasswordField({ isReadOnly: true });
expect(getByLabelText('PasswordField')).toHaveAttribute('readonly');
});
it('should set the input type to password', () => {
const { container } = renderPasswordField({ isReadOnly: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const { container } = renderPasswordField({ isReadOnly: true });
const { getByLabelText } = renderPasswordField({value: 'foo', isReadOnly: true });

});

describe('when readOnly', () => {
it('should disable the input', () => {
const { getByLabelText } = renderPasswordField({ isReadOnly: true });
expect(getByLabelText('PasswordField')).toHaveAttribute('readonly');
});
it('should set the input type to password', () => {
const { container } = renderPasswordField({ isReadOnly: true });
expect(container.querySelector('input')).toHaveAttribute(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(container.querySelector('input')).toHaveAttribute(
expect(getByLabelText('PasswordField')).toHaveAttribute(

@serge-st
Copy link
Contributor Author

serge-st commented Jan 7, 2024

@ddouglasz Hello!

Thank you for your patience.

I followed your suggestion and made the test more uniform.

I also covered:

  1. scenario with/without value
  2. scenario when both disabled and readOnly

about "when input type is text", since it is not possible to force input type via props, do you think it is needed to cover this as well, and how?

@ddouglasz
Copy link
Contributor

@ddouglasz Hello!

Thank you for your patience.

I followed your suggestion and made the test more uniform.

I also covered:

  1. scenario with/without value
  2. scenario when both disabled and readOnly

about "when input type is text", since it is not possible to force input type via props, do you think it is needed to cover this as well, and how?

Thank you for the changes. Honestly, I think these scenarios covered are enough.
Thank you for working on this 🙌🏾

Copy link
Contributor

@ddouglasz ddouglasz left a comment

Choose a reason for hiding this comment

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

@serge-st please we have some tiny last typos to fix 👌🏽

'password'
);
});
descrbe('when has value', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
descrbe('when has value', () => {
describe('when has value', () => {

'password'
);
});
descrbe('when has value', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
descrbe('when has value', () => {
describe('when has value', () => {

@serge-st
Copy link
Contributor Author

serge-st commented Jan 8, 2024

@ddouglasz my bad, I didn't setup the working environment correctly.

Now I ran the format and lint scripts, checks should pass.

Copy link

vercel bot commented Jan 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 8, 2024 10:47am

@emmenko emmenko merged commit bca5ba9 into commercetools:main Jan 9, 2024
3 checks passed
@ct-changesets ct-changesets bot mentioned this pull request Jan 9, 2024
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.

[fields/password-field] Disable "show" when isReadOnly props is true
4 participants