-
-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
271 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
src/components/GroupChatDetails/GroupChatDetails.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
import GroupChatDetails from './GroupChatDetails'; | ||
import { MockedProvider } from '@apollo/client/testing'; | ||
import { | ||
ADD_USER_TO_GROUP_CHAT, | ||
UPDATE_CHAT, | ||
} from 'GraphQl/Mutations/OrganizationMutations'; | ||
import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries'; | ||
|
||
const mockChat = { | ||
_id: '1', | ||
isGroup: true, | ||
name: 'Test Group', | ||
image: '', | ||
messages: [], | ||
admins: [ | ||
{ | ||
_id: '1', | ||
firstName: 'Admin', | ||
lastName: 'User', | ||
email: '[email protected]', | ||
}, | ||
], | ||
users: [ | ||
{ | ||
_id: '2', | ||
firstName: 'Test', | ||
lastName: 'User', | ||
email: '[email protected]', | ||
}, | ||
], | ||
unseenMessagesByUsers: JSON.parse('{"1": 0, "2": 0}'), | ||
description: 'Test Description', | ||
}; | ||
|
||
const mocks = [ | ||
{ | ||
request: { | ||
query: USERS_CONNECTION_LIST, | ||
variables: { firstName_contains: '', lastName_contains: '' }, | ||
}, | ||
result: { | ||
data: { | ||
users: [ | ||
{ | ||
user: { | ||
_id: '3', | ||
firstName: 'New', | ||
lastName: 'User', | ||
email: '[email protected]', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
{ | ||
request: { | ||
query: ADD_USER_TO_GROUP_CHAT, | ||
variables: { userId: '3', chatId: '1' }, | ||
}, | ||
result: { | ||
data: { | ||
addUserToGroupChat: { success: true }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
request: { | ||
query: UPDATE_CHAT, | ||
variables: { input: { _id: '1', image: '', name: 'Updated Group' } }, | ||
}, | ||
result: { | ||
data: { | ||
updateChat: { success: true }, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
describe('GroupChatDetails', () => { | ||
it('renders correctly', () => { | ||
render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<GroupChatDetails | ||
toggleGroupChatDetailsModal={jest.fn()} | ||
groupChatDetailsModalisOpen={true} | ||
chat={mockChat} | ||
chatRefetch={jest.fn()} | ||
/> | ||
</MockedProvider>, | ||
); | ||
|
||
expect(screen.getByText('Test Group')).toBeInTheDocument(); | ||
expect(screen.getByText('Test Description')).toBeInTheDocument(); | ||
}); | ||
|
||
it('opens and closes modals correctly', () => { | ||
const toggleGroupChatDetailsModal = jest.fn(); | ||
render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<GroupChatDetails | ||
toggleGroupChatDetailsModal={toggleGroupChatDetailsModal} | ||
groupChatDetailsModalisOpen={true} | ||
chat={mockChat} | ||
chatRefetch={jest.fn()} | ||
/> | ||
</MockedProvider>, | ||
); | ||
|
||
fireEvent.click(screen.getByTestId('createDirectChat')); | ||
expect(toggleGroupChatDetailsModal).toHaveBeenCalled(); | ||
}); | ||
|
||
it('edits chat title', async () => { | ||
render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<GroupChatDetails | ||
toggleGroupChatDetailsModal={jest.fn()} | ||
groupChatDetailsModalisOpen={true} | ||
chat={mockChat} | ||
chatRefetch={jest.fn()} | ||
/> | ||
</MockedProvider>, | ||
); | ||
|
||
fireEvent.click(screen.getByText('Test Group')); | ||
fireEvent.change(screen.getByDisplayValue('Test Group'), { | ||
target: { value: 'Updated Group' }, | ||
}); | ||
fireEvent.click(screen.getByText('✔')); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('Updated Group')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('opens add user modal and adds user', async () => { | ||
render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<GroupChatDetails | ||
toggleGroupChatDetailsModal={jest.fn()} | ||
groupChatDetailsModalisOpen={true} | ||
chat={mockChat} | ||
chatRefetch={jest.fn()} | ||
/> | ||
</MockedProvider>, | ||
); | ||
|
||
fireEvent.click(screen.getByText('Add Members')); | ||
expect(screen.getByTestId('addExistingUserModal')).toBeInTheDocument(); | ||
|
||
fireEvent.change(screen.getByPlaceholderText('searchFullName'), { | ||
target: { value: 'New User' }, | ||
}); | ||
fireEvent.click(screen.getByTestId('submitBtn')); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('New User')).toBeInTheDocument(); | ||
}); | ||
|
||
fireEvent.click(screen.getByText('Add')); | ||
await waitFor(() => { | ||
expect(screen.queryByText('New User')).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.