Coder Social home page Coder Social logo

zhipingyang / einstein Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 2.0 378 KB

Einstein is an UITest framework that integrates the logic across the Project and UITest through AccessibilityIdentified. And in UITest, using it to better support test code writing.

Home Page: https://zhipingyang.github.io/Einstein/

License: MIT License

Swift 94.33% Ruby 4.57% Objective-C 0.90% Shell 0.19%
uitest uitesting uikit-accessibilityidentifier xctest xcuielement ui-testing xcuitest swift5 swift rawrepresentable-extension

einstein's Issues

combine enum's the RawValue type define and it's protocol as the one

public protocol PrettyRawRepresentable: RawRepresentable where RawValue == String {
    var prettyRawValue: RawValue { get }
}
public extension PrettyRawRepresentable {
    var prettyRawValue: String {
        let paths = String(reflecting: self).split(separator: ".").dropFirst()
        if String(paths.last ?? "") != rawValue {
            return rawValue
        }
        return paths.joined(separator: "_")
    }
}

As we already defined PrettyRawRepresentable's RawValue == String,
but enum cannot write as blow, why?

enum Home: PrettyRawRepresentable {    
    case setting
} 
let str = Home.seeting.prettyRawValue // Home_setting

current

enum Home: String, PrettyRawRepresentable {
    case setting
}

let str = Home.seeting.prettyRawValue // Home_setting

wants

enum Home: XXX {
    case setting
}
let str = Home.seeting.prettyRawValue // Home_setting
  • XXX can be a protocol or a struct, but should better as a subprotocol of RawRepresentable
  • XXX method already be achieved (no more code as the blow)

see more: AccessibilityIdentifier

How combine two functions as the one in `AccessibilityIdentifier`

๐Ÿ˜ค

Here is two extensions PrettyRawRepresentable+helpers.swift and RawRepresentable+helpers.swift which are support different situation on enum.
But the most unacceptable thing is that their API is almost the same

enum WayOne: String, PrettyRawRepresentable {
    case theWay
}
enum WayTwo: String {
    case theWay
}
wayOneView >>> WayOne.theWay
wayTwoView >>> WayTwo.theWay

// wayOneView.accessibilityIdentifier == "WayOne_theWay"
// called in PrettyRawRepresentable+helpers.swift
let element_1: XCUIElement = WayOne.theWay.element 

// wayTwoView.accessibilityIdentifier == "theWay"
// called in RawRepresentable+helpers.swift
let element_2: XCUIElement = WayTwo.theWay.element

current

public protocol PrettyRawRepresentable: RawRepresentable where RawValue == String {
    var prettyRawValue: RawValue { get }
}

public extension PrettyRawRepresentable {
    var prettyRawValue: String {
        let paths = String(reflecting: self).split(separator: ".").dropFirst()
        if String(paths.last ?? "") != rawValue {
            return rawValue
        }
        return paths.joined(separator: "_")
    }
}

infix operator >>>
public func >>> <T: RawRepresentable>(lhs: UIAccessibilityIdentification?, rhs: T) where T.RawValue == String {
    lhs?.accessibilityIdentifier = rhs.rawValue
}
public func >>> <T: PrettyRawRepresentable>(lhs: UIAccessibilityIdentification?, rhs: T) {
    lhs?.accessibilityIdentifier = rhs.prettyRawValue
}

wants the design

only use one function

public protocol PrettyRawRepresentable: RawRepresentable where RawValue == String {
    var rawValue: RawValue { get }
}

public extension PrettyRawRepresentable {
    var rawValue: String {
        // how todo
    }
}

infix operator >>>
public func >>> <T: RawRepresentable>(lhs: UIAccessibilityIdentification?, rhs: T) where T.RawValue == String {
    lhs?.accessibilityIdentifier = rhs.rawValue
}

About the `EasyPredicate` design

PredicateRawValue is RawValue type of EasyPredicate

current

public enum PredicateRawValue: RawRepresentable {
    public var rawValue: String { return xxx }
    public init?(rawValue: String) {
        self = .custom(regular: rawValue)
    }
    case bool(key: PredicateKey.bool, comparison: Comparison, value: Bool)
    case string(key: PredicateKey.string, comparison: Comparison, value: String)
    case type(value: XCUIElement.ElementType)
    case custom(regular: String)
}

the thinking of new design

enum PredicateRawValue<Key: RawRepresentable, Value: RawRepresentable>: RawRepresentable where Key.RawValue == String {
    var rawValue: String { return xxx }
    init?(rawValue: String) {
        self = .custom(regular: rawValue)
    }
    case keyValue(key: Key, comparison: Comparison, value: Value)
    case custom(regular: String) // unrelated with Key & Value define, shit ๐Ÿ’ฉ
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.