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

Add Snapshot tests for GVA response text #708

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this was removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is applicable only to a normal message, and not to an attributed message. Removing that was essential for the accessibility to be displayed properly

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()
)
}
}
Loading