generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notification/local notify #439
Open
shreya-mishra
wants to merge
25
commits into
develop
Choose a base branch
from
notification/local_notify
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
0832f2c
updated the way we notify locally
shreya1mishra fb23fc6
fix ui of notify screen button
shreya1mishra 48dc277
integtrated the notify api
shreya1mishra 339b35a
updated the api and applied on form
shreya1mishra aeca783
added firebase messaging package
shreya1mishra e839964
getting urls from env
shreya1mishra 396ebe2
getting url from staging
shreya1mishra 748aa7e
fix cookie issue
shreya1mishra 789712a
refactor: Remove the unused props
divyansh0908 73da022
style: Give some style to notification's title
divyansh0908 dfef746
feat: Add env template
divyansh0908 a2bc9ea
fix: Remove git tracking of google-services.json
divyansh0908 8a0876c
feat: Add postinstall script to generate google-services.json
divyansh0908 7f730fd
refactor: Remove google-services.json
divyansh0908 e0a78d3
notify test cases
shreya1mishra 73d9359
Merge branch 'Real-Dev-Squad:notification/local_notify' into notifica…
divyansh0908 63d6e16
fix: Remove unused code from `NotificationScreen`
divyansh0908 0fb6d0a
fix: Write test according to the modified code
divyansh0908 179b039
feat: Update notify form to request for notification
divyansh0908 b30102a
feat: Add test for notification form component
divyansh0908 3b806be
feat: Add ios package for firebase notification
divyansh0908 c761f8d
feat: Update test for NotifyScreen and NotificationForm
divyansh0908 9465ff4
chore: Remove console logs
divyansh0908 9150ce9
style: Update fontSize to use responsive value
divyansh0908 02ad0ff
Merge pull request #453 from divyansh0908/notification/local_notify
shreya-mishra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
import NotifyScreen from '../../src/screens/NotifyScreen/NotifyScreen'; | ||
|
||
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('NotifyScreen', () => { | ||
it('should render correctly with title and NotifyForm', async () => { | ||
const { getByText } = render(<NotifyScreen />); | ||
|
||
expect(getByText('Event Notifications')).toBeTruthy(); | ||
// Wait for the getToken to be called | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<color name="white">#FFF</color> | ||
</resources> |
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
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
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,6 +1,14 @@ | ||
import { jest } from '@jest/globals'; | ||
import mockRNDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock'; | ||
|
||
require('react-native-reanimated/lib/reanimated2/jestUtils').setUpTests(); | ||
jest.mock('react-native-device-info', () => mockRNDeviceInfo); | ||
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter'); | ||
jest.mock('@react-native-firebase/app', () => { | ||
return { | ||
firebase: { | ||
app: jest.fn(() => ({ | ||
initializeApp: jest.fn(), | ||
})), | ||
messaging: jest.fn(() => ({ | ||
getToken: jest.fn(), | ||
})), | ||
}, | ||
}; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import PushNotification from 'react-native-push-notification'; | ||
|
||
const LocalNotification = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const key = Date.now().toString(); // Key must be unique everytime | ||
PushNotification.createChannel( | ||
{ | ||
channelId: key, // (required) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
channelName: 'Local messasge', // (required) | ||
channelDescription: 'Notification for Local message', // (optional) default: undefined. | ||
importance: 4, // (optional) default: 4. Int value of the Android notification importance | ||
vibrate: true, // (optional) default: true. Creates the default vibration patten if true. | ||
}, | ||
(created) => console.log(`createChannel returned '${created}'`), // (optional) callback returns whether the channel was created, false means it already existed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
); | ||
PushNotification.localNotification({ | ||
channelId: key, //this must be same with channelid in createchannel | ||
title: 'Local Message', | ||
message: 'Local message !!', | ||
}); | ||
}; | ||
|
||
export default LocalNotification; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.