Skip to content

Commit

Permalink
Merge branch 'develop' into MHP-3132
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNoodleMoose authored Feb 5, 2020
2 parents 39065f7 + 8c39933 commit 8bfd322
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 29 deletions.
78 changes: 78 additions & 0 deletions src/actions/__tests__/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,84 @@ describe('navigateToCelebrateComments', () => {
});
});

describe('no celebrationItemId', () => {
describe('Cru org | undefined', () => {
beforeEach(() => {
store.dispatch<any>(navigateToCelebrateComments(cruOrg, undefined));
});

it('navigates to community celebrate feed if celebrationItemId is not present', () => {
expect(store.getActions()).toEqual([
{
type: 'Navigation/PUSH',
routeName: GROUP_SCREEN,
params: {
orgId: cruOrgId,
initialTab: undefined,
},
},
]);
});
});

describe('Cru org | null', () => {
beforeEach(() => {
store.dispatch<any>(navigateToCelebrateComments(cruOrg, null));
});

it('navigates to community celebrate feed if celebrationItemId is not present', () => {
expect(store.getActions()).toEqual([
{
type: 'Navigation/PUSH',
routeName: GROUP_SCREEN,
params: {
orgId: cruOrgId,
initialTab: undefined,
},
},
]);
});
});

describe('user-created Org | undefined', () => {
beforeEach(() => {
store.dispatch<any>(
navigateToCelebrateComments(userCreatedOrg, undefined),
);
});
it('navigates to community celebrate feed if celebrationItemId is not present', () => {
expect(store.getActions()).toEqual([
{
type: 'Navigation/PUSH',
routeName: USER_CREATED_GROUP_SCREEN,
params: {
orgId: userCreatedOrgId,
initialTab: undefined,
},
},
]);
});
});

describe('user-created Org | null', () => {
beforeEach(() => {
store.dispatch<any>(navigateToCelebrateComments(userCreatedOrg, null));
});
it('navigates to community celebrate feed if celebrationItemId is not present', () => {
expect(store.getActions()).toEqual([
{
type: 'Navigation/PUSH',
routeName: USER_CREATED_GROUP_SCREEN,
params: {
orgId: userCreatedOrgId,
initialTab: undefined,
},
},
]);
});
});
});

describe('Cru org', () => {
beforeEach(() => {
store.dispatch<any>(navigateToCelebrateComments(cruOrg, celebrateItemId));
Expand Down
53 changes: 53 additions & 0 deletions src/actions/__tests__/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,59 @@ describe('askNotificationPermissions', () => {
});
});

describe('celebrate_feed', () => {
it('should navigate to community celebrate feed', async () => {
await testNotification({
screen: 'celebrate_feed',
organization_id: organization.id,
screen_extra_data: {
celebration_item_id: undefined,
},
});

expect(refreshCommunity).toHaveBeenCalledWith(organization.id);
expect(navigateToCommunity).toHaveBeenCalledWith(organization);
});
it('should not navigate if no organization_id', async () => {
await testNotification({
screen: 'celebrate_feed',
organization_id: undefined,
screen_extra_data: {
celebration_item_id: undefined,
},
});

expect(refreshCommunity).not.toHaveBeenCalled();
expect(navigateToCommunity).not.toHaveBeenCalled();
});
});

describe('celebrate_item', () => {
it('should navigate to CELEBRATION_DETAIL_SCREEN', async () => {
await testNotification({
screen: 'celebrate_item',
organization_id: organization.id,
screen_extra_data,
});

expect(refreshCommunity).toHaveBeenCalledWith(organization.id);
expect(navigateToCelebrateComments).toHaveBeenCalledWith(
organization,
celebration_item_id,
);
});
it('should not navigate if no organization_id', async () => {
await testNotification({
screen: 'celebrate_item',
organization_id: undefined,
screen_extra_data,
});

expect(refreshCommunity).not.toHaveBeenCalled();
expect(navigateToCelebrateComments).not.toHaveBeenCalled();
});
});

describe('celebrate', () => {
it('should look for stored org', async () => {
await testNotification({
Expand Down
32 changes: 18 additions & 14 deletions src/actions/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,30 @@ export function navigateToCommunity(

export function navigateToCelebrateComments(
community: Organization,
celebrationItemId: string,
celebrationItemId?: string | null,
) {
return async (dispatch: ThunkDispatch<{}, null, AnyAction>) => {
const orgId = community.id;
const userCreated = orgIsUserCreated(community);

const event = { id: celebrationItemId, organization: community };

await dispatch(
navigateNestedReset([
{
routeName: getScreenForOrg(orgId, userCreated),
params: { orgId },
},
{
routeName: GROUP_UNREAD_FEED_SCREEN,
params: { organization: community },
},
{ routeName: CELEBRATE_DETAIL_SCREEN, params: { event } },
]),
);
if (celebrationItemId) {
await dispatch(
navigateNestedReset([
{
routeName: getScreenForOrg(orgId, userCreated),
params: { orgId },
},
{
routeName: GROUP_UNREAD_FEED_SCREEN,
params: { organization: community },
},
{ routeName: CELEBRATE_DETAIL_SCREEN, params: { event } },
]),
);
} else {
dispatch(navigateToCommunity(community));
}
};
}
10 changes: 9 additions & 1 deletion src/actions/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function showNotificationPrompt(notificationType, doNotNavigateBack) {
}

return new Promise(resolve =>
// @ts-ignore
PushNotification.checkPermissions(permission => {
// Android does not need to ask user for notification permissions
if (permission && permission.alert) {
Expand Down Expand Up @@ -95,6 +96,7 @@ export function configureNotificationHandler() {
// @ts-ignore
return (dispatch, getState) => {
PushNotification.configure({
// @ts-ignore
onRegister(t) {
const { pushDevice } = getState().notifications;

Expand All @@ -107,7 +109,7 @@ export function configureNotificationHandler() {
// @ts-ignore
async onNotification(notification = {}) {
await dispatch(handleNotification(notification));

// @ts-ignore
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
// ANDROID ONLY: GCM Sender ID
Expand Down Expand Up @@ -158,7 +160,13 @@ function handleNotification(notification) {
organization: { id: organization_id },
}),
);
case 'celebrate_feed':
if (organization_id) {
const community = await dispatch(refreshCommunity(organization_id));
return dispatch(navigateToCommunity(community));
}
case 'celebrate':
case 'celebrate_item':
if (organization_id) {
const community = await dispatch(refreshCommunity(organization_id));
return dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1552,15 +1552,6 @@ exports[`renders for member renders correctly 1`] = `
}
}
/>
<ShareStoryInput
dispatch={[Function]}
organization={
Object {
"id": "456",
}
}
refreshItems={[Function]}
/>
</View>
<View
onLayout={[Function]}
Expand Down
12 changes: 7 additions & 5 deletions src/containers/CelebrateFeed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ const CelebrateFeed = ({
const renderHeader = () => (
<>
<CelebrateFeedHeader isMember={!!person} organization={organization} />
<ShareStoryInput
dispatch={dispatch}
refreshItems={handleRefreshing}
organization={organization}
/>
{!person ? (
<ShareStoryInput
dispatch={dispatch}
refreshItems={handleRefreshing}
organization={organization}
/>
) : null}
</>
);

Expand Down

0 comments on commit 8bfd322

Please sign in to comment.