|
| 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 | +}); |
0 commit comments