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

Easy testing of business logic #1

Closed
swankjesse opened this issue Nov 2, 2020 · 3 comments · Fixed by #84
Closed

Easy testing of business logic #1

swankjesse opened this issue Nov 2, 2020 · 3 comments · Fixed by #84

Comments

@swankjesse
Copy link
Collaborator

I’d like to build out test infrastructure. A sketch of how it might work:

fun test() {
  val renderer = TreehouseRenderer()

  renderer.compose {
    Counter(100)
  }
  assertThat((renderer.root[0] as SunspotButton).text).isEqualTo("-1")
  assertThat((renderer.root[1] as SunspotText).text).isEqualTo("100")

  (renderer.root[0] as SunspotButton).onClick()

  renderer.recompose() // Necessary?
  assertThat((renderer.root[1] as SunspotText).text).isEqualTo("99")
}

The renderer’s root is a Kotlin value object of the most recently composed view.

We could make it so onClick() automatically recomposes, or we could make it explicit.

@JakeWharton
Copy link
Member

Potentially blocked by #14 since we basically want to change from operating on the real nodes to the schema nodes. However, we could also still use the real nodes and then use the protocol output to operate on a schema node tree without doing #14. This is probably where to start since #14 is being deprioritized due to how we are going to deploy the project.

@JakeWharton
Copy link
Member

In order to avoid yet-another code generation module, I think we can do this by parsing the schema again at runtime and building an in-memory version of the NodeFactory which factories schema nodes. The downside is that if you do this incorrectly you parse the schema each time. It's probably fast enough to not matter, I guess we'll find out.

We also need to expose the clock ticking mechanism so you can control when frames occur. For now we'll probably just go with direct BroadcastFrameClock usage to get off the ground, but it seems like there should be a 'treehouse' artifact that has the compose+display integration that seems to get repeated on each platform and can also have the testing version of that integration.

@JakeWharton
Copy link
Member

This approach doesn't work anywhere except the JVM because of the use of kotlin-reflect-full which only works on JVM. Maybe that's fine for now, but isn't great long-term.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants