Skip to content

Commit 2c7001f

Browse files
authored
hotfix: modify invitation modal submit btn disable cond (#670)
Modified the invitation modal disable condition not to include the logged-in user in the user counting logic. Reported by https://sendbird.slack.com/archives/C04TSUD6KV1/p1688111690523829?thread_ts=1688003922.764459&cid=C04TSUD6KV1
1 parent 944315b commit 2c7001f

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom/extend-expect';
4+
import '@testing-library/jest-dom/matchers';
5+
import InviteUsers from '../index';
6+
7+
jest.mock('../../../context/CreateChannelProvider', () => ({
8+
useCreateChannelContext: jest.fn(() => ({
9+
onBeforeCreateChannel: jest.fn(),
10+
onCreateChannel: jest.fn(),
11+
overrideInviteUser: jest.fn(),
12+
createChannel: jest.fn().mockResolvedValue({}),
13+
type: 'group',
14+
})),
15+
}));
16+
17+
// Mock createPortal function to render content directly without portal
18+
jest.mock('react-dom', () => ({
19+
...jest.requireActual('react-dom'),
20+
createPortal: (node) => node,
21+
}));
22+
23+
describe('InviteUsers', () => {
24+
it('should enable the modal submit button when there is only the logged-in user is in the user list', () => {
25+
const userListQuery = jest.fn(() => ({
26+
hasNext: false,
27+
next: jest.fn().mockResolvedValue([
28+
{ userId: 'user1' },
29+
]),
30+
}));
31+
32+
render(<InviteUsers userListQuery={userListQuery} />);
33+
34+
const submitButton = screen.getByText('Create');
35+
expect(submitButton).toBeEnabled();
36+
});
37+
38+
// TODO: add this case too
39+
// it('should disable the modal submit button when there are users on the list but none are checked', () => {
40+
// })
41+
});

src/modules/CreateChannel/components/InviteUsers/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ const InviteUsers: React.FC<InviteUsersProps> = ({
9292
submitText={submitText}
9393
type={ButtonTypes.PRIMARY}
9494
// Disable the create button if no users are selected,
95-
// but if there's no users to display, then the create button should be enabled
96-
disabled={users.length > 0 && Object.keys(selectedUsers).length === 0}
95+
// but if there's only the logged-in user in the user list,
96+
// then the create button should be enabled
97+
disabled={users.length > 1 && Object.keys(selectedUsers).length === 0}
9798
onCancel={onCancel}
9899
onSubmit={() => {
99100
const selectedUserList = Object.keys(selectedUsers).length > 0

0 commit comments

Comments
 (0)