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 31 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
106 changes: 53 additions & 53 deletions src/actions/__tests__/celebrateComments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import configureStore from 'redux-mock-store';
/* eslint-disable @typescript-eslint/no-explicit-any */

import configureStore, { MockStore } from 'redux-mock-store';
import thunk from 'redux-thunk';

import {
Expand All @@ -20,43 +22,51 @@ import { REQUESTS } from '../../api/routes';
import { celebrateCommentsSelector } from '../../selectors/celebrateComments';
import { trackActionWithoutData } from '../analytics';
import { ACTIONS } from '../../constants';
import { mockFragment } from '../../../testUtils/apolloMockClient';
import { CELEBRATE_ITEM_FRAGMENT } from '../../components/CelebrateItem/queries';
import { GetCelebrateFeed_community_celebrationItems_nodes as CelebrateItem } from '../../containers/CelebrateFeed/__generated__/GetCelebrateFeed';
import { Person } from '../../reducers/people';

jest.mock('../api');
jest.mock('../../selectors/celebrateComments');
jest.mock('../analytics');

const event = mockFragment<CelebrateItem>(CELEBRATE_ITEM_FRAGMENT);

const orgId = '645654';
const event = { id: '80890', organization: { id: orgId } };
const comment = { pagination: { page: 2, hasNextPage: true } };
const callApiResponse = { result: 'hello world' };
const celebrateComments = { someProp: 'asdfasdfasdf' };
const comment = {
pagination: { page: 2, hasNextPage: true },
};
const baseQuery = { orgId, eventId: event.id };
const me = { id: 'myId' };
const me: Person = { id: 'myId' };
const include = 'organization_celebration_item,person';

const auth = { person: me };
const celebrateComments = { comments: [comment] };

const callApiResponse = { type: 'call API', result: 'hello world' };
const trackActionResult = { type: 'tracked action' };

const mockStore = configureStore([thunk]);
// @ts-ignore
let store;

// @ts-ignore
callApi.mockReturnValue(() => callApiResponse);
// @ts-ignore
celebrateCommentsSelector.mockReturnValue(comment);
// @ts-ignore
trackActionWithoutData.mockReturnValue(trackActionResult);
let store: MockStore;

beforeEach(() => {
store = mockStore({ auth: { person: me }, celebrateComments });
store = mockStore({ auth, celebrateComments });
(callApi as jest.Mock).mockReturnValue(callApiResponse);
((celebrateCommentsSelector as unknown) as jest.Mock).mockReturnValue(
comment,
);
(trackActionWithoutData as jest.Mock).mockReturnValue(trackActionResult);
});

describe('getCelebrateCommentsNextPage', () => {
// @ts-ignore
let response;
let response: any;

describe('getCelebrateCommentsNextPage', () => {
beforeEach(
// @ts-ignore
() => (response = store.dispatch(getCelebrateCommentsNextPage(event))),
() =>
(response = store.dispatch<any>(
getCelebrateCommentsNextPage(event.id, orgId),
)),
);

it('should call selector', () => {
Expand All @@ -78,17 +88,18 @@ describe('getCelebrateCommentsNextPage', () => {
});

it('should return api response', () => {
// @ts-ignore
expect(response).toEqual(callApiResponse);
expect(store.getActions()).toEqual([callApiResponse]);
});
});

describe('reloadCelebrateComments', () => {
// @ts-ignore
let response;

// @ts-ignore
beforeEach(() => (response = store.dispatch(reloadCelebrateComments(event))));
beforeEach(
() =>
(response = store.dispatch<any>(
reloadCelebrateComments(event.id, orgId),
)),
);

it('should callApi with no page', () => {
expect(callApi).toHaveBeenCalledWith(REQUESTS.GET_CELEBRATE_COMMENTS, {
Expand All @@ -98,20 +109,19 @@ describe('reloadCelebrateComments', () => {
});

it('should return api response', () => {
// @ts-ignore
expect(response).toEqual(callApiResponse);
expect(store.getActions()).toEqual([callApiResponse]);
});
});

describe('createCelebrateComment', () => {
const content = 'this is a comment';
// @ts-ignore
let response;

beforeEach(
async () =>
// @ts-ignore
(response = await store.dispatch(createCelebrateComment(event, content))),
(response = await store.dispatch<any>(
createCelebrateComment(event.id, orgId, content),
)),
);

it('should callApi with no page', () => {
Expand All @@ -123,29 +133,24 @@ describe('createCelebrateComment', () => {
});

it('should return api response', () => {
// @ts-ignore
expect(response).toEqual(callApiResponse);
});

it('should track action', () => {
expect(trackActionWithoutData).toHaveBeenCalledWith(
ACTIONS.CELEBRATE_COMMENT_ADDED,
);
// @ts-ignore
expect(store.getActions()).toEqual([trackActionResult]);
expect(store.getActions()).toEqual([callApiResponse, trackActionResult]);
});
});

describe('deleteCelebrateComment', () => {
const item = { id: 'comment1' };
// @ts-ignore
let response;

beforeEach(
async () =>
// @ts-ignore
(response = await store.dispatch(
deleteCelebrateComment(event.organization.id, event, item),
(response = await store.dispatch<any>(
deleteCelebrateComment(orgId, event.id, item.id),
)),
);

Expand All @@ -157,29 +162,26 @@ describe('deleteCelebrateComment', () => {
});

it('should return api response', () => {
// @ts-ignore
expect(response).toEqual(callApiResponse);
});

it('should track action', () => {
expect(trackActionWithoutData).toHaveBeenCalledWith(
ACTIONS.CELEBRATE_COMMENT_DELETED,
);
// @ts-ignore
expect(store.getActions()).toEqual([trackActionResult]);
expect(store.getActions()).toEqual([callApiResponse, trackActionResult]);
});
});

describe('updateCelebrateComment', () => {
const item = { id: 'comment1', organization_celebration_item: event };
const text = 'text';
// @ts-ignore
let response;

beforeEach(
async () =>
// @ts-ignore
(response = await store.dispatch(updateCelebrateComment(item, text))),
(response = await store.dispatch<any>(
updateCelebrateComment(event.id, orgId, item.id, text),
)),
);

it('should callApi', () => {
Expand All @@ -198,16 +200,14 @@ describe('updateCelebrateComment', () => {
});

it('should return api response', () => {
// @ts-ignore
expect(response).toEqual(callApiResponse);
});

it('should track action', () => {
expect(trackActionWithoutData).toHaveBeenCalledWith(
ACTIONS.CELEBRATE_COMMENT_EDITED,
);
// @ts-ignore
expect(store.getActions()).toEqual([trackActionResult]);
expect(store.getActions()).toEqual([callApiResponse, trackActionResult]);
});
});

Expand All @@ -219,9 +219,9 @@ it('resetCelebrateEditingComment', () => {

it('setCelebrateEditingComment', () => {
const comment = { id: 'test' };
// @ts-ignore
store.dispatch(setCelebrateEditingComment(comment.id));
// @ts-ignore

store.dispatch<any>(setCelebrateEditingComment(comment.id));

expect(store.getActions()).toEqual([
{
type: RESET_CELEBRATE_EDITING_COMMENT,
Expand Down
126 changes: 3 additions & 123 deletions src/actions/__tests__/celebration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,9 @@
import configureStore, { MockStore } from 'redux-mock-store';
import thunk from 'redux-thunk';

import {
getGroupCelebrateFeed,
toggleLike,
getGroupCelebrateFeedUnread,
reloadGroupCelebrateFeed,
} from '../celebration';
import { toggleLike } from '../celebration';
import callApi from '../api';
import { REQUESTS } from '../../api/routes';
import {
DEFAULT_PAGE_LIMIT,
RESET_CELEBRATION_PAGINATION,
} from '../../constants';
import { GET_CELEBRATE_INCLUDE } from '../../utils/actions';

jest.mock('../api');

Expand All @@ -28,118 +18,8 @@ let store: MockStore;

const currentPage = 0;

describe('getGroupCelebrateFeed', () => {
beforeEach(() => {
store = createStore();
(callApi as jest.Mock).mockReturnValue(apiResult);
});

it('gets a page of celebrate feed', () => {
store = createStore({
organizations: {
all: [
{
id: orgId,
celebratePagination: {
hasNextPage: true,
page: currentPage,
},
},
],
},
});

store.dispatch<any>(getGroupCelebrateFeed(orgId));

expect(callApi).toHaveBeenCalledWith(REQUESTS.GET_GROUP_CELEBRATE_FEED, {
page: {
limit: DEFAULT_PAGE_LIMIT,
offset: DEFAULT_PAGE_LIMIT * currentPage,
},
orgId,
include:
'subject_person.organizational_permissions,subject_person.contact_assignments',
});
expect(store.getActions()).toEqual([apiResult]);
});

it('does not get celebrate items if there is no next page', () => {
store = createStore({
organizations: {
all: [
{
id: orgId,
celebratePagination: {
hasNextPage: false,
page: currentPage,
},
},
],
},
});

store.dispatch<any>(getGroupCelebrateFeed(orgId));

expect(callApi).not.toHaveBeenCalled();
expect(store.getActions()).toEqual([]);
});
});

describe('reloadGroupCelebrateFeed', () => {
beforeEach(() => {
store = createStore({
organizations: {
all: [
{
id: orgId,
celebratePagination: {
hasNextPage: true,
page: currentPage,
},
},
],
},
});
(callApi as jest.Mock).mockReturnValue(apiResult);
});

it('reloads feed', () => {
store.dispatch<any>(reloadGroupCelebrateFeed(orgId));

expect(callApi).toHaveBeenCalledWith(REQUESTS.GET_GROUP_CELEBRATE_FEED, {
page: {
limit: DEFAULT_PAGE_LIMIT,
offset: DEFAULT_PAGE_LIMIT * currentPage,
},
orgId,
include:
'subject_person.organizational_permissions,subject_person.contact_assignments',
});
expect(store.getActions()).toEqual([
{ type: RESET_CELEBRATION_PAGINATION, orgId },
apiResult,
]);
});
});

describe('getGroupCelebrateFeedUnread', () => {
beforeEach(() => {
store = createStore({ organizations: { all: [{ id: orgId }] } });
});

it('calls feed of unread items', () => {
store.dispatch<any>(getGroupCelebrateFeedUnread(orgId));

expect(callApi).toHaveBeenCalledWith(
REQUESTS.GET_GROUP_CELEBRATE_FEED_UNREAD,
{
orgId,
filters: { has_unread_comments: true },
include: GET_CELEBRATE_INCLUDE,
},
);
expect(store.getActions()).toEqual([apiResult]);
});
beforeEach(() => {
(callApi as jest.Mock).mockReturnValue(apiResult);
});

describe('toggleLike', () => {
Expand Down
Loading