-
Notifications
You must be signed in to change notification settings - Fork 206
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
[Android] add LocalClock to control time for screenshot test #1224
Merged
takahirom
merged 14 commits into
main
from
kenken/pass_clock_to_controll_time_in_preview
Sep 30, 2023
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d68ca76
add clock parameter
tkhs0604 eb10b89
add LocalClockProvider
tkhs0604 c6787c2
suppress CompositionLocalAllowList
tkhs0604 9c90ff8
replace with staticCompositionLocalOf
tkhs0604 518615b
fix format
tkhs0604 3d0f9c5
rename to LocalClock
tkhs0604 2172876
move FakeClock
tkhs0604 046fba6
fix tests
tkhs0604 d456d3f
Merge remote-tracking branch 'origin/main' into kenken/pass_clock_to_…
tkhs0604 051d5b8
inject clock provider
tkhs0604 c06314b
wrap with composition local
tkhs0604 2a755cc
Merge remote-tracking branch 'origin/main' into kenken/pass_clock_to_…
tkhs0604 de25d96
Merge branch 'main' into kenken/pass_clock_to_controll_time_in_preview
tkhs0604 d41ed3f
Merge branch 'main' into kenken/pass_clock_to_controll_time_in_preview
takahirom 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 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
This file contains 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
24 changes: 24 additions & 0 deletions
24
app-android/src/test/java/io/github/droidkaigi/confsched2023/FakeAppModule.kt
This file contains 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,24 @@ | ||
package io.github.droidkaigi.confsched2023 | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.components.SingletonComponent | ||
import dagger.hilt.testing.TestInstallIn | ||
import kotlinx.datetime.Clock | ||
import kotlinx.datetime.Instant | ||
import javax.inject.Singleton | ||
|
||
@TestInstallIn( | ||
components = [SingletonComponent::class], | ||
replaces = [AppModule::class], | ||
) | ||
@Module | ||
class FakeAppModule { | ||
@Provides | ||
@Singleton | ||
fun provideClockProvider(): ClockProvider = object : ClockProvider { | ||
override fun clock(): Clock = object : Clock { | ||
override fun now() = Instant.parse("2023-09-14T10:00:00.00Z") | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
14 changes: 14 additions & 0 deletions
14
...c/androidMain/kotlin/io/github/droidkaigi/confsched2023/ui/compositionlocal/LocalClock.kt
This file contains 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,14 @@ | ||
package io.github.droidkaigi.confsched2023.ui.compositionlocal | ||
|
||
import androidx.compose.runtime.staticCompositionLocalOf | ||
import kotlinx.datetime.Clock | ||
import kotlinx.datetime.Instant | ||
|
||
@Suppress("CompositionLocalAllowlist") | ||
val LocalClock = staticCompositionLocalOf<Clock> { | ||
Clock.System | ||
} | ||
|
||
object FakeClock : Clock { | ||
override fun now(): Instant = Instant.parse("2023-09-14T10:00:00.000Z") | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
@takahirom
It does not seem like it works well...
Do you know how I can overwrite the CompositionLocal in test environment? 🤔
Maybe, since there is no setContent in KaigiAppTest, so the only way is to add like ClockTestRule or something like that?
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.
I'm not sure too.
By the way, you might have to fix the commit history 👀
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.
Thank you, I'll investigate the cause again 🙏
And regarding your BTW comment, which commits? All?
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.
Sorry, I might see old commits 🙇
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.
The FakeClock worked well for only TimetableScreenTest on my local, but the screenshot results haven't been updated even if I pushed some commits 👀
Is there any way to update them on this PR's comment?
In case of
2023-09-14T10:00:00.000Z
In case of
2023-09-15T10:00:00.000Z
(To check the diff)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.
I've removed the comment and rerun the test. Let's see what screenshots the tests take.
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.
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.
Thank you! 🙌