@@ -13,6 +13,51 @@ class InAppPriorityTests: XCTestCase {
13
13
logDelegate: DefaultLogDelegate ( ) )
14
14
}
15
15
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
+
16
61
func testDisplayingCriticalPriorityLevel( ) {
17
62
let condition1 = expectation ( description: " in-app displayer didn't show or succeed " )
18
63
@@ -27,7 +72,7 @@ class InAppPriorityTests: XCTestCase {
27
72
28
73
let mockInAppFetcher = MockInAppFetcher ( )
29
74
let mockInAppDisplayer = MockInAppDisplayer ( )
30
-
75
+
31
76
mockInAppDisplayer. onShow. onSuccess { [ weak mockInAppDisplayer = mockInAppDisplayer] message in
32
77
mockInAppDisplayer? . click ( url: URL ( string: " https://iterable.com " ) !)
33
78
XCTAssertEqual ( message. messageId, messageIdWithCritical)
@@ -84,7 +129,7 @@ class InAppPriorityTests: XCTestCase {
84
129
85
130
condition1. fulfill ( )
86
131
}
87
-
132
+
88
133
// Test will fail without assigning to internalAPI because InAppManager will be deallocated
89
134
let internalAPI = IterableAPIInternal . initializeForTesting ( inAppFetcher: mockInAppFetcher,
90
135
inAppDisplayer: mockInAppDisplayer)
0 commit comments