Skip to content

Commit b36a277

Browse files
author
piotr pietruszewski
committed
test: ui test for fetch help center methods
- android error handling fixes
1 parent f318160 commit b36a277

File tree

6 files changed

+87
-24
lines changed

6 files changed

+87
-24
lines changed

android/src/main/java/com/intercom/reactnative/IntercomModule.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public void onFailure() {
319319
promise.reject(IntercomErrorCodes.FETCH_HELP_CENTER_COLLECTIONS, "fetchHelpCenterCollections failure");
320320
}
321321
};
322-
322+
Log.d(NAME, "fetchHelpCenterCollections");
323323
Intercom.client().fetchHelpCenterCollections(collectionRequestCallback);
324324

325325
} catch (Exception err) {
@@ -332,27 +332,30 @@ public void onFailure() {
332332
@ReactMethod
333333
public void fetchHelpCenterCollection(String collectionId, Promise promise) {
334334
try {
335-
336-
CollectionContentRequestCallback collectionContentCallback = new CollectionContentRequestCallback() {
337-
@Override
338-
public void onComplete(@NotNull HelpCenterCollectionContent helpCenterCollectionContent) {
339-
promise.resolve(IntercomHelpCenterHelpers.parseHelpCenterCollectionsContentToReadableMap(helpCenterCollectionContent));
340-
}
341-
342-
@Override
343-
public void onError(int i) {
344-
Log.e(NAME, "fetchHelpCenterCollection error");
345-
promise.reject(String.valueOf(i), "fetchHelpCenterCollection error");
346-
}
347-
348-
@Override
349-
public void onFailure() {
350-
Log.e(NAME, "fetchHelpCenterCollection failure");
351-
promise.reject(IntercomErrorCodes.FETCH_HELP_CENTER_COLLECTION, "fetchHelpCenterCollection failure");
352-
}
353-
};
354-
355-
Intercom.client().fetchHelpCenterCollection(collectionId, collectionContentCallback);
335+
if (collectionId.equals("") ) {
336+
promise.reject(IntercomErrorCodes.FETCH_HELP_CENTER_COLLECTION, "collectionID can\'t be empty");
337+
} else {
338+
CollectionContentRequestCallback collectionContentCallback = new CollectionContentRequestCallback() {
339+
@Override
340+
public void onComplete(@NotNull HelpCenterCollectionContent helpCenterCollectionContent) {
341+
promise.resolve(IntercomHelpCenterHelpers.parseHelpCenterCollectionsContentToReadableMap(helpCenterCollectionContent));
342+
}
343+
344+
@Override
345+
public void onError(int i) {
346+
Log.e(NAME, "fetchHelpCenterCollection error");
347+
promise.reject(String.valueOf(i), "fetchHelpCenterCollection error");
348+
}
349+
350+
@Override
351+
public void onFailure() {
352+
Log.e(NAME, "fetchHelpCenterCollection failure");
353+
promise.reject(IntercomErrorCodes.FETCH_HELP_CENTER_COLLECTION, "fetchHelpCenterCollection failure");
354+
}
355+
};
356+
Log.d(NAME, "fetchHelpCenterCollection");
357+
Intercom.client().fetchHelpCenterCollection(collectionId, collectionContentCallback);
358+
}
356359

357360
} catch (Exception err) {
358361
Log.e(NAME, "fetchHelpCenterCollection error:");
@@ -383,7 +386,7 @@ public void onFailure() {
383386
promise.reject(IntercomErrorCodes.SEARCH_HELP_CENTER, "searchHelpCenter failure");
384387
}
385388
};
386-
389+
Log.d(NAME, "searchHelpCenter");
387390
Intercom.client().searchHelpCenter(searchTerm, collectionContentCallback);
388391

389392
} catch (Exception err) {

example/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ CAROUSEL_ID=$CAROUSEL_ID
66
EVENT_NAME=$EVENT_NAME
77
ARTICLE_ID=$ARTICLE_ID
88
USER_NAME=$USER_NAME
9+
SECTION_ID=$SECTION_ID
10+
SEARCH_TERM=$SEARCH_TERM

example/e2e/tests/mainIntercom.e2e.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ describe('Intercom E2E', () => {
4545
await driver.closeHelpCenterOverlay();
4646
});
4747

48+
it('Should fetch help center collections', async () => {
49+
await driver.scrollToElementByAccessibilityLabel(
50+
'fetch-help-center-collections'
51+
);
52+
await (await $('~fetch-help-center-collections')).click();
53+
});
54+
55+
it('Should fetch help center collection', async () => {
56+
await driver.scrollToElementByAccessibilityLabel(
57+
'fetch-help-center-collections'
58+
);
59+
await (await $('~fetch-help-center-collection')).click();
60+
});
61+
62+
it('Should fetch filtered hel center collections', async () => {
63+
await driver.scrollToElementByAccessibilityLabel('search-help-center');
64+
await (await $('~search-help-center')).click();
65+
});
66+
4867
it('Should display carousel', async () => {
4968
await driver.scrollToElementByAccessibilityLabel('display-carousel');
5069
await (await $('~display-carousel')).click();

example/scripts/generateEnv.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ echo CAROUSEL_ID=$CAROUSEL_ID >>.env
88
echo EVENT_NAME=$EVENT_NAME >>.env
99
echo ARTICLE_ID=$ARTICLE_ID >>.env
1010
echo USER_NAME=$USER_NAME >>.env
11+
echo SEARCH_TERM=$SEARCH_TERM >>.env
12+
echo SECTION_ID=$SECTION_ID >>.env

example/src/App.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const CAROUSEL_ID = Config.CAROUSEL_ID;
2323
const EVENT_NAME = Config.EVENT_NAME;
2424
const ARTICLE_ID = Config.ARTICLE_ID;
2525
const USER_NAME = Config.USER_NAME;
26+
const COLLECTION_ID = Config.COLLECTION_ID;
27+
const SEARCH_TERM = Config.SEARCH_TERM;
2628
const TOKEN = Platform.select({
2729
ios: 'RN-IOS-TOKEN',
2830
default: 'RN-ANDROID-TOKEN',
@@ -37,6 +39,10 @@ export default function App() {
3739
const [launcherVisibility, setLauncherVisibility] = useState<boolean>(false);
3840
const [user, setUser] = useState<Registration>({ email: '' });
3941

42+
const showErrorAlert = (e: Error) => {
43+
Alert.alert('ERROR', JSON.stringify(e));
44+
};
45+
4046
useEffect(() => {
4147
/**
4248
* Handle PushNotification
@@ -203,6 +209,37 @@ export default function App() {
203209
console.log(items);
204210
})
205211
.catch((e) => {
212+
showErrorAlert(e);
213+
console.error(e);
214+
});
215+
}}
216+
/>
217+
<Button
218+
accessibilityLabel="fetch-help-center-collection"
219+
disabled={!loggedUser}
220+
title="Fetch Help Center Collection"
221+
onPress={() => {
222+
Intercom.fetchHelpCenterCollection(COLLECTION_ID)
223+
.then((item) => {
224+
console.log(item);
225+
})
226+
.catch((e) => {
227+
showErrorAlert(e);
228+
console.error(e);
229+
});
230+
}}
231+
/>
232+
<Button
233+
accessibilityLabel="search-help-center"
234+
disabled={!loggedUser}
235+
title="Search Help Center"
236+
onPress={() => {
237+
Intercom.searchHelpCenter(SEARCH_TERM)
238+
.then((item) => {
239+
console.log(item);
240+
})
241+
.catch((e) => {
242+
showErrorAlert(e);
206243
console.error(e);
207244
});
208245
}}

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export type IntercomType = {
133133
const Intercom = {
134134
searchHelpCenter: (term) => IntercomModule.searchHelpCenter(term),
135135
fetchHelpCenterCollections: () => IntercomModule.fetchHelpCenterCollections(),
136-
fetchHelpCenterCollection: (id) =>
136+
fetchHelpCenterCollection: (id = '') =>
137137
IntercomModule.fetchHelpCenterCollection(id),
138138
displayArticle: (articleId: string) =>
139139
IntercomModule.displayArticle(articleId),

0 commit comments

Comments
 (0)