Skip to content

Commit 7731b39

Browse files
chore(js-ts): Convert content-sharing hooks to TypeScript
Co-Authored-By: tjuanitas@box.com <tjuanitas@box.com>
1 parent dc5d352 commit 7731b39

File tree

7 files changed

+317
-211
lines changed

7 files changed

+317
-211
lines changed

src/elements/content-sharing/__tests__/useCollaborators.test.js renamed to src/elements/content-sharing/__tests__/useCollaborators.test.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
const handleSuccess = jest.fn().mockReturnValue(MOCK_COLLABS_CONVERTED_RESPONSE);
1414
const handleError = jest.fn();
1515

16-
function FakeComponent({ api, itemType }: { api: API, itemType: string }) {
16+
function FakeComponent({ api, itemType }: { api: API; itemType: string }) {
1717
const [collaboratorsList, setCollaboratorsList] = React.useState(null);
1818

1919
const collabsResponse = useCollaborators(api, MOCK_ITEM_ID, itemType, { handleSuccess, handleError });
@@ -53,11 +53,7 @@ describe('elements/content-sharing/hooks/useCollaborators', () => {
5353
fakeComponent = mount(<FakeComponent api={mockAPI} itemType={itemType} />);
5454
});
5555
fakeComponent.update();
56-
expect(getCollaborations).toHaveBeenCalledWith(
57-
MOCK_ITEM_ID,
58-
expect.anything(Function),
59-
expect.anything(Function),
60-
);
56+
expect(getCollaborations).toHaveBeenCalledWith(MOCK_ITEM_ID, expect.anything(), expect.anything());
6157
expect(handleSuccess).toHaveBeenCalled();
6258
expect(fakeComponent.find('div').text()).toBe(STRINGIFIED_MOCK_RESPONSE);
6359
});
@@ -85,11 +81,7 @@ describe('elements/content-sharing/hooks/useCollaborators', () => {
8581
fakeComponent = mount(<FakeComponent api={mockAPI} itemType={itemType} />);
8682
});
8783
fakeComponent.update();
88-
expect(getCollaborations).toHaveBeenCalledWith(
89-
MOCK_ITEM_ID,
90-
expect.anything(Function),
91-
expect.anything(Function),
92-
);
84+
expect(getCollaborations).toHaveBeenCalledWith(MOCK_ITEM_ID, expect.anything(), expect.anything());
9385
expect(handleError).toHaveBeenCalled();
9486
expect(fakeComponent.find('div').text()).toBe(JSON.stringify({ entries: [], next_marker: null }));
9587
});

src/elements/content-sharing/__tests__/useContactsByEmail.test.js renamed to src/elements/content-sharing/__tests__/useContactsByEmail.test.tsx

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// @flow
2-
31
import React, { act } from 'react';
42
import { mount } from 'enzyme';
53
import API from '../../../api';
4+
import { GetContactsByEmailFnType } from '../types';
65
import useContactsByEmail from '../hooks/useContactsByEmail';
76
import {
87
MOCK_CONTACTS_API_RESPONSE,
@@ -14,12 +13,12 @@ const handleSuccess = jest.fn();
1413
const handleError = jest.fn();
1514
const transformUsersSpy = jest.fn().mockReturnValue(MOCK_CONTACTS_BY_EMAIL_CONVERTED_RESPONSE);
1615

17-
const createAPIMock = markerBasedUsersAPI => ({
16+
const createAPIMock = (markerBasedUsersAPI: Record<string, unknown>): { getMarkerBasedUsersAPI: jest.Mock } => ({
1817
getMarkerBasedUsersAPI: jest.fn().mockReturnValue(markerBasedUsersAPI),
1918
});
2019

21-
function FakeComponent({ api, transformUsers }: { api: API, transformUsers: Function }) {
22-
const [getContactsByEmail, setGetContactsByEmail] = React.useState(null);
20+
function FakeComponent({ api, transformUsers }: { api: API; transformUsers?: Function }) {
21+
const [getContactsByEmail, setGetContactsByEmail] = React.useState<GetContactsByEmailFnType | null>(null);
2322

2423
const updatedGetContactsByEmailFn = useContactsByEmail(api, MOCK_ITEM_ID, {
2524
handleSuccess,
@@ -63,12 +62,9 @@ describe('elements/content-sharing/hooks/useContactsByEmail', () => {
6362

6463
const contacts = fakeComponent.find('button').invoke('onClick')({ emails: [MOCK_EMAIL] });
6564

66-
expect(getUsersInEnterprise).toHaveBeenCalledWith(
67-
MOCK_ITEM_ID,
68-
expect.anything(Function),
69-
expect.anything(Function),
70-
{ filter_term: MOCK_EMAIL },
71-
);
65+
expect(getUsersInEnterprise).toHaveBeenCalledWith(MOCK_ITEM_ID, expect.anything(), expect.anything(), {
66+
filter_term: MOCK_EMAIL,
67+
});
7268
expect(handleSuccess).toHaveBeenCalledWith(MOCK_CONTACTS_API_RESPONSE);
7369
expect(transformUsersSpy).toHaveBeenCalledWith(MOCK_CONTACTS_API_RESPONSE);
7470
return expect(contacts).resolves.toEqual(MOCK_CONTACTS_BY_EMAIL_CONVERTED_RESPONSE);
@@ -83,12 +79,9 @@ describe('elements/content-sharing/hooks/useContactsByEmail', () => {
8379

8480
const contacts = fakeComponent.find('button').invoke('onClick')({ emails: [MOCK_EMAIL] });
8581

86-
expect(getUsersInEnterprise).toHaveBeenCalledWith(
87-
MOCK_ITEM_ID,
88-
expect.anything(Function),
89-
expect.anything(Function),
90-
{ filter_term: MOCK_EMAIL },
91-
);
82+
expect(getUsersInEnterprise).toHaveBeenCalledWith(MOCK_ITEM_ID, expect.anything(), expect.anything(), {
83+
filter_term: MOCK_EMAIL,
84+
});
9285
expect(handleSuccess).toHaveBeenCalledWith(MOCK_CONTACTS_API_RESPONSE);
9386
expect(transformUsersSpy).not.toHaveBeenCalled();
9487
expect(contacts).resolves.toEqual(MOCK_CONTACTS_API_RESPONSE.entries);
@@ -154,12 +147,9 @@ describe('elements/content-sharing/hooks/useContactsByEmail', () => {
154147

155148
const contacts = fakeComponent.find('button').invoke('onClick')({ emails: [MOCK_EMAIL] });
156149

157-
expect(getUsersInEnterprise).toHaveBeenCalledWith(
158-
MOCK_ITEM_ID,
159-
expect.anything(Function),
160-
expect.anything(Function),
161-
{ filter_term: MOCK_EMAIL },
162-
);
150+
expect(getUsersInEnterprise).toHaveBeenCalledWith(MOCK_ITEM_ID, expect.anything(), expect.anything(), {
151+
filter_term: MOCK_EMAIL,
152+
});
163153
expect(handleError).toHaveBeenCalled();
164154
expect(contacts).resolves.toBeFalsy();
165155
});

0 commit comments

Comments
 (0)