Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: dismiss message when close button pressed #734

Merged
merged 24 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f0c5d97
chore: get WebView for inline message and add to Inline View to display
levibostian May 20, 2024
1c38f27
chore: add AutoLayout constraints to make inline messages visible in …
levibostian May 20, 2024
f96607f
chore: display inline messages fetched after View constructed
levibostian May 20, 2024
434d587
chore: when in-app web content rendered, animate visibility of inline…
levibostian May 22, 2024
b6a03f9
animate height to 0
levibostian Jun 4, 2024
b0231ea
when fetch is done and message expired, dismiss it.
levibostian Jun 4, 2024
66e9b4d
write test inline view that checks if a fetch is done and message exp…
levibostian Jun 4, 2024
2951c97
Apply suggestions from code review
levibostian Jun 4, 2024
966e3f9
improve onDoneRenderingInAppMessage in tests by better explaining how…
levibostian Jun 4, 2024
7b9008b
Merge remote-tracking branch 'origin/levi/inline-dismiss-when-expire'…
levibostian Jun 4, 2024
d89934a
revert failed test. I'll fix it in previous commit where it was intro…
levibostian Jun 4, 2024
22b4183
Merge branch 'feature-inline-inapp' into levi/display-inline-uiview-a…
levibostian Jun 4, 2024
b1da3f3
dismiss message with animation when close button pressed
levibostian Jun 6, 2024
a8b2f1f
wrote tests
levibostian Jun 6, 2024
1f96d5f
added test that message doesnt get replaced
levibostian Jun 7, 2024
8b62311
fix failed test.
levibostian Jun 11, 2024
c89822c
fix the message comparison to use the queue id and not the template id.
levibostian Jun 11, 2024
7cede1d
Merge branch 'levi/display-inline-uiview-afterfetch' into levi/inline…
levibostian Jun 11, 2024
7363f0c
Merge branch 'levi/inline-animate-open' into levi/inline-dismiss-when…
levibostian Jun 11, 2024
a10d4b7
Merge branch 'levi/inline-dismiss-when-expire' into levi/inline-close…
levibostian Jun 11, 2024
4aa0f25
Merge branch 'feature-inline-inapp' into levi/inline-dismiss-when-expire
levibostian Jun 12, 2024
46ba7b1
Merge branch 'levi/inline-dismiss-when-expire' into levi/inline-close…
levibostian Jun 12, 2024
b09d087
Merge branch 'feature/inline-inapp' into levi/inline-close-button
levibostian Jun 28, 2024
513bdaa
Merge branch 'feature/inline-inapp' into levi/inline-close-button
levibostian Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Foundation
// Callbacks specific to inline message events.
protocol InlineMessageManagerDelegate: AnyObject {
func sizeChanged(width: CGFloat, height: CGFloat)
func onCloseAction()
}

/**
Expand Down Expand Up @@ -38,7 +39,7 @@ class InlineMessageManager: MessageManager {
}

override func onCloseAction() {
// Not yet implemented. Planned in future update.
inlineMessageDelegate?.onCloseAction()
}
}

Expand Down
1 change: 1 addition & 0 deletions Sources/MessagingInApp/Gist/Managers/MessageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class MessageManager {
// This means that the message begins the process of loading.
// Start a timer that helps us determine how long a message took to load/render.
elapsedTimer.start(title: "Loading message with id: \(currentMessage.templateId)")

self.engine = engineWebProvider.getEngineWebInstance(configuration: engineWebConfiguration)
engine.delegate = self
self.gistView = GistView(message: currentMessage, engineView: engine.view)
Expand Down
6 changes: 6 additions & 0 deletions Sources/MessagingInApp/Views/InAppMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,10 @@ extension InAppMessageView: InlineMessageManagerDelegate {
self.animateHeight(to: height)
}
}

func onCloseAction() {
Task { @MainActor in
self.dismissInAppMessage()
}
}
}
42 changes: 42 additions & 0 deletions Tests/MessagingInApp/Views/InAppMessageViewTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,39 @@ class InAppMessageViewTest: UnitTest {
XCTAssertFalse(isDisplayingInAppMessage(inlineView)) // expect ignore new message, stay dismissed.
}

// MARK: close action button

@MainActor
func test_onCloseAction_givenCloseActionClickedOnInAppMessage_expectDismissInlineView() async {
let givenInlineMessage = Message.randomInline
queueMock.getInlineMessagesReturnValue = [givenInlineMessage]

let inlineView = InAppMessageView(elementId: givenInlineMessage.elementId!)
await onDoneRenderingInAppMessage(givenInlineMessage)
XCTAssertTrue(isDisplayingInAppMessage(inlineView))

await onCloseActionButtonPressed()

XCTAssertFalse(isDisplayingInAppMessage(inlineView))
}

// Once an in-app message has been closed it will not be replaced with another message.
// We plan to change this behavior in the future. Test function can be modified to match the new behavior at that time.
@MainActor
func test_onCloseAction_givenMessageClosed_givenNewMessageFetched_expectIgnoreMessage() async {
let givenMessageThatGetsClosed = Message.randomInline
queueMock.getInlineMessagesReturnValue = [givenMessageThatGetsClosed]

let inlineView = InAppMessageView(elementId: givenMessageThatGetsClosed.elementId!)
await onDoneRenderingInAppMessage(givenMessageThatGetsClosed)
XCTAssertTrue(isDisplayingInAppMessage(inlineView))
await onCloseActionButtonPressed()
XCTAssertFalse(isDisplayingInAppMessage(inlineView))

await simulateSdkFetchedMessages([Message.randomInline]) // simulate new message fetched
XCTAssertFalse(isDisplayingInAppMessage(inlineView)) // expect ignore new message, stay dismissed.
}

// MARK: height and width constriants

// When the View is constructed, the SDK will add a constraint or it will modify the existing height constraint.
Expand Down Expand Up @@ -291,6 +324,15 @@ extension InAppMessageViewTest {
await waitForMainThreadToFinishPendingTasks()
}

func onCloseActionButtonPressed() async {
// Triggering the close button from the web engine simulates the user tapping the close button on the in-app WebView.
// This behaves more like an integration test because we are also able to test the message manager, too.
engineWebMock.delegate?.tap(name: "", action: GistMessageActions.close.rawValue, system: false)

// When onCloseAction() is called on the inline View, it adds a task to the main thread queue. Our test wants to wait until this task is done running.
await waitForMainThreadToFinishPendingTasks()
}

func isDisplayingInAppMessage(_ view: InAppMessageView) -> Bool {
guard let viewHeightConstraint = view.heightConstraint else {
return false
Expand Down
Loading