Page MenuHomePhabricator

[native] Introduce client-side logic for deleting roles on native
ClosedPublic

Authored by rohan on Jul 26 2023, 8:26 AM.
Tags
None
Referenced Files
F3388781: D8640.diff
Fri, Nov 29, 3:57 PM
Unknown Object (File)
Sat, Nov 23, 9:53 AM
Unknown Object (File)
Sat, Nov 23, 9:53 AM
Unknown Object (File)
Sat, Nov 23, 9:53 AM
Unknown Object (File)
Sat, Nov 23, 9:53 AM
Unknown Object (File)
Sat, Nov 23, 9:53 AM
Unknown Object (File)
Wed, Nov 13, 9:26 AM
Unknown Object (File)
Tue, Nov 12, 10:19 PM
Subscribers

Details

Summary

Split out from D8574, this diff introduces the client-side logic and behavior for deleting roles on native.

Depends on D8639

Test Plan

Same test plan / results video as was originally in D8574

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

rohan requested review of this revision.Jul 26 2023, 8:43 AM
atul requested changes to this revision.Jul 26 2023, 3:40 PM

Let's move logic for construction of message to lib so it can be used across web and native.

native/roles/role-utils.react.js
40–52 ↗(On Diff #29062)

Given we also have something like this for web (D8625), it makes sense to move the construction of this message to lib so it can be kept in sync across platforms.

This revision now requires changes to proceed.Jul 26 2023, 3:40 PM

Extract message extraction to lib

Looks good, thanks for addressing feedback!

lib/utils/role-utils.js
38–56

Now that we have this pulled out into utils function, we could add some quick unit tests?

I think we can just cut/paste these:

const { constructRoleDeletionMessagePrompt } = require('./path_to_your_function');

describe('constructRoleDeletionMessagePrompt', () => {
  it('should return generic deletion message if no members have this role', () => {
    const result = constructRoleDeletionMessagePrompt('defaultRole', 0);
    expect(result).toBe('Are you sure you want to delete this role?');
  });

  it('should correctly format message for single member', () => {
    const result = constructRoleDeletionMessagePrompt('defaultRole', 1);
    expect(result).toBe('There is currently 1 member with this role. Deleting the role will automatically assign the member affected to the defaultRole role.');
  });

  it('should correctly format message for multiple members', () => {
    const result = constructRoleDeletionMessagePrompt('defaultRole', 5);
    expect(result).toBe('There are currently 5 members with this role. Deleting the role will automatically assign the members affected to the defaultRole role.');
  });

  it('should correctly incorporate the name of the default role', () => {
    const result = constructRoleDeletionMessagePrompt('testRole', 5);
    expect(result).toBe('There are currently 5 members with this role. Deleting the role will automatically assign the members affected to the testRole role.');
  });
});

(https://chat.openai.com/share/4884ee58-a441-43e7-a91e-8433507971fc)

This revision is now accepted and ready to land.Jul 28 2023, 12:01 PM

Add unit tests (thanks @atul) and run yarn workspace lib test

This revision was landed with ongoing or failed builds.Jul 31 2023, 6:15 PM
This revision was automatically updated to reflect the committed changes.