generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #453 from divyansh0908/notification/local_notify
Notification/local notify
- Loading branch information
Showing
11 changed files
with
298 additions
and
182 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,9 @@ | ||
BASE_UTL= | ||
RDS_SESSION= | ||
FIREBASE_PROJECT_ID= | ||
FIREBASE_MESSAGING_SENDER_ID= | ||
FIREBASE_STORAGE_BUCKET= | ||
MOBILE_SDK_APP_ID= | ||
OAUTH_CLIENT_ID= | ||
FIREBASE_CURRENT_API_KEY= | ||
OTHER_PLATFORM_OAUTH_CLIENT_ID= |
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 |
---|---|---|
|
@@ -61,6 +61,9 @@ buck-out/ | |
# CocoaPods | ||
/ios/Pods/ | ||
|
||
# ignore google-services | ||
/android/app/google-services.json | ||
|
||
|
||
|
||
#env | ||
|
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,130 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, waitFor } from '@testing-library/react-native'; | ||
import NotifyForm from '../../../src/components/Notify/NotifyForm'; | ||
import { AuthContext } from '../../../src/context/AuthContext'; | ||
import { | ||
postFcmToken, | ||
getAllUsers, | ||
sendNotification, | ||
} from '../../../src/screens/AuthScreen/Util'; | ||
|
||
// Mock the functions used in the component | ||
jest.mock('../../../src/screens/AuthScreen/Util', () => ({ | ||
postFcmToken: jest.fn(), | ||
sendNotification: jest.fn(), | ||
getAllUsers: jest.fn(() => Promise.resolve([])), // Mock getAllUsers with an empty array | ||
})); | ||
|
||
jest.mock('@react-native-firebase/messaging', () => ({ | ||
firebase: { | ||
messaging: jest.fn(() => ({ | ||
getToken: jest.fn(() => Promise.resolve('mocked-fcm-token')), | ||
hasPermission: jest.fn(() => Promise.resolve(1)), // Mock permission granted | ||
requestPermission: jest.fn(() => Promise.resolve()), // Mock permission request | ||
})), | ||
}, | ||
})); | ||
|
||
describe('NotifyForm', () => { | ||
const loggedInUserData = { token: 'user-token' }; | ||
|
||
const renderComponent = () => { | ||
return render( | ||
<AuthContext.Provider value={{ loggedInUserData }}> | ||
<NotifyForm /> | ||
</AuthContext.Provider>, | ||
); | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders the form with title, description, and Notify button', () => { | ||
const { getByText, getByPlaceholderText } = renderComponent(); | ||
|
||
expect(getByText('Title:')).toBeTruthy(); | ||
expect(getByText('Description:')).toBeTruthy(); | ||
expect(getByText('Notify To:')).toBeTruthy(); | ||
expect(getByPlaceholderText('Enter title')).toBeTruthy(); | ||
expect(getByPlaceholderText('Enter description')).toBeTruthy(); | ||
expect(getByText('Notify')).toBeTruthy(); | ||
}); | ||
|
||
it('Calls postFcmToken', async () => { | ||
renderComponent(); | ||
|
||
await waitFor(() => { | ||
expect(postFcmToken).toHaveBeenCalledWith( | ||
'mocked-fcm-token', | ||
'user-token', | ||
); | ||
}); | ||
}); | ||
|
||
it('fetches users and updates the dropdown', async () => { | ||
const mockUsers = [ | ||
{ id: '1', username: 'john_doe', first_name: 'John', last_name: 'Doe' }, | ||
{ id: '2', username: 'jane_doe', first_name: 'Jane', last_name: 'Doe' }, | ||
]; | ||
|
||
getAllUsers.mockResolvedValue(mockUsers); // Mock resolved users | ||
|
||
const { getByTestId, getByText } = renderComponent(); | ||
|
||
// Wait for users to load | ||
await waitFor(() => { | ||
expect(getAllUsers).toHaveBeenCalledWith('user-token'); | ||
}); | ||
|
||
const dropdown = getByTestId('dropdown'); | ||
fireEvent.press(dropdown); // Simulate dropdown press to show user list | ||
|
||
await waitFor(() => { | ||
expect(getByText('john_doe')).toBeTruthy(); | ||
expect(getByText('jane_doe')).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
it('selects a user from the dropdown and sends a notification', async () => { | ||
const mockUsers = [ | ||
{ id: '1', username: 'john_doe', first_name: 'John', last_name: 'Doe' }, | ||
]; | ||
|
||
getAllUsers.mockResolvedValue(mockUsers); | ||
|
||
const { getByTestId, getByPlaceholderText, getByText } = renderComponent(); | ||
|
||
// Wait for users to load | ||
await waitFor(() => { | ||
expect(getAllUsers).toHaveBeenCalledWith('user-token'); | ||
}); | ||
|
||
const dropdown = getByTestId('dropdown'); | ||
fireEvent.press(dropdown); // Open dropdown | ||
|
||
// Select a user from the dropdown | ||
await waitFor(() => { | ||
fireEvent.press(getByText('john_doe')); | ||
}); | ||
|
||
// Fill in title and description | ||
fireEvent.changeText(getByPlaceholderText('Enter title'), 'Test Title'); | ||
fireEvent.changeText( | ||
getByPlaceholderText('Enter description'), | ||
'Test Description', | ||
); | ||
|
||
// Press Notify button | ||
fireEvent.press(getByText('Notify')); | ||
|
||
await waitFor(() => { | ||
expect(sendNotification).toHaveBeenCalledWith( | ||
'Test Title', | ||
'Test Description', | ||
'1', | ||
'user-token', | ||
); | ||
}); | ||
}); | ||
}); |
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,33 +1,27 @@ | ||
import React from 'react'; | ||
import { render, waitFor } from '@testing-library/react-native'; | ||
import { render } from '@testing-library/react-native'; | ||
import NotifyScreen from '../../src/screens/NotifyScreen/NotifyScreen'; | ||
import { postFcmToken } from '../../src/screens/AuthScreen/Util'; | ||
import { firebase } from '@react-native-firebase/messaging'; | ||
|
||
jest.mock('../../src/screens/AuthScreen/Util', () => ({ | ||
postFcmToken: jest.fn(), | ||
sendNotification: jest.fn(), | ||
getAllUsers: jest.fn(() => Promise.resolve([])), // Mock getAllUsers with an empty array | ||
})); | ||
|
||
jest.mock('@react-native-firebase/messaging', () => ({ | ||
firebase: { | ||
messaging: jest.fn(() => ({ | ||
getToken: jest.fn(() => Promise.resolve('mocked-fcm-token')), | ||
hasPermission: jest.fn(() => Promise.resolve(1)), // Mock permission granted | ||
requestPermission: jest.fn(() => Promise.resolve()), // Mock permission request | ||
})), | ||
}, | ||
})); | ||
jest.mock('../../src/screens/AuthScreen/Util', () => ({ | ||
postFcmToken: jest.fn(), | ||
})); | ||
describe('NotifyScreen', () => { | ||
it('should render correctly with title and NotifyForm', async () => { | ||
const { getByText } = render(<NotifyScreen />); | ||
|
||
expect(getByText('Event Notifications')).toBeTruthy(); | ||
|
||
await waitFor(() => { | ||
expect(firebase.messaging().getToken).toHaveBeenCalled(); | ||
}); | ||
await waitFor(() => | ||
expect(postFcmToken).toHaveBeenCalledWith( | ||
'mocked-fcm-token', | ||
'user-token', | ||
), | ||
); | ||
// Wait for the getToken to be called | ||
}); | ||
}); |
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,12 @@ | ||
#!usr/bin/env node | ||
run('node ./src/service/googleServiceTemplate.js'); | ||
|
||
function run(command) { | ||
console.info(`./bin/postInstall scripit running: ${command}`); | ||
try { | ||
require('child_process').execSync(command, { stdio: 'inherit' }); | ||
} catch (err) { | ||
console.error(`./bin/postInstall failed on command ${command}`); | ||
process.exit(err.status); | ||
} | ||
} |
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.