Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-notifications
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
冷佳娟
react-native-notifications
Commits
f666b856
Commit
f666b856
authored
Jul 31, 2019
by
yogevbd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Done converting the js part to typescript
parent
6c99242e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
14 deletions
+45
-14
lib/src/Notifications.ts
lib/src/Notifications.ts
+9
-5
lib/src/adapters/UniqueIdProvider.ts
lib/src/adapters/UniqueIdProvider.ts
+7
-0
lib/src/commands/Commands.test.ts
lib/src/commands/Commands.test.ts
+24
-6
lib/src/commands/Commands.ts
lib/src/commands/Commands.ts
+5
-3
No files found.
lib/src/Notifications.ts
View file @
f666b856
...
...
@@ -3,18 +3,22 @@ import { NativeEventsReceiver } from './adapters/NativeEventsReceiver';
import
{
Commands
}
from
'
./commands/Commands
'
;
import
{
EventsRegistry
}
from
'
./events/EventsRegistry
'
;
import
{
Notification
,
NotificationCategory
}
from
'
./interfaces/Notification
'
;
import
{
UniqueIdProvider
}
from
'
./adapters/UniqueIdProvider
'
;
export
class
NotificationsRoot
{
private
readonly
nativeEventsReceiver
:
NativeEventsReceiver
;
private
readonly
nativeCommandsSender
:
NativeCommandsSender
;
private
readonly
commands
:
Commands
;
private
readonly
eventsRegistry
:
EventsRegistry
;
private
readonly
uniqueIdProvider
:
UniqueIdProvider
;
constructor
()
{
this
.
nativeEventsReceiver
=
new
NativeEventsReceiver
();
this
.
nativeCommandsSender
=
new
NativeCommandsSender
();
this
.
uniqueIdProvider
=
new
UniqueIdProvider
();
this
.
commands
=
new
Commands
(
this
.
nativeCommandsSender
this
.
nativeCommandsSender
,
this
.
uniqueIdProvider
);
this
.
eventsRegistry
=
new
EventsRegistry
(
this
.
nativeEventsReceiver
);
}
...
...
@@ -36,8 +40,8 @@ export class NotificationsRoot {
/**
* Reset the app to a new layout
*/
public
localNotification
(
notification
:
Notification
)
{
return
this
.
commands
.
sendLocalNotification
(
notification
);
public
localNotification
(
notification
:
Notification
,
id
:
string
)
{
return
this
.
commands
.
sendLocalNotification
(
notification
,
id
);
}
/**
...
...
@@ -86,8 +90,8 @@ export class NotificationsRoot {
/**
* isRegisteredForRemoteNotifications
*/
public
isRegisteredForRemoteNotifications
():
Promise
<
any
>
{
this
.
commands
.
isRegisteredForRemoteNotifications
();
public
isRegisteredForRemoteNotifications
():
Promise
<
boolean
>
{
return
this
.
commands
.
isRegisteredForRemoteNotifications
();
}
/**
...
...
lib/src/adapters/UniqueIdProvider.ts
0 → 100644
View file @
f666b856
import
*
as
_
from
'
lodash
'
;
export
class
UniqueIdProvider
{
generate
(
prefix
?:
string
):
string
{
return
_
.
uniqueId
(
prefix
);
}
}
lib/src/commands/Commands.test.ts
View file @
f666b856
...
...
@@ -4,16 +4,20 @@ import { mock, verify, instance, deepEqual, when, anything, anyString } from 'ts
import
{
Commands
}
from
'
./Commands
'
;
import
{
NativeCommandsSender
}
from
'
../adapters/NativeCommandsSender
'
;
import
{
Notification
,
NotificationCategory
,
NotificationPermissions
}
from
'
../interfaces/Notification
'
;
import
{
UniqueIdProvider
}
from
'
../adapters/UniqueIdProvider
'
;
describe
(
'
Commands
'
,
()
=>
{
let
uut
:
Commands
;
let
mockedNativeCommandsSender
:
NativeCommandsSender
;
let
mockedUniqueIdProvider
:
UniqueIdProvider
;
beforeEach
(()
=>
{
mockedNativeCommandsSender
=
mock
(
NativeCommandsSender
);
mockedUniqueIdProvider
=
mock
(
UniqueIdProvider
);
when
(
mockedUniqueIdProvider
.
generate
(
anything
())).
thenCall
((
prefix
)
=>
`
${
prefix
}
+UNIQUE_ID`
);
uut
=
new
Commands
(
instance
(
mockedNativeCommandsSender
)
instance
(
mockedNativeCommandsSender
),
instance
(
mockedUniqueIdProvider
)
);
});
...
...
@@ -24,11 +28,12 @@ describe('Commands', () => {
});
it
(
'
returns a promise with the initial notification
'
,
async
()
=>
{
const
expectedNotification
:
Notification
=
{
data
:
{},
alert
:
'
alert
'
};
when
(
mockedNativeCommandsSender
.
getInitialNotification
()).
thenResolve
(
{
data
:
{}}
expectedNotification
);
const
result
=
await
uut
.
getInitialNotification
();
expect
(
result
).
toEqual
(
{
data
:
{}}
);
expect
(
result
).
toEqual
(
expectedNotification
);
});
});
...
...
@@ -72,7 +77,20 @@ describe('Commands', () => {
it
(
'
sends to native
'
,
()
=>
{
const
notification
:
Notification
=
{
data
:
{},
alert
:
'
alert
'
};
uut
.
sendLocalNotification
(
notification
);
verify
(
mockedNativeCommandsSender
.
sendLocalNotification
(
notification
,
'
id
'
)).
called
();
verify
(
mockedNativeCommandsSender
.
sendLocalNotification
(
notification
,
anyString
())).
called
();
});
it
(
'
generates unique identifier
'
,
()
=>
{
const
notification
:
Notification
=
{
data
:
{},
alert
:
'
alert
'
};
uut
.
sendLocalNotification
(
notification
);
verify
(
mockedNativeCommandsSender
.
sendLocalNotification
(
notification
,
`Notification_+UNIQUE_ID`
)).
called
();
});
it
(
'
use passed notification id
'
,
()
=>
{
const
notification
:
Notification
=
{
data
:
{},
alert
:
'
alert
'
};
const
passedId
:
string
=
"
passedId
"
;
uut
.
sendLocalNotification
(
notification
,
passedId
);
verify
(
mockedNativeCommandsSender
.
sendLocalNotification
(
notification
,
passedId
)).
called
();
});
});
...
...
lib/src/commands/Commands.ts
View file @
f666b856
import
*
as
_
from
'
lodash
'
;
import
{
NativeCommandsSender
}
from
'
../adapters/NativeCommandsSender
'
;
import
{
Notification
,
NotificationCategory
,
NotificationPermissions
}
from
'
../interfaces/Notification
'
;
import
{
UniqueIdProvider
}
from
'
../adapters/UniqueIdProvider
'
;
export
class
Commands
{
constructor
(
private
readonly
nativeCommandsSender
:
NativeCommandsSender
private
readonly
nativeCommandsSender
:
NativeCommandsSender
,
private
readonly
uniqueIdProvider
:
UniqueIdProvider
)
{}
public
sendLocalNotification
(
notification
:
Notification
)
{
const
notificationId
=
'
id
'
;
public
sendLocalNotification
(
notification
:
Notification
,
id
?:
string
)
{
const
notificationId
=
id
?
id
:
this
.
uniqueIdProvider
.
generate
(
'
Notification_
'
)
;
const
result
=
this
.
nativeCommandsSender
.
sendLocalNotification
(
notification
,
notificationId
);
return
result
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment