feat: update app workflows and permissions
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
// suixinkanTests
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import XCTest
|
||||
@testable import suixinkan
|
||||
|
||||
@ -48,6 +49,33 @@ final class HomeViewModelTests: XCTestCase {
|
||||
XCTAssertEqual(viewModel.locationInfoText, "您已进入打卡范围")
|
||||
}
|
||||
|
||||
func testQuickActionsOnlineEntrySyncsOfflineStyle() throws {
|
||||
let view = HomeQuickActionsView()
|
||||
|
||||
view.apply(isOnline: false)
|
||||
|
||||
let statusContainer = try statusActionContainer(in: view)
|
||||
XCTAssertEqual(statusContainer.backgroundColor?.homeTestHexRGB, AppColor.cardBackground.homeTestHexRGB)
|
||||
XCTAssertEqual(statusContainer.layer.borderWidth, 1)
|
||||
XCTAssertEqual(statusLabel(in: statusContainer)?.text, "离线")
|
||||
XCTAssertEqual(statusLabel(in: statusContainer)?.textColor.homeTestHexRGB, AppColor.textTabInactive.homeTestHexRGB)
|
||||
XCTAssertEqual(statusIcon(in: statusContainer)?.accessibilityIdentifier, "wifi.slash")
|
||||
XCTAssertEqual(statusIcon(in: statusContainer)?.tintColor.homeTestHexRGB, AppColor.textTabInactive.homeTestHexRGB)
|
||||
}
|
||||
|
||||
func testQuickActionsOnlineEntrySyncsOnlineStyle() throws {
|
||||
let view = HomeQuickActionsView()
|
||||
|
||||
view.apply(isOnline: true)
|
||||
|
||||
let statusContainer = try statusActionContainer(in: view)
|
||||
XCTAssertEqual(statusContainer.backgroundColor?.homeTestHexRGB, AppColor.online.homeTestHexRGB)
|
||||
XCTAssertEqual(statusLabel(in: statusContainer)?.text, "在线")
|
||||
XCTAssertEqual(statusLabel(in: statusContainer)?.textColor.homeTestHexRGB, AppColor.successBackground.homeTestHexRGB)
|
||||
XCTAssertEqual(statusIcon(in: statusContainer)?.accessibilityIdentifier, "wifi")
|
||||
XCTAssertEqual(statusIcon(in: statusContainer)?.tintColor.homeTestHexRGB, AppColor.successBackground.homeTestHexRGB)
|
||||
}
|
||||
|
||||
func testRebuildCommonMenusFiltersUnknownURIs() {
|
||||
appStore.savePermissionItems([
|
||||
HomePermissionItem(id: "1", name: "钱包", uri: "wallet"),
|
||||
@ -178,4 +206,49 @@ final class HomeViewModelTests: XCTestCase {
|
||||
XCTAssertEqual(viewModel.currentScenicName, "")
|
||||
XCTAssertEqual(appStore.currentScenicName, "")
|
||||
}
|
||||
|
||||
private func statusActionContainer(in view: HomeQuickActionsView) throws -> UIView {
|
||||
let stackView = try XCTUnwrap(view.subviews.compactMap { $0 as? UIStackView }.first)
|
||||
XCTAssertEqual(stackView.arrangedSubviews.count, 3)
|
||||
return stackView.arrangedSubviews[2]
|
||||
}
|
||||
|
||||
private func statusLabel(in view: UIView) -> UILabel? {
|
||||
if let label = view as? UILabel {
|
||||
return label
|
||||
}
|
||||
for subview in view.subviews {
|
||||
if let label = statusLabel(in: subview) {
|
||||
return label
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
private func statusIcon(in view: UIView) -> UIImageView? {
|
||||
if let imageView = view as? UIImageView {
|
||||
return imageView
|
||||
}
|
||||
for subview in view.subviews {
|
||||
if let imageView = statusIcon(in: subview) {
|
||||
return imageView
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
private extension UIColor {
|
||||
|
||||
var homeTestHexRGB: UInt {
|
||||
var red: CGFloat = 0
|
||||
var green: CGFloat = 0
|
||||
var blue: CGFloat = 0
|
||||
var alpha: CGFloat = 0
|
||||
getRed(&red, green: &green, blue: &blue, alpha: &alpha)
|
||||
let r = Int(round(red * 255))
|
||||
let g = Int(round(green * 255))
|
||||
let b = Int(round(blue * 255))
|
||||
return UInt(r << 16 | g << 8 | b)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user