Skip to content

Commit f3d711e

Browse files
authored
Merge branch 'master' into new-arch/master
2 parents dc7ff75 + 8e8374d commit f3d711e

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

.github/workflows/unit-test.yml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,23 @@ jobs:
2929
with:
3030
hide-comment: false
3131
coverage-summary-path: ./coverage/coverage-summary.json
32-
test-code-climate:
33-
name: Upload unit test results to Code Climate
32+
33+
run-tests-and-publish-coverage:
34+
name: Upload unit test results to qlty
3435
runs-on: ubuntu-latest
35-
36+
3637
steps:
3738
- uses: actions/checkout@v3
38-
39+
3940
- name: Setup
4041
uses: ./.github/actions/setup
41-
42+
4243
- name: Run tests
4344
run: |
4445
yarn test --coverage --coverageReporters lcov
45-
46-
- name: Upload coverage to Code Climate
47-
uses: paambaati/[email protected]
48-
env:
49-
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
46+
47+
- name: Upload coverage to qlty
48+
uses: qltysh/qlty-action/coverage@v1
5049
with:
51-
coverageCommand: yarn test --coverage --coverageReporters lcov
52-
coverageLocations: |
53-
${{github.workspace}}/coverage/lcov.info:lcov
50+
token: ${{ secrets.QLTY_COVERAGE_TOKEN }}
51+
files: coverage/lcov.info

src/__tests__/IterableInApp.test.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { NativeEventEmitter } from 'react-native';
22

33
import { IterableLogger } from '../core';
4-
import { IterableInAppManager } from '../inApp';
54

65
import { MockRNIterableAPI } from '../__mocks__/MockRNIterableAPI';
76

@@ -202,10 +201,8 @@ describe('Iterable In App', () => {
202201

203202
// WHEN the simulated local queue is set to the in-app messages
204203
MockRNIterableAPI.setMessages(messages);
205-
const inAppManager = new IterableInAppManager();
206-
207-
// THEN Iterable,inAppManager.getMessages returns the list of in-app messages
208-
return await inAppManager.getMessages().then((messagesObtained) => {
204+
// THEN Iterable.inAppManager.getMessages returns the list of in-app messages
205+
return await Iterable.inAppManager?.getMessages().then((messagesObtained) => {
209206
expect(messagesObtained).toEqual(messages);
210207
});
211208
});
@@ -224,9 +221,8 @@ describe('Iterable In App', () => {
224221

225222
// WHEN the simulated clicked url is set to the clicked url
226223
MockRNIterableAPI.setClickedUrl(clickedUrl);
227-
const inAppManager = new IterableInAppManager();
228224
// THEN Iterable,inAppManager.showMessage returns the simulated clicked url
229-
return await inAppManager.showMessage(message, consume).then((url) => {
225+
return await Iterable.inAppManager?.showMessage(message, consume).then((url) => {
230226
expect(url).toEqual(clickedUrl);
231227
});
232228
});
@@ -242,10 +238,9 @@ describe('Iterable In App', () => {
242238
const location: IterableInAppLocation = IterableInAppLocation.inApp;
243239
const source: IterableInAppDeleteSource =
244240
IterableInAppDeleteSource.deleteButton;
245-
const inAppManager = new IterableInAppManager();
246241

247242
// WHEN Iterable.inAppManager.removeMessage is called
248-
inAppManager.removeMessage(message, location, source);
243+
Iterable.inAppManager?.removeMessage(message, location, source);
249244

250245
// THEN corresponding method is called on MockIterableAPI with appropriate parameters
251246
expect(MockRNIterableAPI.removeMessage).toBeCalledWith(
@@ -266,8 +261,7 @@ describe('Iterable In App', () => {
266261
const read: boolean = true;
267262

268263
// WHEN Iterable.inAppManager.setReadForMessage is called
269-
const inAppManager = new IterableInAppManager();
270-
inAppManager.setReadForMessage(message, read);
264+
Iterable.inAppManager?.setReadForMessage(message, read);
271265

272266
// THEN corresponding method is called on MockRNIterableAPI with appropriate parameters
273267
expect(MockRNIterableAPI.setReadForMessage).toBeCalledWith(
@@ -281,8 +275,7 @@ describe('Iterable In App', () => {
281275
const paused: boolean = true;
282276

283277
// WHEN Iterable.inAppManager.setAutoDisplayPaused is called
284-
const inAppManager = new IterableInAppManager();
285-
inAppManager.setAutoDisplayPaused(paused);
278+
Iterable.inAppManager?.setAutoDisplayPaused(paused);
286279

287280
// THEN corresponding method is called on MockRNIterableAPI with appropriate parameters
288281
expect(MockRNIterableAPI.setAutoDisplayPaused).toBeCalledWith(paused);

src/core/classes/Iterable.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import { IterableInAppDeleteSource } from '../../inApp/enums/IterableInAppDelete
1515
import { IterableInAppLocation } from '../../inApp/enums/IterableInAppLocation';
1616
import { IterableAuthResponseResult, IterableEventName } from '../enums';
1717

18+
// Add this type-only import to avoid circular dependency
19+
import type { IterableInAppManager } from '../../inApp/classes/IterableInAppManager';
20+
1821
import { IterableAction } from './IterableAction';
1922
import { IterableActionContext } from './IterableActionContext';
2023
import { IterableAttributionInfo } from './IterableAttributionInfo';
@@ -55,6 +58,36 @@ export class Iterable {
5558
*/
5659
static savedConfig: IterableConfig = new IterableConfig();
5760

61+
/**
62+
* In-app message manager for the current user.
63+
*
64+
* This property provides access to in-app message functionality including
65+
* retrieving messages, displaying messages, removing messages, and more.
66+
*
67+
* @example
68+
* ```typescript
69+
* // Get all in-app messages
70+
* Iterable.inAppManager.getMessages().then(messages => {
71+
* console.log('Messages:', messages);
72+
* });
73+
*
74+
* // Show a specific message
75+
* Iterable.inAppManager.showMessage(message, true);
76+
* ```
77+
*/
78+
static get inAppManager() {
79+
// Lazy initialization to avoid circular dependency
80+
if (!this._inAppManager) {
81+
// Import here to avoid circular dependency at module level
82+
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-require-imports
83+
const { IterableInAppManager } = require('../../inApp/classes/IterableInAppManager');
84+
this._inAppManager = new IterableInAppManager();
85+
}
86+
return this._inAppManager;
87+
}
88+
89+
private static _inAppManager: IterableInAppManager | undefined;
90+
5891
/**
5992
* Initializes the Iterable React Native SDK in your app's Javascript or Typescript code.
6093
*

0 commit comments

Comments
 (0)