Skip to content

Commit eac7ba2

Browse files
authored
Merge pull request #458 from Iterable/MOB-2568-in-app-priority-test
[MOB-2568] add in-app priority test for sorting on a list
2 parents 3bbc6f5 + 9c542ff commit eac7ba2

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

tests/swift-sdk-swift-tests/in-app-tests/InAppPriorityTests.swift

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,51 @@ class InAppPriorityTests: XCTestCase {
1313
logDelegate: DefaultLogDelegate())
1414
}
1515

16+
func testDisplayingPriorityLevelsInOrder() {
17+
let condition1 = expectation(description: "not able to match message priority levels")
18+
condition1.expectedFulfillmentCount = 4
19+
20+
let messages = [
21+
getMessageWithPriority("1", Const.PriorityLevel.low),
22+
getMessageWithPriority("2", Const.PriorityLevel.high),
23+
getMessageWithPriority("3", Const.PriorityLevel.medium),
24+
getMessageWithPriority("4", Const.PriorityLevel.critical)
25+
]
26+
27+
var expectedDisplayOrder = messages.sorted { (message1, message2) -> Bool in
28+
message1.priorityLevel < message2.priorityLevel
29+
}
30+
31+
let mockInAppFetcher = MockInAppFetcher()
32+
let mockInAppDisplayer = MockInAppDisplayer()
33+
34+
mockInAppDisplayer.onShow.onSuccess { [weak mockInAppDisplayer = mockInAppDisplayer] message in
35+
mockInAppDisplayer?.click(url: URL(string: "https://iterable.com")!)
36+
37+
guard let nextExpectedMessage = expectedDisplayOrder.first else {
38+
XCTFail("could not get the next expected message")
39+
return
40+
}
41+
42+
if message.messageId == nextExpectedMessage.messageId {
43+
expectedDisplayOrder.removeFirst()
44+
condition1.fulfill()
45+
}
46+
}
47+
48+
let config = IterableConfig()
49+
config.inAppDisplayInterval = 1.0
50+
51+
let internalAPI = IterableAPIInternal.initializeForTesting(config: config,
52+
inAppFetcher: mockInAppFetcher,
53+
inAppDisplayer: mockInAppDisplayer)
54+
55+
mockInAppFetcher.mockMessagesAvailableFromServer(internalApi: internalAPI,
56+
messages: messages)
57+
58+
wait(for: [condition1], timeout: testExpectationTimeout)
59+
}
60+
1661
func testDisplayingCriticalPriorityLevel() {
1762
let condition1 = expectation(description: "in-app displayer didn't show or succeed")
1863

@@ -27,7 +72,7 @@ class InAppPriorityTests: XCTestCase {
2772

2873
let mockInAppFetcher = MockInAppFetcher()
2974
let mockInAppDisplayer = MockInAppDisplayer()
30-
75+
3176
mockInAppDisplayer.onShow.onSuccess { [weak mockInAppDisplayer = mockInAppDisplayer] message in
3277
mockInAppDisplayer?.click(url: URL(string: "https://iterable.com")!)
3378
XCTAssertEqual(message.messageId, messageIdWithCritical)
@@ -84,7 +129,7 @@ class InAppPriorityTests: XCTestCase {
84129

85130
condition1.fulfill()
86131
}
87-
132+
88133
// Test will fail without assigning to internalAPI because InAppManager will be deallocated
89134
let internalAPI = InternalIterableAPI.initializeForTesting(inAppFetcher: mockInAppFetcher,
90135
inAppDisplayer: mockInAppDisplayer)

0 commit comments

Comments
 (0)