-
Notifications
You must be signed in to change notification settings - Fork 1
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
7 changed files
with
184 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react'; | ||
import { fireEvent } from '@testing-library/react-native'; | ||
import StreamPreviewImage from '../../src/components/StreamPreviewImage'; // Adjust the path as necessary | ||
import { customRender } from '../test_utils/customRender'; | ||
|
||
describe('StreamPreviewImage', () => { | ||
const handleAddImageMock = jest.fn(); | ||
const clearImageMock = jest.fn(); | ||
|
||
beforeEach(() => { | ||
handleAddImageMock.mockClear(); | ||
clearImageMock.mockClear(); | ||
}); | ||
|
||
it('customRenders correctly without image', () => { | ||
const { getByTestId, queryByTestId } = customRender( | ||
<StreamPreviewImage | ||
uri={null} | ||
handleAddImage={handleAddImageMock} | ||
clearImage={clearImageMock} | ||
/> | ||
); | ||
|
||
expect(queryByTestId('add-image-button')).toBeTruthy(); | ||
expect(queryByTestId('clear-image-button')).toBeFalsy(); | ||
}); | ||
|
||
it('customRenders correctly with image', () => { | ||
const { getByTestId, queryByTestId } = customRender( | ||
<StreamPreviewImage | ||
uri="https://example.com/image.jpg" | ||
handleAddImage={handleAddImageMock} | ||
clearImage={clearImageMock} | ||
/> | ||
); | ||
|
||
expect(queryByTestId('add-image-button')).toBeFalsy(); | ||
expect(queryByTestId('clear-image-button')).toBeTruthy(); | ||
}); | ||
|
||
it('calls handleAddImage when add image button is pressed', () => { | ||
const { getByTestId } = customRender( | ||
<StreamPreviewImage | ||
uri={null} | ||
handleAddImage={handleAddImageMock} | ||
clearImage={clearImageMock} | ||
/> | ||
); | ||
|
||
fireEvent.press(getByTestId('add-image-button')); | ||
expect(handleAddImageMock).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('calls clearImage when clear image button is pressed', () => { | ||
const { getByTestId } = customRender( | ||
<StreamPreviewImage | ||
uri="https://example.com/image.jpg" | ||
handleAddImage={handleAddImageMock} | ||
clearImage={clearImageMock} | ||
/> | ||
); | ||
|
||
fireEvent.press(getByTestId('clear-image-button')); | ||
expect(clearImageMock).toHaveBeenCalledTimes(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,59 @@ | ||
import { fireEvent } from '@testing-library/react-native'; | ||
import React from 'react'; | ||
|
||
import useAuth from '../../../src/modules/auth/useAuth'; | ||
import SettingsList from '../../../src/modules/settings/SettingsList'; // Adjust the path as necessary | ||
import { settingSectionsMap } from '../../../src/modules/settings/settings'; // Adjust the path as necessary | ||
import { customRender } from '../../test_utils/customRender'; | ||
|
||
// Mock the useAuth hook | ||
jest.mock('@modules/auth/useAuth', () => ({ | ||
__esModule: true, | ||
default: jest.fn(), | ||
})); | ||
|
||
describe('SettingsList', () => { | ||
const mockSignOut = jest.fn(); | ||
const originalConsoleLog = console.log; | ||
|
||
beforeEach(() => { | ||
(useAuth as jest.Mock).mockReturnValue({ signOut: mockSignOut }); | ||
console.log = jest.fn(); // Mock console.log | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
console.log = originalConsoleLog; // Restore console.log | ||
}); | ||
it('renders all settings sections and items correctly', () => { | ||
const { getByTestId } = customRender(<SettingsList />); | ||
|
||
Object.entries(settingSectionsMap).forEach(([key, items]) => { | ||
// Check if the section header is rendered | ||
expect(getByTestId(`${key}-header`)).toBeTruthy(); | ||
|
||
// Check if all items in the section are rendered | ||
items.forEach((item) => { | ||
expect(getByTestId(`${item}-button`)).toBeTruthy(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('triggers the correct action on item press', () => { | ||
const { getByTestId } = customRender(<SettingsList />); | ||
|
||
Object.entries(settingSectionsMap).forEach(([_, items]) => { | ||
items.forEach((item) => { | ||
// Trigger the onPress event | ||
fireEvent.press(getByTestId(`${item}-button`)); | ||
|
||
// Check console log or signOut action | ||
if (item === 'Logout') { | ||
expect(mockSignOut).toHaveBeenCalled(); | ||
} else { | ||
expect(console.log).toHaveBeenCalled(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
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,53 @@ | ||
import { settingSectionsMap } from '../../../src/modules/settings/settings'; | ||
|
||
describe('settingSectionMap', () => { | ||
it('Should have expected Keys', () => { | ||
expect(Object.keys(settingSectionsMap)).toHaveLength(8); | ||
expect(Object.keys(settingSectionsMap)).toEqual([ | ||
'Account', | ||
'Livestream Settings', | ||
'Privacy and Safety', | ||
'Notifications', | ||
'Support and Feedback', | ||
'Legal', | ||
'About', | ||
'Logout', | ||
]); | ||
}); | ||
|
||
it('Key value should have expected length', () => { | ||
const valueLength = [4, 2, 3, 2, 3, 3, 4, 1]; | ||
|
||
Object.keys(settingSectionsMap).forEach((key, index) => { | ||
expect(settingSectionsMap[key]).toHaveLength(valueLength[index]); | ||
}); | ||
}); | ||
|
||
it('Key should have expected value', () => { | ||
expect(settingSectionsMap.Account).toEqual(['Profile', 'Security', 'Shares', 'Permissions']); | ||
expect(settingSectionsMap['Livestream Settings']).toEqual(['Preferences', 'Chat Options']); | ||
expect(settingSectionsMap['Privacy and Safety']).toEqual([ | ||
'Privacy', | ||
'Content Moderation', | ||
'Blocked Users', | ||
]); | ||
expect(settingSectionsMap.Notifications).toEqual(['General', 'Livestream']); | ||
expect(settingSectionsMap['Support and Feedback']).toEqual([ | ||
'Help Center', | ||
'Report a Problem', | ||
'Rate Us', | ||
]); | ||
expect(settingSectionsMap.Legal).toEqual([ | ||
'Terms of Service', | ||
'Privacy Policy', | ||
'Community Guidelines', | ||
]); | ||
expect(settingSectionsMap.About).toEqual([ | ||
'Version', | ||
'Developer Info', | ||
'Release Notes', | ||
'Join Beta Program', | ||
]); | ||
expect(settingSectionsMap.Logout).toEqual(['Logout']); | ||
}); | ||
}); |
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