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

Cover GVA persistent button with snapshot tests #705

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: 2 additions & 2 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@
7552DFA72A683A2C0093519B /* NSLayoutConstraint+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75940957298D386F008B173A /* NSLayoutConstraint+Extensions.swift */; };
7552DFA82A683A2C0093519B /* UIStackView.Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75940956298D386F008B173A /* UIStackView.Extensions.swift */; };
7552DFB12A6FB7DF0093519B /* ChatMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7552DFB02A6FB7DF0093519B /* ChatMessageTests.swift */; };
7552DFB42A6FBC7F0093519B /* CoreSdk.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7552DFB32A6FBC7F0093519B /* CoreSdk.swift */; };
755D186529A6A4E20009F5E8 /* WelcomeStyle+TitleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D186429A6A4E20009F5E8 /* WelcomeStyle+TitleStyle.swift */; };
755D186729A6A4FA0009F5E8 /* WelcomeStyle+SubtitleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D186629A6A4FA0009F5E8 /* WelcomeStyle+SubtitleStyle.swift */; };
755D186929A6A5270009F5E8 /* WelcomeStyle+CheckMessagesButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D186829A6A5270009F5E8 /* WelcomeStyle+CheckMessagesButtonStyle.swift */; };
Expand Down Expand Up @@ -299,6 +298,7 @@
75CF8D9129C3A85C00CB1524 /* SecureConversationsWelcomeScreenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75CF8D9029C3A85C00CB1524 /* SecureConversationsWelcomeScreenTests.swift */; };
75CF8DAD29C8F2B500CB1524 /* SecureConversationsConfirmationScreenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75CF8DAC29C8F2B500CB1524 /* SecureConversationsConfirmationScreenTests.swift */; };
75F58EE127E7D5300065BA2D /* Survey.ViewController.Props.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F58EE027E7D5300065BA2D /* Survey.ViewController.Props.swift */; };
75FD003F2A80E8C5002DC458 /* CoreSdk.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7552DFB32A6FBC7F0093519B /* CoreSdk.swift */; };
75FF151427F3A2D600FE7BE2 /* Theme+Survey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75FF151327F3A2D600FE7BE2 /* Theme+Survey.swift */; };
75FF151727F4E13900FE7BE2 /* Theme.Survey.BooleanQuestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75FF151627F4E13900FE7BE2 /* Theme.Survey.BooleanQuestion.swift */; };
75FF151B27F4F52D00FE7BE2 /* Theme.Survey.SingleQuestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75FF151A27F4F52D00FE7BE2 /* Theme.Survey.SingleQuestion.swift */; };
Expand Down Expand Up @@ -4478,6 +4478,7 @@
754CC61227E2767A005676E9 /* Survey.BooleanQuestionView.swift in Sources */,
755D187529A6A6B70009F5E8 /* WelcomeStyle+SendButton.swift in Sources */,
6EA3516926E139DA00BF5941 /* GliaViewTransitionController.swift in Sources */,
75FD003F2A80E8C5002DC458 /* CoreSdk.swift in Sources */,
C0D2F07929A4E3DF00803B47 /* UserImageView.Mock.swift in Sources */,
84265E6B29912E2100D65842 /* RemoteConfiguration+CallVisualizer.swift in Sources */,
1A1E30C725F9FDAB00850E68 /* ChatImageFileContentView.swift in Sources */,
Expand Down Expand Up @@ -4554,7 +4555,6 @@
84681A982A61853300DD7406 /* GvaOption.Mock.swift in Sources */,
AF6AB34B2989517100003645 /* FileUploader.Failing.swift in Sources */,
EB03B00E27FFF6DD0058F6B1 /* CallViewTests.swift in Sources */,
7552DFB42A6FBC7F0093519B /* CoreSdk.swift in Sources */,
3197F7AD29E6A5C8008EE9F7 /* SecureConversations.FileUploadListView.Mock.swift in Sources */,
AF29810929E045CE0005BD55 /* TranscriptModelTests.swift in Sources */,
7512A57727BE8A6700319DF1 /* InteractorTests.swift in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions GliaWidgets/Sources/Theme/Theme+Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ extension Theme {
let visitorText = ChatTextContentStyle(
textFont: font.bodyText,
textColor: color.baseLight,
textStyle: .body,
backgroundColor: color.primary,
accessibility: .init(isFontScalingEnabled: true)
)
Expand All @@ -177,6 +178,7 @@ extension Theme {
let operatorText = ChatTextContentStyle(
textFont: font.bodyText,
textColor: color.baseDark,
textStyle: .body,
backgroundColor: Color.lightGrey,
accessibility: .init(isFontScalingEnabled: true)
)
Expand All @@ -201,6 +203,7 @@ extension Theme {
let choiceCardText = ChatTextContentStyle(
textFont: font.bodyText,
textColor: color.baseDark,
textStyle: .body,
backgroundColor: color.baseLight,
accessibility: .init(isFontScalingEnabled: true)
)
Expand All @@ -215,6 +218,7 @@ extension Theme {
let choiceCardOptionNormalState = ChoiceCardOptionStateStyle(
textFont: font.bodyText,
textColor: color.baseDark,
textStyle: .body,
backgroundColor: Color.lightGrey,
borderColor: nil,
accessibility: .init(
Expand All @@ -225,6 +229,7 @@ extension Theme {
let choiceCardOptionSelectedState = ChoiceCardOptionStateStyle(
textFont: font.bodyText,
textColor: color.baseLight,
textStyle: .body,
backgroundColor: color.primary,
borderColor: nil,
accessibility: .init(
Expand All @@ -235,6 +240,7 @@ extension Theme {
let choiceCardOptionDisabledState = ChoiceCardOptionStateStyle(
textFont: font.bodyText,
textColor: Color.grey,
textStyle: .body,
backgroundColor: Color.lightGrey,
borderColor: Color.baseShade,
accessibility: .init(
Expand Down
7 changes: 5 additions & 2 deletions GliaWidgets/Sources/Theme/Theme+Gva.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ extension Theme {
title: .init(
textFont: font.bodyText,
textColor: .black,
backgroundColor: .clear
textStyle: .body,
backgroundColor: .clear,
accessibility: .init(isFontScalingEnabled: true)
),
backgroundColor: .fill(color: color.lightGrey),
cornerRadius: 10,
Expand All @@ -20,7 +22,8 @@ extension Theme {
backgroundColor: .fill(color: color.background),
cornerRadius: 5,
borderColor: .clear,
borderWidth: 0
borderWidth: 0,
accessibility: .init(isFontScalingEnabled: true)
)
)

Expand Down
2 changes: 1 addition & 1 deletion GliaWidgets/Sources/View/Chat/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ extension ChatView {

private func gvaResponseTextView(
_ message: ChatMessage,
text: NSAttributedString,
text: NSMutableAttributedString,
showImage: Bool,
imageUrl: String?
) -> GvaResponseTextView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class GvaPersistentButtonOptionView: BaseView {

override func setup() {
super.setup()
isAccessibilityElement = true
accessibilityLabel = text
accessibilityTraits = .button
layer.cornerRadius = style.cornerRadius
layer.borderWidth = style.borderWidth
layer.borderColor = style.borderColor.cgColor
Expand All @@ -38,14 +41,19 @@ class GvaPersistentButtonOptionView: BaseView {
textLabel.numberOfLines = 0
textLabel.isAccessibilityElement = false

setFontScalingEnabled(
style.accessibility.isFontScalingEnabled,
for: textLabel
)

choiceButton.addTarget(self, action: #selector(onTap), for: .touchUpInside)
}

override func defineLayout() {
super.defineLayout()
var constraints = [NSLayoutConstraint](); defer { constraints.activate() }

heightAnchor.constraint(equalToConstant: Self.height).isActive = true
heightAnchor.constraint(greaterThanOrEqualToConstant: 42).isActive = true
addSubview(textLabel)
textLabel.translatesAutoresizingMaskIntoConstraints = false
constraints += textLabel.layoutInSuperview(insets: viewInsets)
Expand All @@ -67,22 +75,6 @@ class GvaPersistentButtonOptionView: BaseView {
}
}

private func applyStyle(_ style: ChoiceCardOptionStateStyle) {
setFontScalingEnabled(
style.accessibility.isFontScalingEnabled,
for: textLabel
)

UIView.transition(with: textLabel, duration: 0.2, options: .transitionCrossDissolve) {
self.layer.backgroundColor = style.backgroundColor.cgColor
self.textLabel.textColor = style.textColor
if let borderColor = style.borderColor {
self.layer.borderColor = borderColor.cgColor
self.layer.borderWidth = style.borderWidth
}
}
}

@objc private func onTap() {
tap?()
}
Expand Down
36 changes: 35 additions & 1 deletion GliaWidgets/Sources/View/Chat/GVA/GvaPersistentButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,18 @@ extension GvaPersistentButtonStyle {
/// Border width of the button
public var borderWidth: CGFloat

/// Accessibility
public var accessibility: Accessibility

init(
textFont: UIFont,
textColor: UIColor,
textStyle: UIFont.TextStyle = .title2,
backgroundColor: ColorType,
cornerRadius: CGFloat,
borderColor: UIColor,
borderWidth: CGFloat
borderWidth: CGFloat,
accessibility: Accessibility = .unsupported
) {
self.textFont = textFont
self.textColor = textColor
Expand All @@ -128,6 +132,7 @@ extension GvaPersistentButtonStyle {
self.cornerRadius = cornerRadius
self.borderColor = borderColor
self.borderWidth = borderWidth
self.accessibility = accessibility
}

mutating func apply(
Expand Down Expand Up @@ -180,3 +185,32 @@ extension GvaPersistentButtonStyle {
}
}
}

extension GvaPersistentButtonStyle {
/// Accessibility properties for ChoiceCardOptionStateStyle.
public struct Accessibility: Equatable {
/// Accessibility value.
public var value: String

/// Flag that provides font dynamic type by setting `adjustsFontForContentSizeCategory` for component that supports it.
public var isFontScalingEnabled: Bool

///
/// - Parameters:
/// - value: Accessibility value.
/// - isFontScalingEnabled: Flag that provides font dynamic type by setting `adjustsFontForContentSizeCategory` for component that supports it.
public init(
value: String = "",
isFontScalingEnabled: Bool
) {
self.value = value
self.isFontScalingEnabled = isFontScalingEnabled
}

/// Accessibility is not supported intentionally.
public static let unsupported = Self(
value: "",
isFontScalingEnabled: false
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enum ChatMessageContent {
case downloads([FileDownload], accessibility: ChatFileContentView.AccessibilityProperties)
case choiceCard(ChoiceCard)
case gvaPersistentButton(GvaButton)
case attributedText(NSAttributedString, accessibility: TextAccessibilityProperties)
case attributedText(NSMutableAttributedString, accessibility: TextAccessibilityProperties)

struct TextAccessibilityProperties {
let label: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public final class ChoiceCardOptionStateStyle: ChatTextContentStyle {
public init(
textFont: UIFont,
textColor: UIColor,
textStyle: UIFont.TextStyle,
backgroundColor: UIColor,
borderColor: UIColor?,
borderWidth: CGFloat = 1,
Expand All @@ -28,6 +29,7 @@ public final class ChoiceCardOptionStateStyle: ChatTextContentStyle {
super.init(
textFont: textFont,
textColor: textColor,
textStyle: textStyle,
backgroundColor: backgroundColor,
accessibility: accessibility
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ public class ChatTextContentStyle {
/// - Parameters:
/// - textFont: Font of the message text.
/// - textColor: Color of the message text.
/// - textStyle: Text style of the message text.
/// - textStyle: Text style of the message text. Necessary for attributed strings.
/// - backgroundColor: Background color of the content view.
/// - accessibility: Accessibility related properties.
///
public init(
textFont: UIFont,
textColor: UIColor,
textStyle: UIFont.TextStyle = .body,
textStyle: UIFont.TextStyle,
backgroundColor: UIColor,
cornerRadius: CGFloat = 8.49,
accessibility: Accessibility = .unsupported
accessibility: Accessibility
) {
self.textFont = textFont
self.textColor = textColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class ChatTextContentView: BaseView {
set { setText(newValue) }
}

var attributedText: NSAttributedString? {
get { return textView.attributedText }
var attributedText: NSMutableAttributedString? {
get { return textView.attributedText as? NSMutableAttributedString }
set { return setAttributedText(newValue) }
}

Expand Down Expand Up @@ -68,7 +68,6 @@ class ChatTextContentView: BaseView {
textView.font = style.textFont
textView.backgroundColor = .clear
textView.textColor = style.textColor
textView.isAccessibilityElement = false

setFontScalingEnabled(
style.accessibility.isFontScalingEnabled,
Expand Down Expand Up @@ -110,7 +109,7 @@ class ChatTextContentView: BaseView {
textView.accessibilityIdentifier = text
}

private func setAttributedText(_ text: NSAttributedString?) {
private func setAttributedText(_ text: NSMutableAttributedString?) {
guard let text, !text.string.isEmpty else {
textView.removeFromSuperview()
return
Expand All @@ -124,20 +123,19 @@ class ChatTextContentView: BaseView {
}

let attributes: [NSAttributedString.Key: Any] = [
.font: style.textFont,
.font: UIFont.preferredFont(forTextStyle: style.textStyle),
.foregroundColor: style.textColor
]

let attributedText = NSMutableAttributedString(attributedString: text)
attributedText.addAttributes(
text.addAttributes(
attributes,
range: NSRange(
location: 0,
length: attributedText.length
length: text.length
)
)

textView.attributedText = attributedText
textView.attributedText = text
textView.accessibilityIdentifier = text.string
}
}
Expand Down Expand Up @@ -168,8 +166,9 @@ extension ChatTextContentView {
with: ChatTextContentStyle(
textFont: .systemFont(ofSize: 10),
textColor: .black,
textStyle: .body,
backgroundColor: .black,
accessibility: .unsupported
accessibility: .init(isFontScalingEnabled: true)
),
contentAlignment: .left,
insets: .zero
Expand Down
Loading
Loading