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

Create compose base #439

Merged
merged 17 commits into from
Sep 23, 2021
Merged

Create compose base #439

merged 17 commits into from
Sep 23, 2021

Conversation

alorma
Copy link
Member

@alorma alorma commented Sep 3, 2021

Create barista-compose module and create first assertions.

assertDisplayed("Some text") && assertDisplayed(R.string.some_string)
assertNotDisplayed("Some text") && assertNotDisplayed(R.string.some_string)

Both depending on ComposeTestRule and `SemantincNodeInteraction``

So test will look:

  @Test
  fun assertIsDisplayed_StringTest() {
    composeTestRule.setContent {
      TextComposable("Hello world")
    }

    composeTestRule.assertDisplayed("Hello world")
  }

  @Test
  fun assertDisplayed_ResourceTest() {
    composeTestRule.setContent {
      TextComposable(stringResource(R.string.app_name))
    }

    composeTestRule.assertNotDisplayed(R.string.next)
  }

@alorma alorma added the wip label Sep 3, 2021
@alorma alorma force-pushed the compose_base branch 5 times, most recently from e63273d to eda9763 Compare September 3, 2021 10:29
@rocboronat rocboronat changed the title Crete compose base Create compose base Sep 3, 2021
@alorma alorma removed the wip label Sep 8, 2021
Copy link

@costular costular left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, looks good to me 👌🏼
Just added some comments that could be an improvement

sample/build.gradle.kts Outdated Show resolved Hide resolved
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.junit4.ComposeTestRule

internal fun ComposeTestRule.resources() = if (this is AndroidComposeTestRule<*, *>) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it!

WrappedTextComposable(text = text, nodeTestTag = "Node test")
}

composeTestRule.onNodeWithTag("Node test").assertIsDisplayed(text = "Barista")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use text variable instead of hardcoded Barista text?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same than before :·)

@rocboronat
Copy link
Member

rocboronat commented Sep 9, 2021

Hello! 👋

Same than @victormpineda : I would try to mimic Barista's API. Why don't call those methods assertDisplayed and instead of receiving named parameters, receive plain old ones? If you pass a text it's the hardcoded text, if you pass a int it's a R.string... It makes the API less verbose.

Thanks for the contribution, of course! It's a big step forward 💌

@Sloy
Copy link
Member

Sloy commented Sep 9, 2021

+1 on the Barista-style API. My idea of a Barista for Compose would be to have the same simple straightforward human-readable API. Function names with a few words with a couple of parameters to perform the most common tasks.
What are the most common tasks? The ones in the existing Barista API! 😄

A more flexible or modularized API is cool too (I don't know if it's needed, I haven't tried Compose test API yet). But, in my opinion, it would be a different thing from Barista.

@costular
Copy link

costular commented Sep 9, 2021

Hello! 👋

Same than @victormpineda : I would try to mimic Barista's API. Why don't call those methods assertDisplayed and instead of receiving named parameters, receive plain old ones? If you pass a text it's the hardcoded text, if you pass a int it's a R.string... It makes the API less verbose.

Thanks for the contribution, of course! It's a big step forward 💌

If I'm not wrong there are different methods for hardcoded text and string resource. The named parameters are optional and related to the specific Compose API.

@rocboronat
Copy link
Member

Hi @costular ! Right now, the API is like this:

assertDisplayed("Hello world");
assertDisplayed(R.string.hello_world);
assertDisplayed(R.id.button);
assertDisplayed(R.id.button, "Hello world")
assertDisplayed(R.id.button, R.string.hello_world)

@costular
Copy link

costular commented Sep 9, 2021

Hi @costular ! Right now, the API is like this:

assertDisplayed("Hello world");
assertDisplayed(R.string.hello_world);
assertDisplayed(R.id.button);
assertDisplayed(R.id.button, "Hello world")
assertDisplayed(R.id.button, R.string.hello_world)

Maybe you understood me wrong or I did. You said that you prefer to receive plain parameters and what I'm saying is this PR contains different methods for hardcoded and resource assertions (like you asked) plus Compose API arguments:

useUnmergedTree: Boolean = false,
substring: Boolean = false,
ignoreCase: Boolean = false

I think if we change the order of the arguments like this:

fun ComposeTestRule.assertDisplayed(
  @StringRes textRes: Int,
  useUnmergedTree: Boolean = false,
  substring: Boolean = false,
  ignoreCase: Boolean = false
)

We can do something like this:

// Plain
composeTestRule.assertDisplayed(R.string.some_text)
// Use unmerged tree which is part of Compose API
composeTestRule.assertDisplayed(R.string.some_text, useUnmergedTree = true)

What do you think?

@rocboronat
Copy link
Member

Ah! Seems great! But we need an assertDisplayed() that receives the hardcoded value, too. So maybe this does the job?

fun ComposeTestRule.assertDisplayed(
  text: String,
  useUnmergedTree: Boolean = false,
  substring: Boolean = false,
  ignoreCase: Boolean = false
)
fun ComposeTestRule.assertDisplayed(
  @StringRes textRes: Int,
  useUnmergedTree: Boolean = false,
  substring: Boolean = false,
  ignoreCase: Boolean = false
)

@costular
Copy link

costular commented Sep 9, 2021

Ah! Seems great! But we need an assertDisplayed() that receives the hardcoded value, too. So maybe this does the job?

fun ComposeTestRule.assertDisplayed(
  text: String,
  useUnmergedTree: Boolean = false,
  substring: Boolean = false,
  ignoreCase: Boolean = false
)
fun ComposeTestRule.assertDisplayed(
  @StringRes textRes: Int,
  useUnmergedTree: Boolean = false,
  substring: Boolean = false,
  ignoreCase: Boolean = false
)

This would work perfectly!

@rocboronat
Copy link
Member

What do you think, @alorma? Does it break your plans too much?

@alorma
Copy link
Member Author

alorma commented Sep 9, 2021

Hi everyone! Wow so great discussions here!

I won't be able to work on this until later today but yeah, your proposals look great.

Let me redo this PR applying your suggestions

@alorma
Copy link
Member Author

alorma commented Sep 9, 2021

Hello @rocboronat @Sloy @costular @victormpineda!(wow, so many contributors on this PR!!!)

I've applied all the comments suggested on the PR, so now the API matches barista style methods.

What do you think? Is ok as a first step to have a barista-compose API?

@alorma alorma requested review from rocboronat and Sloy September 9, 2021 12:52
@costular
Copy link

costular commented Sep 9, 2021

@alorma Go ahead! IMHO it suits our needs for the first step with barista-compose. As soon as it's deployed we'll use it!

@costular
Copy link

@rocboronat @Sloy Any updates on this?

TextComposable(text = "Hello world")
}

composeTestRule.assertDisplayed(text = "Hello world")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the same approach we did in the regular Barista, like composeTestRule.assertDisplayed("Hello world")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, removed it!

@rocboronat
Copy link
Member

Hello @alorma! That's my only feedback. As soon as you update the tests or just add cases that call the assertDisplayed method by the regular way, without specifying the text, textRes and so on, feel free to merge it with your admin superpowers 💪

Congratulations on this PR! It's a step that will make lots of people happier 😄

@alorma alorma merged commit 3f0e105 into master Sep 23, 2021
@alorma alorma deleted the compose_base branch September 23, 2021 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants