-
Notifications
You must be signed in to change notification settings - Fork 3
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
zuies
committed
Nov 30, 2023
1 parent
70894b3
commit c91316a
Showing
20 changed files
with
222 additions
and
447 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
62 changes: 49 additions & 13 deletions
62
src/components/centric/selectCommunity/TcSelectCommunity.spec.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 |
---|---|---|
@@ -1,21 +1,57 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import TcCommunityListItems from './TcCommunityListItems'; | ||
import { ICommunity } from '../../../utils/interfaces'; | ||
|
||
describe('<TcCommunityListItems />', () => { | ||
const mockCommunities = [ | ||
{ avatar: 'path1', label: 'Community 1' }, | ||
{ avatar: 'path2', label: 'Community 2' }, | ||
{ avatar: 'path3', label: 'Community 3' }, | ||
describe('TcCommunityListItems', () => { | ||
const mockCommunities: ICommunity[] = [ | ||
{ | ||
id: '1', | ||
name: 'Community 1', | ||
platforms: ['platform1', 'platform2'], | ||
users: ['user1', 'user2'], | ||
avatarURL: 'url1', | ||
}, | ||
{ | ||
id: '2', | ||
name: 'Community 2', | ||
platforms: ['platform3', 'platform4'], | ||
users: ['user3', 'user4'], | ||
avatarURL: 'url2', | ||
}, | ||
]; | ||
|
||
it('renders the community items correctly', () => { | ||
render(<TcCommunityListItems communities={mockCommunities} />); | ||
const onSelectCommunityMock = jest.fn(); | ||
|
||
// Check that each community is rendered | ||
mockCommunities.forEach((community) => { | ||
expect(screen.getByText(community.label)).toBeInTheDocument(); | ||
}); | ||
it('renders community items correctly', () => { | ||
render( | ||
<TcCommunityListItems | ||
communities={mockCommunities} | ||
onSelectCommunity={onSelectCommunityMock} | ||
/> | ||
); | ||
expect(screen.getByText('Community 1')).toBeInTheDocument(); | ||
expect(screen.getByText('Community 2')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls onSelectCommunity when a community is clicked', () => { | ||
render( | ||
<TcCommunityListItems | ||
communities={mockCommunities} | ||
onSelectCommunity={onSelectCommunityMock} | ||
/> | ||
); | ||
fireEvent.click(screen.getByText('Community 1')); | ||
expect(onSelectCommunityMock).toHaveBeenCalledWith(mockCommunities[0]); | ||
}); | ||
|
||
it('displays a message when no communities are available', () => { | ||
render( | ||
<TcCommunityListItems | ||
communities={[]} | ||
onSelectCommunity={onSelectCommunityMock} | ||
/> | ||
); | ||
expect(screen.getByText('No community exist')).toBeInTheDocument(); | ||
}); | ||
}); |
3 changes: 0 additions & 3 deletions
3
src/components/communitySettings/communityIntegrations/TcAvailableIntegrations.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
57 changes: 47 additions & 10 deletions
57
src/components/communitySettings/communityIntegrations/TcConnectedPlatforms.spec.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 |
---|---|---|
@@ -1,19 +1,56 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
import TcConnectedPlatforms from './TcConnectedPlatforms'; | ||
|
||
describe('<TcConnectedPlatforms />', () => { | ||
it('renders TcConnectedPlatformsItem components based on mock data', () => { | ||
render(<TcConnectedPlatforms />); | ||
// Mock the TcConnectedPlatformsItem component since it's imported and used in TcConnectedPlatforms | ||
jest.mock('./TcConnectedPlatformsItem', () => { | ||
return function MockTcConnectedPlatformsItem({ | ||
platform, | ||
}: { | ||
platform: any; | ||
}) { | ||
return ( | ||
<div data-testid="mock-connected-platforms-item"> | ||
{/* Render the platform's name for testing purposes */} | ||
{platform.name} | ||
</div> | ||
); | ||
}; | ||
}); | ||
|
||
describe('TcConnectedPlatforms', () => { | ||
it('renders connected platforms correctly', () => { | ||
// Define mock data for connected platforms | ||
const connectedPlatforms = [ | ||
{ | ||
name: 'Platform 1', | ||
community: 'Community 1', | ||
isInProgress: false, | ||
connectedAt: '2023-01-01', | ||
id: '1', | ||
disconnectedAt: null, | ||
metadata: {}, | ||
}, | ||
{ | ||
name: 'Platform 2', | ||
community: 'Community 2', | ||
isInProgress: true, | ||
connectedAt: '2023-01-02', | ||
id: '2', | ||
disconnectedAt: null, | ||
metadata: {}, | ||
}, | ||
]; | ||
|
||
// Render the TcConnectedPlatforms component with the mock data | ||
render(<TcConnectedPlatforms connectedPlatforms={connectedPlatforms} />); | ||
|
||
// Check if the platform title from mock data is rendered | ||
const allPlatformTitleElements = screen.getAllByText('Discord'); | ||
expect(allPlatformTitleElements[0]).toBeInTheDocument(); | ||
// Check if the platform names are rendered correctly | ||
const platform1Element = screen.getByText('Platform 1'); | ||
const platform2Element = screen.getByText('Platform 2'); | ||
|
||
// Check if the community name from mock data is rendered | ||
const communityNameElement = screen.getByText('Togethercrew'); | ||
expect(communityNameElement).toBeInTheDocument(); | ||
expect(platform1Element).toBeInTheDocument(); | ||
expect(platform2Element).toBeInTheDocument(); | ||
}); | ||
}); |
36 changes: 17 additions & 19 deletions
36
src/components/communitySettings/communityIntegrations/TcConnectedPlatformsItem.spec.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 |
---|---|---|
@@ -1,29 +1,27 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
import TcConnectedPlatformsItem from './TcConnectedPlatformsItem'; | ||
|
||
describe('<TcConnectedPlatformsItem />', () => { | ||
it('renders the platform title, icon, status, and community info', () => { | ||
const MockIcon = () => <span>MockIcon</span>; | ||
|
||
render( | ||
<TcConnectedPlatformsItem | ||
icon={<MockIcon />} | ||
platformTitle="Mock Platform" | ||
status={true} | ||
community={{ | ||
logo: 'https://example.com/logo.png', | ||
name: 'Mock Community', | ||
}} | ||
/> | ||
); | ||
const mockPlatform = { | ||
name: 'Discord', | ||
community: 'Mock Community', | ||
isInProgress: false, | ||
connectedAt: '2021-01-01', | ||
id: '1', | ||
disconnectedAt: null, | ||
metadata: { | ||
profileImageUrl: 'https://example.com/image.png', | ||
name: 'Example Community', | ||
username: 'exampleuser', | ||
icon: 'icon-id', | ||
}, | ||
}; | ||
|
||
// Checking the platform title | ||
expect(screen.getByText('Mock Platform')).toBeInTheDocument(); | ||
it('renders the platform title, status, and community info', () => { | ||
render(<TcConnectedPlatformsItem platform={mockPlatform} />); | ||
|
||
// Checking the icon | ||
expect(screen.getByText('MockIcon')).toBeInTheDocument(); | ||
expect(screen.getByText('Discord')).toBeInTheDocument(); | ||
}); | ||
}); |
53 changes: 29 additions & 24 deletions
53
src/components/communitySettings/communityIntegrations/TcConnectedPlatformsItem.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
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
Oops, something went wrong.