-
Notifications
You must be signed in to change notification settings - Fork 80
Add iOS change list renderer tests #1197
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
Open
apatronl
wants to merge
2
commits into
trunk
Choose a base branch
from
alejandrina/snapshot-test
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...od-treehouse-host/src/iosTest/kotlin/app/cash/redwood/treehouse/ChangeListRendererTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.treehouse | ||
|
||
import app.cash.redwood.testing.toChangeList | ||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import example.redwood.compose.ExampleSchemaProtocolBridge | ||
import example.redwood.compose.Row | ||
import example.redwood.compose.Text | ||
import example.redwood.widget.ExampleSchemaTester | ||
import kotlin.test.Test | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import platform.UIKit.UILabel | ||
import platform.UIKit.UIStackView | ||
import platform.UIKit.UIView | ||
|
||
class ChangeListRendererTest { | ||
@Test fun createSnapshotChangeListAndRenderIt() = runTest { | ||
ExampleSchemaTester { | ||
setContent { | ||
Text("hello") | ||
} | ||
val snapshot = awaitSnapshot() | ||
val snapshotChangeList = snapshot.toChangeList(ExampleSchemaProtocolBridge) | ||
|
||
val treehouseUIKitView = TreehouseUIKitView(ExampleSchemaWidgetSystem()) | ||
|
||
val renderer = ChangeListRenderer<UIView>(Json) | ||
renderer.render(treehouseUIKitView, snapshotChangeList) | ||
|
||
val uiView = treehouseUIKitView.view | ||
assertThat((uiView.subviews.firstOrNull() as? UILabel)?.text).isEqualTo("hello") | ||
} | ||
} | ||
|
||
@Test fun renderSnapshotChangeListWithSubviews() = runTest { | ||
ExampleSchemaTester { | ||
setContent { | ||
Row { | ||
Text("red") | ||
Text("orange") | ||
Text("yellow") | ||
} | ||
} | ||
val snapshot = awaitSnapshot() | ||
val snapshotChangeList = snapshot.toChangeList(ExampleSchemaProtocolBridge) | ||
|
||
val treehouseUIKitView = TreehouseUIKitView(ExampleSchemaWidgetSystem()) | ||
|
||
val renderer = ChangeListRenderer<UIView>(Json) | ||
renderer.render(treehouseUIKitView, snapshotChangeList) | ||
|
||
val uiView = treehouseUIKitView.view | ||
val row = uiView.subviews.firstOrNull() as UIStackView | ||
assertThat((row.subviews[0] as? UILabel)?.text).isEqualTo("red") | ||
assertThat((row.subviews[1] as? UILabel)?.text).isEqualTo("orange") | ||
assertThat((row.subviews[2] as? UILabel)?.text).isEqualTo("yellow") | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...e-host/src/iosTest/kotlin/app/cash/redwood/treehouse/DefaultExampleSchemaWidgetFactory.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.treehouse | ||
|
||
import example.redwood.widget.Button | ||
import example.redwood.widget.Button2 | ||
import example.redwood.widget.ExampleSchemaWidgetFactory | ||
import example.redwood.widget.Row | ||
import example.redwood.widget.ScopedRow | ||
import example.redwood.widget.Space | ||
import example.redwood.widget.Text | ||
import example.redwood.widget.TextInput | ||
import platform.UIKit.UIView | ||
|
||
class DefaultExampleSchemaWidgetFactory : ExampleSchemaWidgetFactory<UIView> { | ||
override fun Row(): Row<UIView> = RowBinding() | ||
override fun ScopedRow(): ScopedRow<UIView> = TODO("Not yet implemented") | ||
override fun Text(): Text<UIView> = TextBinding() | ||
override fun Button(): Button<UIView> = TODO("Not yet implemented") | ||
override fun Button2(): Button2<UIView> = TODO("Not yet implemented") | ||
override fun TextInput(): TextInput<UIView> = TODO("Not yet implemented") | ||
override fun Space(): Space<UIView> = TODO("Not yet implemented") | ||
} |
38 changes: 38 additions & 0 deletions
38
...treehouse-host/src/iosTest/kotlin/app/cash/redwood/treehouse/ExampleSchemaWidgetSystem.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.treehouse | ||
|
||
import app.cash.redwood.layout.uiview.UIViewRedwoodLayoutWidgetFactory | ||
import app.cash.redwood.protocol.widget.ProtocolMismatchHandler | ||
import app.cash.redwood.protocol.widget.ProtocolNode | ||
import example.redwood.widget.ExampleSchemaProtocolNodeFactory | ||
import example.redwood.widget.ExampleSchemaWidgetFactories | ||
import kotlinx.serialization.json.Json | ||
|
||
/** Basic UIView implementation of the example schema, for testing. */ | ||
class ExampleSchemaWidgetSystem : TreehouseView.WidgetSystem { | ||
override fun widgetFactory( | ||
json: Json, | ||
protocolMismatchHandler: ProtocolMismatchHandler, | ||
): ProtocolNode.Factory<*> { | ||
return ExampleSchemaProtocolNodeFactory( | ||
provider = ExampleSchemaWidgetFactories( | ||
ExampleSchema = DefaultExampleSchemaWidgetFactory(), | ||
RedwoodLayout = UIViewRedwoodLayoutWidgetFactory(), | ||
), | ||
) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
redwood-treehouse-host/src/iosTest/kotlin/app/cash/redwood/treehouse/RowBinding.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.treehouse | ||
|
||
import app.cash.redwood.Modifier | ||
import app.cash.redwood.widget.UIViewChildren | ||
import app.cash.redwood.widget.Widget | ||
import example.redwood.widget.Row | ||
import platform.UIKit.UIStackView | ||
import platform.UIKit.UIView | ||
|
||
/** Note: this doesn't bother to arrange child views horizontally! */ | ||
class RowBinding : Row<UIView> { | ||
override val value = UIStackView() | ||
|
||
override var modifier: Modifier = Modifier | ||
|
||
override val children: Widget.Children<UIView> = UIViewChildren(value) | ||
} |
30 changes: 30 additions & 0 deletions
30
redwood-treehouse-host/src/iosTest/kotlin/app/cash/redwood/treehouse/TextBinding.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package app.cash.redwood.treehouse | ||
|
||
import app.cash.redwood.Modifier | ||
import example.redwood.widget.Text | ||
import platform.UIKit.UILabel | ||
import platform.UIKit.UIView | ||
|
||
class TextBinding : Text<UIView> { | ||
override val value = UILabel() | ||
override var modifier: Modifier = Modifier | ||
|
||
override fun text(text: String?) { | ||
value.text = text ?: "" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We MIGHT want to change these to
error("unexpected call")
because I think there’s a robot that creates GitHub issues for all of our TODOs in this repo. I don’t think we ever want to actually do this work.