123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- import {Organization} from 'sentry-fixture/organization';
- import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
- import OrganizationMemberRow from 'sentry/views/settings/organizationMembers/organizationMemberRow';
- describe('OrganizationMemberRow', function () {
- const member = TestStubs.Member({
- id: '1',
- email: '',
- name: '',
- orgRole: 'member',
- roleName: 'Member',
- pending: false,
- flags: {
- 'sso:linked': false,
- },
- user: {
- id: '',
- has2fa: false,
- name: 'sentry@test.com',
- },
- groupOrgRoles: [],
- });
- const managerTeam = TestStubs.Team({
- orgRole: 'manager',
- });
- const memberOnManagerTeam = TestStubs.Member({
- id: '2',
- orgRole: 'member',
- teams: [managerTeam.slug],
- groupOrgRoles: [
- {
- teamSlug: managerTeam.slug,
- role: {name: 'Manager'},
- },
- ],
- });
- const currentUser = TestStubs.User({
- id: '2',
- email: 'currentUser@email.com',
- });
- const defaultProps: React.ComponentProps<typeof OrganizationMemberRow> = {
- organization: Organization(),
- status: '',
- requireLink: false,
- memberCanLeave: false,
- canAddMembers: false,
- canRemoveMembers: false,
- member,
- currentUser,
- onSendInvite: () => {},
- onRemove: () => {},
- onLeave: () => {},
- };
- function resendButton() {
- return screen.queryByRole('button', {name: 'Resend invite'});
- }
- function resendSsoButton() {
- return screen.queryByRole('button', {name: 'Resend SSO link'});
- }
- function leaveButton() {
- return screen.queryByRole('button', {name: 'Leave'});
- }
- function removeButton() {
- return screen.queryByRole('button', {name: 'Remove'});
- }
- describe('two factor', function () {
- it('does not have 2fa warning if user has 2fa', function () {
- render(
- <OrganizationMemberRow
- {...defaultProps}
- member={TestStubs.Member({
- ...member,
- user: TestStubs.User({...member.user, has2fa: true}),
- })}
- />
- );
- expect(screen.getByText('2FA Enabled')).toBeInTheDocument();
- expect(screen.queryByText('2FA Not Enabled')).not.toBeInTheDocument();
- });
- it('has 2fa warning if user does not have 2fa enabled', function () {
- render(
- <OrganizationMemberRow
- {...defaultProps}
- member={{
- ...member,
- user: {...member.user, has2fa: false},
- }}
- />
- );
- expect(screen.getByText('2FA Not Enabled')).toBeInTheDocument();
- expect(screen.queryByText('2FA Enabled')).not.toBeInTheDocument();
- });
- });
- describe('Pending user', function () {
- const props = {
- ...defaultProps,
- member: {...member, pending: true},
- };
- it('has "Invited" status, no "Resend Invite"', function () {
- render(<OrganizationMemberRow {...props} />);
- expect(screen.getByTestId('member-role')).toHaveTextContent('Invited Member');
- expect(resendButton()).toBeDisabled();
- });
- it('has "Resend Invite" button only if `canAddMembers` is true', function () {
- render(<OrganizationMemberRow {...props} canAddMembers />);
- expect(screen.getByTestId('member-role')).toHaveTextContent('Invited Member');
- expect(resendButton()).toBeEnabled();
- });
- it('has the right inviting states', function () {
- render(<OrganizationMemberRow {...props} canAddMembers />);
- expect(resendButton()).toBeInTheDocument();
- });
- it('has loading state', function () {
- render(<OrganizationMemberRow {...props} canAddMembers status="loading" />);
- // Should have loader
- expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
- // No Resend Invite button
- expect(resendButton()).not.toBeInTheDocument();
- });
- it('has success status', function () {
- render(<OrganizationMemberRow {...props} canAddMembers status="success" />);
- // Should not have loader
- expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
- // No Resend Invite button
- expect(resendButton()).not.toBeInTheDocument();
- expect(screen.getByTestId('member-status')).toHaveTextContent('Sent!');
- });
- });
- describe('Expired user', function () {
- it('has "Expired" status', function () {
- render(
- <OrganizationMemberRow
- {...defaultProps}
- canAddMembers
- member={{...member, pending: true, expired: true}}
- />
- );
- expect(screen.getByTestId('member-role')).toHaveTextContent('Expired Invite');
- expect(resendButton()).toBeEnabled();
- });
- });
- describe('Requires SSO Link', function () {
- const props = {
- ...defaultProps,
- flags: {'sso:link': false},
- requireLink: true,
- };
- it('shows "Invited" status if user has not registered and not linked', function () {
- render(
- <OrganizationMemberRow
- {...props}
- canAddMembers
- member={{...member, pending: true}}
- />
- );
- expect(screen.getByTestId('member-role')).toHaveTextContent('Invited Member');
- expect(resendButton()).toBeEnabled();
- });
- it('shows "missing SSO link" message if user is registered and needs link', function () {
- render(<OrganizationMemberRow {...props} />);
- expect(screen.getByTestId('member-role')).toHaveTextContent('Member');
- expect(resendSsoButton()).toBeDisabled();
- });
- it('has "Resend SSO link" button only if `canAddMembers` is true and no link', function () {
- render(<OrganizationMemberRow {...props} canAddMembers />);
- expect(resendSsoButton()).toBeEnabled();
- });
- it('has 2fa warning if user is linked does not have 2fa enabled', function () {
- render(
- <OrganizationMemberRow
- {...defaultProps}
- member={{
- ...member,
- flags: {'sso:linked': true},
- user: {...member.user, has2fa: false},
- }}
- />
- );
- expect(screen.getByText('2FA Not Enabled')).toBeInTheDocument();
- expect(screen.queryByText('2FA Enabled')).not.toBeInTheDocument();
- });
- });
- describe('Is Current User', function () {
- const props = {
- ...defaultProps,
- member: {...member, email: 'currentUser@email.com'},
- };
- it('has button to leave organization and no button to remove', function () {
- render(<OrganizationMemberRow {...props} memberCanLeave />);
- expect(leaveButton()).toBeInTheDocument();
- expect(removeButton()).not.toBeInTheDocument();
- });
- it('has disabled button to leave organization and no button to remove when member can not leave', function () {
- render(<OrganizationMemberRow {...props} memberCanLeave={false} />);
- expect(leaveButton()).toBeDisabled();
- expect(removeButton()).not.toBeInTheDocument();
- });
- });
- describe('IDP flags permissions', function () {
- member.flags['idp:provisioned'] = true;
- it('current user cannot leave if idp:provisioned', function () {
- const props = {
- ...defaultProps,
- member: {...member, email: 'currentUser@email.com'},
- };
- render(
- <OrganizationMemberRow
- {...props}
- memberCanLeave={!member.flags['idp:provisioned']}
- />
- );
- expect(leaveButton()).toBeDisabled();
- });
- it('cannot remove member if member is idp:provisioned', function () {
- render(<OrganizationMemberRow {...defaultProps} />);
- expect(removeButton()).toBeDisabled();
- });
- });
- describe('Not Current User', function () {
- const props = {
- ...defaultProps,
- };
- it('does not have Leave button', function () {
- render(<OrganizationMemberRow {...props} memberCanLeave />);
- expect(leaveButton()).not.toBeInTheDocument();
- });
- it('has Remove disabled button when `canRemoveMembers` is false', function () {
- member.flags['idp:provisioned'] = false;
- render(<OrganizationMemberRow {...props} />);
- expect(removeButton()).toBeDisabled();
- });
- it('has Remove button when `canRemoveMembers` is true', function () {
- member.flags['idp:provisioned'] = false;
- render(<OrganizationMemberRow {...props} canRemoveMembers />);
- expect(removeButton()).toBeEnabled();
- });
- });
- describe('render org role', function () {
- it('renders org role without tooltip if no org roles from team membership', function () {
- render(
- <OrganizationMemberRow
- {...defaultProps}
- member={{...member, user: {...member.user}}}
- />
- );
- expect(screen.getByText('Member')).toBeInTheDocument();
- const questionTooltip = screen.queryByTestId('more-information');
- expect(questionTooltip).not.toBeInTheDocument();
- });
- });
- it('renders org role info tooltip if member has org roles from team membership', async function () {
- render(
- <OrganizationMemberRow
- {...defaultProps}
- member={{...memberOnManagerTeam, user: {...memberOnManagerTeam.user}}}
- />
- );
- const questionTooltip = screen.getByTestId('more-information');
- expect(questionTooltip).toBeInTheDocument();
- await userEvent.hover(questionTooltip);
- await waitFor(() => {
- expect(screen.getByText(`#${managerTeam.slug}`)).toBeInTheDocument();
- expect(screen.getByText(': Manager')).toBeInTheDocument();
- });
- });
- });
|