Skip to content

Commit

Permalink
Add Snapshot tests for gva response text
Browse files Browse the repository at this point in the history
This PR adds snapshot tests for GVA response text.

MOB-2509
  • Loading branch information
rasmustautsglia authored and github-review-helper committed Aug 9, 2023
1 parent 93fb411 commit dae73ab
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
4 changes: 0 additions & 4 deletions GliaWidgets/Sources/View/Chat/Message/ChatMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ class ChatMessageView: BaseView {
)
contentView.attributedText = text
contentView.linkTapped = { [weak self] in self?.linkTapped?($0) }
contentView.accessibilityProperties = .init(
label: accProperties.label,
value: accProperties.value
)
appendContentView(contentView, animated: animated)
default:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,53 @@ extension ChatViewController {
return controller
}

static func mockGvaResponseText() throws -> ChatViewController {
var chatViewModelEnv = ChatViewModel.Environment.mock
chatViewModelEnv.fileManager.urlsForDirectoryInDomainMask = { _, _ in [URL.mock] }
chatViewModelEnv.loadChatMessagesFromHistory = { true }

let messageUuid = UUID.incrementing
let messageId = { messageUuid().uuidString }
let queueId = UUID.mock.uuidString

let jsonData = mockGvaResponseTextJson() ?? Data()
let metadataContainer = try CoreSdkMessageMetadataContainer(jsonData: jsonData, jsonDecoder: .init())
let metadata = Message.Metadata(container: metadataContainer.container)

let messages: [ChatMessage] = [
.mock(
id: messageId(),
queueID: queueId,
operator: .mock(
name: "Rasmus",
pictureUrl: "https://mock.mock/single_choice/567/image.png"
),
sender: .operator,
content: "",
attachment: nil,
downloads: [],
metadata: metadata
)
]

chatViewModelEnv.fetchChatHistory = { $0(.success(messages)) }

var viewFactoryEnv = ViewFactory.Environment.mock
viewFactoryEnv.imageViewCache.getImageForKey = { _ in UIImage.mock }

let chatViewModel = ChatViewModel.mock(environment: chatViewModelEnv)
let controller = ChatViewController.mock(
chatViewModel: chatViewModel,
viewFactory: .init(
with: .mock(),
messageRenderer: .mock,
environment: viewFactoryEnv
)
)
chatViewModel.action?(.setMessageText("Input Message Mock"))
return controller
}

// MARK: - Visitor File Download States
static func mockVisitorFileDownloadStates(completion: ([ChatMessage]) -> Void) throws -> ChatViewController {
var chatViewModelEnv = ChatViewModel.Environment.mock
Expand Down Expand Up @@ -489,6 +536,18 @@ extension ChatViewController {
}
""".data(using: .utf8)
}

static private func mockGvaResponseTextJson() -> Data? {
"""
{
"metadata":
{
"type" : "plainText",
"content" : "This is a Glia Virutal Assistant Response Text.",
}
}
""".data(using: .utf8)
}
}
// swiftlint:enable function_body_length
#endif
10 changes: 10 additions & 0 deletions SnapshotTests/ChatViewControllerLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ class ChatViewControllerLayoutTests: SnapshotTestCase {
)
}

func test_gvaResponseText() throws {
let viewController = try ChatViewController.mockGvaResponseText()
viewController.view.frame = UIScreen.main.bounds
assertSnapshot(
matching: viewController,
as: .image,
named: nameForDevice()
)
}

func test_visitorFileDownloadStates() throws {
var chatMessages: [ChatMessage] = []
let viewController = try ChatViewController.mockVisitorFileDownloadStates { messages in
Expand Down
10 changes: 10 additions & 0 deletions SnapshotTests/ChatViewControllerVoiceOverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,14 @@ class ChatViewControllerVoiceOverTests: SnapshotTestCase {
named: nameForDevice()
)
}

func test_gvaResponseText() throws {
let viewController = try ChatViewController.mockGvaResponseText()
viewController.view.frame = UIScreen.main.bounds
assertSnapshot(
matching: viewController,
as: .accessibilityImage(precision: Self.possiblePrecision),
named: nameForDevice()
)
}
}

0 comments on commit dae73ab

Please sign in to comment.