concretesolutions / kappuccino

A kotlin library to simplify how to do espresso tests on Android.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Differentiate between matchIntent methods

victorolinasc opened this issue · comments

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 :)

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(/*...*/)
    // ...
}

@victorolinasc do you mind in close your issue? 😁