Skip to content
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

MHP 3099 -- Convert Celebrate Feed to GraphQL & Add Polling #1444

Merged
merged 34 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3c25959
Convert GroupCelebrate to TypeScript
reldredge71 Jan 22, 2020
35ae948
New gql query
reldredge71 Jan 23, 2020
205f137
update GroupCelebrate, MemberCelebrate, and GroupUnreadFeed
reldredge71 Jan 23, 2020
52477fb
changes to GroupUnreadFeed
reldredge71 Jan 24, 2020
4f6a8e5
small fixes
reldredge71 Jan 24, 2020
67a10cf
Fix components off of CelebrateFeed
reldredge71 Jan 24, 2020
eb04c21
apply types to other screens
reldredge71 Jan 27, 2020
832b0ea
undo import
reldredge71 Jan 27, 2020
42e2bde
updates to reducers, selectors, and hooks
reldredge71 Jan 27, 2020
e3d6a64
more updates
reldredge71 Jan 27, 2020
592bbfd
start tests
reldredge71 Jan 28, 2020
7a3a9eb
CelebrateItem tests
reldredge71 Jan 29, 2020
e556aa3
CelebrateFeed tests
reldredge71 Jan 29, 2020
ab7ac8e
CelebrateFeed wrapper tests
reldredge71 Jan 29, 2020
efa739d
Tests for some other screens
reldredge71 Jan 30, 2020
afecbf0
more tests
reldredge71 Jan 30, 2020
7329d0c
Merge remote-tracking branch 'origin/develop' into MHP-3099
reldredge71 Jan 30, 2020
4828f04
small fixes
reldredge71 Jan 30, 2020
a8ae0fb
CommentsList tests
reldredge71 Jan 30, 2020
f8277b4
other small fixes
reldredge71 Jan 30, 2020
0824f2c
update actions -- remove celebrate feed stuff, apply typescript to ce…
reldredge71 Jan 31, 2020
d42074c
update CELEBRATEABLE_TYPES
reldredge71 Jan 31, 2020
359b62d
change query to descending
reldredge71 Jan 31, 2020
a9f1944
send onRefresh into CelebrateDetailScreen
reldredge71 Jan 31, 2020
73109e0
start adding fragments
reldredge71 Jan 31, 2020
381289b
work on tests
reldredge71 Jan 31, 2020
67a9df4
Merge remote-tracking branch 'origin/develop' into MHP-3099
reldredge71 Feb 3, 2020
1bc25c8
celebrateDetailScreen tests
reldredge71 Feb 3, 2020
036d816
add fragments to tests
reldredge71 Feb 3, 2020
fa4d72c
Other fixes
reldredge71 Feb 3, 2020
413fe99
Merge branch 'develop' into MHP-3099
reldredge71 Feb 3, 2020
6ff0175
remove notifyOnNetworkStatusChange
reldredge71 Feb 3, 2020
ca08b8b
Merge branch 'MHP-3099' of github.com:CruGlobal/missionhub-react-nati…
reldredge71 Feb 3, 2020
016a0ce
Merge branch 'develop' into MHP-3099
reldredge71 Feb 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/actions/__tests__/reportComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { celebrateCommentsSelector } from '../../selectors/celebrateComments';
import { trackActionWithoutData } from '../analytics';
import { ACTIONS } from '../../constants';
import { formatApiDate } from '../../utils/common';
import { CelebrateComment } from '../../reducers/celebrateComments';

jest.mock('../api');
jest.mock('../../selectors/celebrateComments');
Expand All @@ -40,7 +41,13 @@ beforeEach(() => {
});

describe('report comments', () => {
const item = { id: 'comment1' };
const item: CelebrateComment = {
id: 'comment1',
person: {},
created_at: '2019-04-11T13:51:49.888',
updated_at: '2019-04-11T13:51:49.888',
content: '',
};

it('should callApi for report', async () => {
const response = await store.dispatch<any>(reportComment(orgId, item));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,31 @@ import {
resetCelebrateEditingComment,
updateCelebrateComment,
} from '../../../actions/celebrateComments';
import { celebrationItemSelector } from '../../../selectors/celebration';
import { celebrateCommentsCommentSelector } from '../../../selectors/celebrateComments';
import { GetCelebrateFeed_community_celebrationItems_nodes } from '../../../containers/CelebrateFeed/__generated__/GetCelebrateFeed';

import CelebrateCommentBox from '..';

jest.mock('../../../selectors/celebration');
jest.mock('../../../selectors/celebrateComments');
jest.mock('../../../actions/celebrateComments');

const event = { text: 'some celebrate item', organization: { id: 'orgId' } };
const event: GetCelebrateFeed_community_celebrationItems_nodes = {
__typename: 'CommunityCelebrationItem',
id: '1',
adjectiveAttributeName: null,
adjectiveAttributeValue: null,
celebrateableId: '1',
celebrateableType: '',
changedAttributeName: '',
changedAttributeValue: '',
commentsCount: 0,
liked: true,
likesCount: 1,
objectDescription: null,
subjectPerson: null,
subjectPersonName: null,
};

const createCelebrateCommentResult = { type: 'created comment' };
const updateCelebrateCommentResult = { type: 'update comment' };
const resetCelebrateEditingCommentResult = { type: 'reset editing' };
Expand All @@ -27,7 +42,6 @@ const editingComment = {
};
const onAddComplete = jest.fn();
const initialState = {
organizations: [],
celebrateComments: {
editingCommentId: null,
},
Expand All @@ -49,7 +63,6 @@ beforeEach(() => {
(resetCelebrateEditingComment as jest.Mock).mockReturnValue(
resetCelebrateEditingCommentResult,
);
((celebrationItemSelector as unknown) as jest.Mock).mockReturnValue(event);
});

it('renders correctly', () => {
Expand Down
15 changes: 3 additions & 12 deletions src/components/CelebrateCommentBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import {
resetCelebrateEditingComment,
updateCelebrateComment,
} from '../../actions/celebrateComments';
import { celebrationItemSelector } from '../../selectors/celebration';
import { celebrateCommentsCommentSelector } from '../../selectors/celebrateComments';
import { OrganizationsState } from '../../reducers/organizations';
import { CelebrateCommentsState } from '../../reducers/celebrateComments';
import { GetCelebrateFeed_community_celebrationItems_nodes } from '../../containers/CelebrateFeed/__generated__/GetCelebrateFeed';

import styles from './styles';

interface CelebrateCommentBoxProps {
event: object;
event: GetCelebrateFeed_community_celebrationItems_nodes;
editingComment?: object;
onAddComplete?: () => void;
dispatch: ThunkDispatch<{}, {}, AnyAction>;
Expand Down Expand Up @@ -61,24 +60,16 @@ const CelebrateCommentBox = ({
};
const mapStateToProps = (
{
organizations,
celebrateComments,
}: {
organizations: OrganizationsState;
celebrateComments: CelebrateCommentsState;
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
{ event }: any,
{ event }: { event: GetCelebrateFeed_community_celebrationItems_nodes },
) => ({
editingComment: celebrateCommentsCommentSelector(
{ celebrateComments },
{ eventId: event.id, commentId: celebrateComments.editingCommentId },
),
event:
celebrationItemSelector(
{ organizations },
{ eventId: event.id, organizationId: event.organization.id },
) || event,
});

export default connect(mapStateToProps)(CelebrateCommentBox);
89 changes: 57 additions & 32 deletions src/components/CelebrateItem/__tests__/CelebrateItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,27 @@ import { renderWithContext } from '../../../../testUtils';
import { CELEBRATEABLE_TYPES, GLOBAL_COMMUNITY_ID } from '../../../constants';
import { CELEBRATE_DETAIL_SCREEN } from '../../../containers/CelebrateDetailScreen';
import { CELEBRATE_EDIT_STORY_SCREEN } from '../../../containers/Groups/EditStoryScreen';
import { Organization } from '../../../reducers/organizations';
import {
GetCelebrateFeed_community_celebrationItems_nodes,
GetCelebrateFeed_community_celebrationItems_nodes_subjectPerson,
} from '../../../containers/CelebrateFeed/__generated__/GetCelebrateFeed';

import CelebrateItem, { Event, DELETE_STORY, REPORT_STORY } from '..';
import CelebrateItem, { DELETE_STORY, REPORT_STORY } from '..';

jest.mock('../../../actions/analytics');
jest.mock('../../../actions/navigation');

const myId = '123';
const subjectPerson = {
const subjectPerson: GetCelebrateFeed_community_celebrationItems_nodes_subjectPerson = {
__typename: 'Person',
id: '234',
first_name: 'John',
last_name: 'Smith',
full_name: 'John Smith',
firstName: 'John',
lastName: 'Smith',
};
const globalOrg = { id: GLOBAL_COMMUNITY_ID };
const organization = { id: '3' };
const subjectPersonName = `${subjectPerson.firstName} ${subjectPerson.lastName}`;
const globalOrg: Organization = { id: GLOBAL_COMMUNITY_ID };
const organization: Organization = { id: '3' };

const date = '2019-08-21T12:00:00.000';
MockDate.set('2019-08-21 12:00:00', 300);
Expand All @@ -36,19 +42,25 @@ let onClearNotification = jest.fn();
const trackActionResult = { type: 'tracked plain action' };
const navigatePushResult = { type: 'navigate push' };

const event: Event = {
const baseEvent: GetCelebrateFeed_community_celebrationItems_nodes = {
__typename: 'CommunityCelebrationItem',
id: '222',
changed_attribute_value: date,
subject_person: subjectPerson,
subject_person_name: subjectPerson.full_name,
celebrateable_id: '2',
celebrateable_type: CELEBRATEABLE_TYPES.completedStep,
organization,
object_description: 'Celebration',
adjectiveAttributeName: null,
adjectiveAttributeValue: null,
changedAttributeName: 'created_at',
changedAttributeValue: date,
commentsCount: 0,
liked: false,
likesCount: 1,
subjectPerson: subjectPerson,
subjectPersonName,
celebrateableId: '2',
celebrateableType: CELEBRATEABLE_TYPES.completedStep,
objectDescription: 'Celebration',
};
const storyEvent: Event = {
...event,
celebrateable_type: CELEBRATEABLE_TYPES.story,
const storyEvent: GetCelebrateFeed_community_celebrationItems_nodes = {
...baseEvent,
celebrateableType: CELEBRATEABLE_TYPES.story,
};

const initialState = { auth: { person: { id: myId } } };
Expand All @@ -64,9 +76,10 @@ describe('global community', () => {
it('renders correctly', () => {
renderWithContext(
<CelebrateItem
event={event}
event={baseEvent}
onRefresh={onRefresh}
organization={globalOrg}
namePressable={false}
/>,
{ initialState },
).snapshot();
Expand All @@ -75,9 +88,10 @@ describe('global community', () => {
it('renders with clear notification button correctly', () => {
renderWithContext(
<CelebrateItem
event={event}
event={baseEvent}
onRefresh={onRefresh}
organization={globalOrg}
namePressable={false}
onClearNotification={onClearNotification}
/>,
{ initialState },
Expand All @@ -90,6 +104,7 @@ describe('global community', () => {
event={storyEvent}
onRefresh={onRefresh}
organization={globalOrg}
namePressable={false}
/>,
{ initialState },
).snapshot();
Expand All @@ -100,9 +115,10 @@ describe('Community', () => {
it('renders correctly', () => {
renderWithContext(
<CelebrateItem
event={event}
event={baseEvent}
onRefresh={onRefresh}
organization={organization}
namePressable={false}
/>,
{ initialState },
).snapshot();
Expand All @@ -111,10 +127,11 @@ describe('Community', () => {
it('renders with clear notification button correctly', () => {
renderWithContext(
<CelebrateItem
event={event}
event={baseEvent}
onRefresh={onRefresh}
organization={organization}
onClearNotification={onClearNotification}
namePressable={false}
/>,
{ initialState },
).snapshot();
Expand All @@ -126,6 +143,7 @@ describe('Community', () => {
event={storyEvent}
onRefresh={onRefresh}
organization={organization}
namePressable={false}
/>,
{ initialState },
).snapshot();
Expand All @@ -135,7 +153,7 @@ describe('Community', () => {
it('renders with name pressable correctly', () => {
renderWithContext(
<CelebrateItem
event={event}
event={baseEvent}
onRefresh={onRefresh}
organization={organization}
namePressable={true}
Expand All @@ -148,9 +166,10 @@ describe('press card', () => {
it('not pressable in global community', () => {
const { getByTestId } = renderWithContext(
<CelebrateItem
event={event}
event={baseEvent}
onRefresh={onRefresh}
organization={globalOrg}
namePressable={false}
/>,
{ initialState },
);
Expand All @@ -163,26 +182,28 @@ describe('press card', () => {
it('navigates to celebrate detail screen', () => {
const { getByTestId } = renderWithContext(
<CelebrateItem
event={event}
event={baseEvent}
onRefresh={onRefresh}
organization={organization}
namePressable={false}
/>,
{ initialState },
);

fireEvent.press(getByTestId('CelebrateItemPressable'));

expect(navigatePush).toHaveBeenCalledWith(CELEBRATE_DETAIL_SCREEN, {
event,
event: baseEvent,
orgId: organization.id,
});
});
});

describe('long-press card', () => {
describe('story written by me', () => {
const myStoryEvent = {
const myStoryEvent: GetCelebrateFeed_community_celebrationItems_nodes = {
...storyEvent,
subject_person: { ...subjectPerson, id: myId },
subjectPerson: { ...subjectPerson, id: myId },
};

it('navigates to edit story screen', () => {
Expand All @@ -194,6 +215,7 @@ describe('long-press card', () => {
event={myStoryEvent}
onRefresh={onRefresh}
organization={organization}
namePressable={false}
/>,
{ initialState },
);
Expand All @@ -219,6 +241,7 @@ describe('long-press card', () => {
event={myStoryEvent}
onRefresh={onRefresh}
organization={organization}
namePressable={false}
/>,
{ initialState },
);
Expand All @@ -242,7 +265,7 @@ describe('long-press card', () => {
],
);
expect(useMutation).toHaveBeenMutatedWith(DELETE_STORY, {
variables: { input: { id: event.celebrateable_id } },
variables: { input: { id: myStoryEvent.celebrateableId } },
});
expect(onRefresh).toHaveBeenCalled();
});
Expand All @@ -258,6 +281,7 @@ describe('long-press card', () => {
event={storyEvent}
onRefresh={onRefresh}
organization={organization}
namePressable={false}
/>,
{ initialState },
);
Expand All @@ -281,7 +305,7 @@ describe('long-press card', () => {
],
);
expect(useMutation).toHaveBeenMutatedWith(REPORT_STORY, {
variables: { subjectId: event.celebrateable_id },
variables: { subjectId: storyEvent.celebrateableId },
});
});
});
Expand All @@ -291,16 +315,17 @@ describe('clear notification button', () => {
it('calls onClearNotification', () => {
const { getByTestId } = renderWithContext(
<CelebrateItem
event={event}
event={baseEvent}
onRefresh={onRefresh}
organization={organization}
onClearNotification={onClearNotification}
namePressable={false}
/>,
{ initialState },
);

fireEvent.press(getByTestId('ClearNotificationButton'));

expect(onClearNotification).toHaveBeenCalledWith(event);
expect(onClearNotification).toHaveBeenCalledWith(baseEvent);
});
});
Loading