-
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
Sep 27, 2023
1 parent
2051448
commit b3d7543
Showing
7 changed files
with
210 additions
and
111 deletions.
There are no files selected for viewing
48 changes: 28 additions & 20 deletions
48
src/components/twitter/growth/accountActivity/TcAccountActivityHeader.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,34 +1,42 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { StorageService } from '../../../../services/StorageService'; | ||
import TcAccountActivityHeader from './TcAccountActivityHeader'; | ||
|
||
jest.mock('../../../../services/StorageService'); | ||
|
||
describe('<TcAccountActivityHeader />', () => { | ||
// Test 1: Check if the component renders correctly | ||
it('renders without crashing', () => { | ||
render(<TcAccountActivityHeader />); | ||
}); | ||
beforeEach(() => { | ||
// Mocking the `readLocalStorage` method | ||
const mockedReadLocalStorage = | ||
StorageService.readLocalStorage as jest.MockedFunction< | ||
typeof StorageService.readLocalStorage | ||
>; | ||
|
||
mockedReadLocalStorage.mockReturnValue({ | ||
twitter: { | ||
twitterUsername: 'testUser', | ||
}, | ||
}); | ||
|
||
// Test 2: Check if the expected texts are displayed | ||
it('displays the expected texts', () => { | ||
render(<TcAccountActivityHeader />); | ||
}); | ||
|
||
expect(screen.getByText('Account activity')).toBeInTheDocument(); | ||
expect(screen.getByText('Data over the last 7 days')).toBeInTheDocument(); | ||
expect(screen.getByText('Analyzed account:')).toBeInTheDocument(); | ||
expect(screen.getByText('@daoxyz')).toBeInTheDocument(); | ||
it('renders the main header text', () => { | ||
const headerText = screen.getByText('Account activity'); | ||
expect(headerText).toBeInTheDocument(); | ||
}); | ||
|
||
// Test 3: Check if the BiTimeFive icon (SVG) is rendered using data-testid | ||
it('renders the BiTimeFive icon (SVG)', () => { | ||
render(<TcAccountActivityHeader />); | ||
const svgIcon = screen.getByTestId('bi-time-five-icon'); | ||
expect(svgIcon).toBeInTheDocument(); | ||
it('renders the time information with an icon', () => { | ||
const timeInfoText = screen.getByText('Data over the last 7 days'); | ||
const timeIcon = screen.getByTestId('bi-time-five-icon'); | ||
expect(timeInfoText).toBeInTheDocument(); | ||
expect(timeIcon).toBeInTheDocument(); | ||
}); | ||
|
||
// Test 4: Check if TcLink with the to prop as '/' is rendered | ||
it('renders TcLink with to prop as "/"', () => { | ||
render(<TcAccountActivityHeader />); | ||
const link = screen.getByRole('link', { name: /@daoxyz/i }); | ||
expect(link).toHaveAttribute('href', '/'); | ||
it('renders the analyzed account username when provided', () => { | ||
const usernameLink = screen.getByText('@testUser'); | ||
expect(usernameLink).toBeInTheDocument(); | ||
expect(usernameLink).toHaveAttribute('href', '/settings'); | ||
}); | ||
}); |
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
55 changes: 40 additions & 15 deletions
55
src/components/twitter/growth/engagementAccounts/TcEngagementAccounts.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,24 +1,49 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import TcEngagementAccounts from './TcEngagementAccounts'; | ||
import TcEngagementAccountsHeader from './TcEngagementAccountsHeader'; | ||
|
||
// Mock the child components to simplify the test | ||
jest.mock('./TcEngagementAccountsHeader', () => () => ( | ||
<div data-testid="header-mock">Header</div> | ||
)); | ||
jest.mock('./TcEngagementAccountsContent', () => () => ( | ||
<div data-testid="content-mock">Content</div> | ||
)); | ||
describe('<TcEngagementAccounts />', () => { | ||
const mockEngagement = { | ||
hqla: 10, | ||
hqhe: 20, | ||
lqla: 15, | ||
lqhe: 25, | ||
}; | ||
|
||
describe('TcEngagementAccounts', () => { | ||
it('renders the component and checks presence of child components', () => { | ||
render(<TcEngagementAccounts />); | ||
beforeEach(() => { | ||
render(<TcEngagementAccounts engagement={mockEngagement} />); | ||
}); | ||
|
||
// Test 1: Check if the TcEngagementAccountsHeader component is rendered. | ||
it('renders the header component', () => { | ||
render(<TcEngagementAccountsHeader />); | ||
}); | ||
|
||
// Test 2: Check if the data is rendered correctly in the TcEngagementAccountsContent component. | ||
it('renders the correct engagement values and descriptions', () => { | ||
const descriptions = [ | ||
'Only engaged a bit but deeper interactions', | ||
'Frequently engaged and deep interactions', | ||
'Only engaged a bit and shallow interactions', | ||
'Frequently engaged but shallow interactions', | ||
]; | ||
|
||
// Check if the mocked header component is rendered | ||
expect(screen.getByTestId('header-mock')).toBeInTheDocument(); | ||
descriptions.forEach((description) => { | ||
expect(screen.getByText(description)).toBeInTheDocument(); | ||
}); | ||
|
||
// Check if the mocked content component is rendered | ||
expect(screen.getByTestId('content-mock')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText(mockEngagement.hqla.toString()) | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByText(mockEngagement.hqhe.toString()) | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByText(mockEngagement.lqla.toString()) | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByText(mockEngagement.lqhe.toString()) | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
62 changes: 50 additions & 12 deletions
62
src/components/twitter/growth/engagementAccounts/TcEngagementAccountsContent.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,23 +1,61 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import TcEngagementAccountsContent from './TcEngagementAccountsContent'; | ||
|
||
describe('TcEngagementAccountsContent', () => { | ||
it('renders the component and checks presence of key elements', () => { | ||
render(<TcEngagementAccountsContent />); | ||
describe('<TcEngagementAccountsContent />', () => { | ||
const mockContentItems = [ | ||
{ | ||
bgColor: 'bg-red', | ||
value: 10, | ||
description: 'Description 1', | ||
tooltipText: 'Tooltip 1', | ||
label: 'Label 1', | ||
}, | ||
{ | ||
bgColor: 'bg-blue', | ||
value: 20, | ||
description: 'Description 2', | ||
tooltipText: 'Tooltip 2', | ||
}, | ||
{ | ||
bgColor: 'bg-yellow', | ||
value: 30, | ||
description: 'Description 3', | ||
tooltipText: 'Tooltip 3', | ||
label: 'Label 3', | ||
}, | ||
{ | ||
bgColor: 'bg-green', | ||
value: 40, | ||
description: 'Description 4', | ||
tooltipText: 'Tooltip 4', | ||
}, | ||
]; | ||
|
||
expect(screen.getByText('Quality of engagement')).toBeInTheDocument(); | ||
expect(screen.getByText('Amount of engagement')).toBeInTheDocument(); | ||
beforeEach(() => { | ||
render(<TcEngagementAccountsContent contentItems={mockContentItems} />); | ||
}); | ||
|
||
const highTexts = screen.getAllByText(/High/i); | ||
highTexts.forEach((element) => { | ||
expect(element).toBeInTheDocument(); | ||
// Test 1: Check if the TcEngagementAccountContentItems component is rendered for each item. | ||
it('renders content items correctly', () => { | ||
mockContentItems.forEach((item) => { | ||
expect(screen.getByText(item.description)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
// Test 2: Check if the labels 'High' and 'Low' are rendered. | ||
it('renders the labels High and Low', () => { | ||
['High', 'Low'].forEach((label) => { | ||
expect(screen.getByText(label)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
const lowTexts = screen.getAllByText(/Low/i); | ||
lowTexts.forEach((element) => { | ||
expect(element).toBeInTheDocument(); | ||
// Test 3: Check if specific labels in content items are rendered. | ||
it('renders content item labels correctly', () => { | ||
mockContentItems.forEach((item) => { | ||
if (item.label) { | ||
expect(screen.getByText(item.label)).toBeInTheDocument(); | ||
} | ||
}); | ||
}); | ||
}); |
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.