Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

MM 20547 user settings security ts #6216

Merged

Conversation

sridhar02
Copy link
Contributor

Summary

Migrate 'components/user_settings/security' module and associated tests to TypeScript

Ticket Link

Fixes mattermost/mattermost#13694

@hanzei hanzei added 2: Dev Review Requires review by a core commiter 3: QA Review Requires review by a QA tester labels Aug 21, 2020
@hanzei
Copy link
Contributor

hanzei commented Aug 21, 2020

Hey @sridhar02,

Thanks for your contribution. Heads up that CI failed with an type check error. You can find the logs here. Let me know if you need help resolving the error.

@mattermod
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

/cc @jasonblais @jfrerich

Copy link
Contributor

@nevyangelova nevyangelova left a comment

Choose a reason for hiding this comment

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

LGTM :)

@jasonblais
Copy link
Contributor

Thanks @sridhar02 for the contribution! Let us know if we can with the type check error reported by our CI build. You can find the logs here. We'd be happy to help :)

@sridhar02
Copy link
Contributor Author

@jasonblais I am busy with some other work, so I was not able to do this, so I will complete it a week or two.If I need I will mention in this PR

@hanzei hanzei added the Awaiting Submitter Action Blocked on the author label Sep 15, 2020
@hanzei hanzei removed the request for review from devinbinnie September 15, 2020 10:32
@sridhar02 sridhar02 force-pushed the MM-20547_user-settings-security-ts branch from 84670aa to f024dc1 Compare September 18, 2020 05:56
@hanzei
Copy link
Contributor

hanzei commented Sep 22, 2020

@devinbinnie devinbinnie self-requested a review September 22, 2020 13:25
@sridhar02 sridhar02 force-pushed the MM-20547_user-settings-security-ts branch from f024dc1 to 4a940c5 Compare September 24, 2020 01:57
@sridhar02
Copy link
Contributor Author

sridhar02 commented Sep 24, 2020

@hanzei can you help me fixing the type errors in the test file, I am new to testing struggling with it and due to it, I was unable to complete this PR.

@@ -125,7 +138,7 @@ describe('components/user_settings/display/UserSettingsDisplay', () => {
preventDefault: jest.fn(),
};
wrapper.setState({authorizedApps: apps});
wrapper.instance().deauthorizeApp(event);
(wrapper.instance() as UserSettingsSecurity).deauthorizeApp(event);
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to update the calls shallow in this file to explicitly set the type to
const wrapper: ShallowWrapper<any, any, UserSettingsSecurity> = shallow(....

With that you can even remove these type cases.

Copy link
Contributor Author

@sridhar02 sridhar02 Sep 24, 2020

Choose a reason for hiding this comment

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

I have written in this const wrapper: any = shallow(<UserSettingsSecurity {...props}/>) using this also I am not getting any errors while checking types will that be okay or I need to change it to const wrapper: ShallowWrapper<any, any, UserSettingsSecurity> ?

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer you use ShallowWrapper<any, any, UserSettingsSecurity but either way is fine.

@hanzei
Copy link
Contributor

hanzei commented Sep 24, 2020

@devinbinnie I'm not sure how to fix the issues with deauthorizeApp. Can you help there?

components/user_settings/security/user_settings_security.test.tsx:141:69 - error TS2345: Argument of type '{ currentTarget: { getAttribute: jest.Mock<any, any>; }; preventDefault: jest.Mock<any, any>; }' is not assignable to parameter of type 'MouseEvent<Element, MouseEvent>'.
  Type '{ currentTarget: { getAttribute: Mock<any, any>; }; preventDefault: Mock<any, any>; }' is missing the following properties from type 'MouseEvent<Element, MouseEvent>': altKey, button, buttons, clientX, and 27 more.

141         (wrapper.instance() as UserSettingsSecurity).deauthorizeApp(event);
                                                                        ~~~~~

@devinbinnie
Copy link
Member

@devinbinnie I'm not sure how to fix the issues with deauthorizeApp. Can you help there?

components/user_settings/security/user_settings_security.test.tsx:141:69 - error TS2345: Argument of type '{ currentTarget: { getAttribute: jest.Mock<any, any>; }; preventDefault: jest.Mock<any, any>; }' is not assignable to parameter of type 'MouseEvent<Element, MouseEvent>'.
  Type '{ currentTarget: { getAttribute: Mock<any, any>; }; preventDefault: Mock<any, any>; }' is missing the following properties from type 'MouseEvent<Element, MouseEvent>': altKey, button, buttons, clientX, and 27 more.

141         (wrapper.instance() as UserSettingsSecurity).deauthorizeApp(event);
                                                                        ~~~~~

@hanzei @sridhar02 You'll want to cast event as an any in this situation, as it's expecting you to provide the entire MouseEvent object. But since we don't want to mock that out, casting as any in the tests is alright.

@devinbinnie devinbinnie removed the Awaiting Submitter Action Blocked on the author label Sep 24, 2020
Copy link
Member

@devinbinnie devinbinnie 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 overall, just had a few comments I'd like you to address.
Thanks for the awesome contribution @sridhar02!


function mapStateToProps(state, ownProps) {
type Actions= {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: space between Actions and =

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved

@@ -48,7 +62,7 @@ describe('components/user_settings/display/UserSettingsDisplay', () => {
enableOAuthServiceProvider: true,
};

const wrapper = shallow(<UserSettingsSecurity {...props}/>);
const wrapper: any = shallow(<UserSettingsSecurity {...props}/>);
Copy link
Member

Choose a reason for hiding this comment

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

This can actually be of type ShallowWrapper<any, any, UserSettingsSecurity>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved

@@ -65,48 +79,64 @@ describe('components/user_settings/display/UserSettingsDisplay', () => {
enableOAuthServiceProvider: true,
};

const wrapper = shallow(<UserSettingsSecurity {...props}/>);
const wrapper: any = shallow(<UserSettingsSecurity {...props}/>);
Copy link
Member

Choose a reason for hiding this comment

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

Same with this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved

currentPassword: string;
newPassword: string;
confirmPassword: string;
passwordError: React.ReactNode | string;
Copy link
Member

Choose a reason for hiding this comment

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

string is part of React.ReactNode so you shouldn't need this as a union type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved

Copy link
Member

@devinbinnie devinbinnie left a comment

Choose a reason for hiding this comment

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

LGTM! Added a couple non-blocking comments but that's all.
Thanks again @sridhar02!

});

test('submitPassword() should not have called updateUserPassword', async () => {
const wrapper = shallow(<UserSettingsSecurity {...requiredProps}/>);

await wrapper.instance().submitPassword();
await (wrapper.instance() as UserSettingsSecurity).submitPassword();
Copy link
Member

Choose a reason for hiding this comment

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

If you use the same type as we added above, you can avoid this cast here.

@@ -125,7 +138,7 @@ describe('components/user_settings/display/UserSettingsDisplay', () => {
preventDefault: jest.fn(),
};
wrapper.setState({authorizedApps: apps});
wrapper.instance().deauthorizeApp(event);
(wrapper.instance() as UserSettingsSecurity).deauthorizeApp(event);
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer you use ShallowWrapper<any, any, UserSettingsSecurity but either way is fine.

@hanzei hanzei removed their request for review September 25, 2020 16:42
@hanzei hanzei removed the 2: Dev Review Requires review by a core commiter label Sep 25, 2020
@hanzei
Copy link
Contributor

hanzei commented Sep 25, 2020

@jgilliam17 A smote test around the security setting should be enough.

@jgilliam17 jgilliam17 added the Setup Cloud Test Server Setup a test server using Mattermost Cloud label Sep 25, 2020
Copy link
Contributor

@jgilliam17 jgilliam17 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 @sridhar02
Tested, looks good to merge.

  • Tested User Security Settings, works as expected (password edits, sign in, access history, view/log out of active sessions)

@hanzei Can you please help merge? Thank you 🙂

@jgilliam17 jgilliam17 added 4: Reviews Complete All reviewers have approved the pull request and removed 3: QA Review Requires review by a QA tester Setup Cloud Test Server Setup a test server using Mattermost Cloud labels Sep 25, 2020
@mm-cloud-bot
Copy link

Test server destroyed

@devinbinnie devinbinnie merged commit e5d2ebf into mattermost:master Sep 25, 2020
@hanzei hanzei added this to the v5.30.0 milestone Sep 25, 2020
@amyblais amyblais added Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation labels Sep 25, 2020
Tak-Iwamoto pushed a commit to Tak-Iwamoto/mattermost-webapp that referenced this pull request Sep 28, 2020
…o MM-20457

* 'master' of github.com:Tak-Iwamoto/mattermost-webapp:
  [MM-28680] fix blank page on undefined message (mattermost#6450)
  MM-28733 : Admin Advisor v2 (mattermost#6461)
  MM 20547 user settings security ts (mattermost#6216)
  MM-20904 Add E2E tests for custom categories (mattermost#5981)
  Update NOTICE.txt (mattermost#6550)
  Check if emojiMap is undefined before invoking method for it (mattermost#6495)
  [MM-28151] Cypress/E2E: Automate backlogs - System Console > User Password (mattermost#6538)
  [MM-28295] e2e/messaging/reactions: add reactions spec (mattermost#6535)
  [MM-28706] revert ordering change for `in:` auto-suggest search results (mattermost#6493)
  Remove usage of t function with useIntl (mattermost#6552)
  MM-28992 Remove unused notPresent and mustBePresent props from MultiSelectSetting (mattermost#6544)
  MM-27530 Fix for Multiselect items not scrolling into view on arrow keys (mattermost#6286)
  Demoting failed test from prod (mattermost#6534)
  migrate show_more to typescript (mattermost#6501)
  [MM-28878] Revert style change to remove next steps arrow (mattermost#6527)
  [MM-28972] Added 'Always On' option for new sidebar (mattermost#6530)
  MM-28839 Fix for hover of cursor on indicators (mattermost#6524)
  [MM-28790] allow plugins to open in a different tab (mattermost#6476)
  MM-28290 Always update team member unread counts when added to a channel (mattermost#6500)
Tak-Iwamoto pushed a commit to Tak-Iwamoto/mattermost-webapp that referenced this pull request Sep 28, 2020
…o MM-20462

* 'master' of github.com:Tak-Iwamoto/mattermost-webapp:
  fix getType is not a function (mattermost#6566)
  MM-29028 Remove findDOMNode from Slack import (mattermost#6554)
  MM-28997 Remove references to old context API (mattermost#6545)
  Add custom slash command tests (mattermost#6391)
  Cypress/E2E: Fix guest experience ui spec (mattermost#6563)
  [MM-28784] Migrate string refs to functional ones (mattermost#6494)
  [MM-28680] fix blank page on undefined message (mattermost#6450)
  MM-28733 : Admin Advisor v2 (mattermost#6461)
  MM 20547 user settings security ts (mattermost#6216)
  MM-20904 Add E2E tests for custom categories (mattermost#5981)
  Update NOTICE.txt (mattermost#6550)
  Check if emojiMap is undefined before invoking method for it (mattermost#6495)
  [MM-28151] Cypress/E2E: Automate backlogs - System Console > User Password (mattermost#6538)
  [MM-28295] e2e/messaging/reactions: add reactions spec (mattermost#6535)
  [MM-28706] revert ordering change for `in:` auto-suggest search results (mattermost#6493)
  Remove usage of t function with useIntl (mattermost#6552)
  MM-28992 Remove unused notPresent and mustBePresent props from MultiSelectSetting (mattermost#6544)
  MM-27530 Fix for Multiselect items not scrolling into view on arrow keys (mattermost#6286)
  Demoting failed test from prod (mattermost#6534)
jfrerich pushed a commit that referenced this pull request Oct 23, 2020
* convert files to ts and resolved type errors

* resolve type errors

* resolved type errors

* resolved type errors

* type errors resolved

* resolved type errors

* resolved test type errors

* type errors

* type errors fix

* fix lint error

* resolved type errors

* Resolved type errors

* resolved comments
calebroseland pushed a commit that referenced this pull request Oct 27, 2020
* convert files to ts and resolved type errors

* resolve type errors

* resolved type errors

* resolved type errors

* type errors resolved

* resolved type errors

* resolved test type errors

* type errors

* type errors fix

* fix lint error

* resolved type errors

* Resolved type errors

* resolved comments
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4: Reviews Complete All reviewers have approved the pull request Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation
Projects
None yet
9 participants