concretesolutions / kappuccino

A kotlin library to simplify how to do espresso tests on Android.
Apache License 2.0
109 stars 20 forks source link

Differentiate between matchIntent methods #89

Closed victorolinasc closed 6 years ago

victorolinasc commented 6 years ago

Current behaviour is to detect if a matchIntent is intending or intended by the contents of the clojure: whether it uses the result methods will decide upon its use.

I think this is a bit confusing and more implicit than explicit. I understand that both methods take a Matcher<Intent> parameter though they are meant for different things. Even the name match is not exactly what it does: it matches to either validate or stub (as per Espresso docs). So, in my opinion we could have a different DSL here. Something like:

// V1 proposal
// Validating
triggeredIntent { // or maybe sentIntent {}
    action(Intent.ACTION_VIEW)
}

// Stubbing
stubIntent {
    action(Intent.ACTION_VIEW)
} withResult {
    ok()
    intent().setAction(Intent.ACTION_VIEW)
}

// Slight variation
// Stubbing
stubIntent {
    action(Intent.ACTION_VIEW)
} respondWithOk { // or respondWithCanceled {} or respondWith(code) {}
    setAction(Intent.ACTION_VIEW)
    setData(/*...*/)
    // ...
}

// --------------

// V2 proposal
// Validating
 matchIntent {
    action(Intent.ACTION_VIEW)
    url(PLAY_STORE_URL + WHATS_PACKAGE_NAME)
} wasSent() // be explicit though a bit awkward

// Stubbing
 matchIntent {
    action(Intent.ACTION_VIEW)
    url(PLAY_STORE_URL + WHATS_PACKAGE_NAME)
} returnWith { // be explicit though a bit awkward
    ok()
    intent().setAction(Intent.ACTION_VIEW)
}

(I am not too sure how we could elegantly populate the intent. Perhaps follow the "anko" way here would be the best alternative...).

The proposals try to be closer to the espresso intentions and perhaps ease future additions to this API. I prefer V1 IMHO.

Please, feel free to say this makes no sense :)

heitorcolangelo commented 6 years ago

I agree, and that's a excellent suggestion, thank you! What do you think about this variation?

// V3 proposal
// Validating
sentIntent {
    action(Intent.ACTION_VIEW)
}

// Stubbing
stubIntent {
    action(Intent.ACTION_VIEW)
} respondWithOk { // or respondWithCanceled {} or respondWith(code) {}
    setAction(Intent.ACTION_VIEW)
    setData(/*...*/)
    // ...
}
heitorcolangelo commented 6 years ago

@victorolinasc https://github.com/heitorcolangelo/kappuccino/pull/96

heitorcolangelo commented 6 years ago

@victorolinasc do you mind in close your issue? 😁

victorolinasc commented 6 years ago

SOrry!