-
Notifications
You must be signed in to change notification settings - Fork 0
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
Brian
committed
Apr 30, 2024
1 parent
1f1371a
commit 9319bfa
Showing
5 changed files
with
106 additions
and
181 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import { TabsItem, Tab } from './TabsItem'; | ||
|
||
describe('TabsItem', () => { | ||
const mockTab: Tab = { | ||
id: 1, | ||
text: 'Example Tab\nTimestamp', | ||
url: 'http://example.com', | ||
time: 'Timestamp', | ||
}; | ||
|
||
test('renders tab title and timestamp', () => { | ||
const onDelete = jest.fn(); | ||
const { getByText } = render(<TabsItem tab={mockTab} onDelete={onDelete} />); | ||
expect(getByText('Example Tab')).toBeInTheDocument(); | ||
expect(getByText('Timestamp')).toBeInTheDocument(); | ||
}); | ||
|
||
test('calls onDelete when delete button is clicked', () => { | ||
const onDelete = jest.fn(); | ||
const { getByText } = render(<TabsItem tab={mockTab} onDelete={onDelete} />); | ||
fireEvent.click(getByText('Delete')); | ||
expect(onDelete).toHaveBeenCalledWith(1); | ||
}); | ||
}); |
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,60 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import TabsList, { TabsListProps } from './TabsList'; | ||
import { Tab } from './TabsItem'; | ||
|
||
describe('TabsList', () => { | ||
const mockTabs: Tab[] = [ | ||
{ | ||
id: 1, | ||
text: 'Example Tab 1\nTimestamp 1', | ||
url: 'http://example.com/1', | ||
time: 'Timestamp 1', | ||
}, | ||
{ | ||
id: 2, | ||
text: 'Example Tab 2\nTimestamp 2', | ||
url: 'http://example.com/2', | ||
time: 'Timestamp 2', | ||
}, | ||
]; | ||
|
||
const onDeleteTabMock = jest.fn(); | ||
|
||
const renderComponent = (props: Partial<TabsListProps> = {}) => { | ||
const defaultProps: TabsListProps = { | ||
title: 'Tabs', | ||
tabs: mockTabs, | ||
onDeleteTab: onDeleteTabMock, | ||
}; | ||
return render(<TabsList {...defaultProps} {...props} />); | ||
}; | ||
|
||
test('renders title and tab count', () => { | ||
const { getByText } = renderComponent(); | ||
expect(getByText('Tabs (2)')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders tab list when title is clicked', () => { | ||
const { getByText, queryByText } = renderComponent(); | ||
expect(queryByText('Example Tab 1')).toBeNull(); | ||
expect(queryByText('Example Tab 2')).toBeNull(); | ||
|
||
fireEvent.click(getByText('Tabs (2)')); | ||
|
||
expect(getByText('Example Tab 1')).toBeInTheDocument(); | ||
expect(getByText('Example Tab 2')).toBeInTheDocument(); | ||
}); | ||
|
||
test('calls onDeleteTab when delete button of a tab is clicked', () => { | ||
const { getByText } = renderComponent(); | ||
fireEvent.click(getByText('Tabs (2)')); | ||
|
||
// Find the delete button within the first tab item and click it | ||
const deleteButton = getByText('Delete', { selector: 'li:nth-of-type(1) button' }); | ||
fireEvent.click(deleteButton); | ||
|
||
expect(onDeleteTabMock).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
}); |