-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[NoQA] chore(tests): unified utilities for mocking collections #30833
Conversation
@mountiny could you please advise on the docs we can update when introducing these utilities? I'd love for people to have a place they can refer to for an explanation/have good defaults. |
I have a concern about this solution: |
@adhorodyski I think you can add this to the README of tests folder, that would make sense or create anothe md file there and link from the readme if you dont want to make that too long |
@barttom you totally can set the properties you care about with overrides, just spread the default object first (or not 😜 just stay safe, keep it typed!). The goal of these utilities is to create well typed, real-world looking objects (that take enough space and have all required properties), not to provide the real objects you might need - that's still on you (it's just that sometimes the dummy ones work). You can also provide your whole new createItem implementation and just use the I haven't tried to provide ready to use implementations of TLDR; you can treat this more like a set of utilities for mocking, not the mocks themselves 😊 |
@mountiny just updated the docs under |
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.
Seems useful, will wait to see if there's additional feedback in the Slack thread though
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.
Alright no additional feedback, but it's a dev dependency so I don't think it's a big deal, plus the benefit is nice! Merging!
Reviewer Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeiOS: NativeiOS: mWeb SafariMacOS: Chrome / SafariMacOS: Desktop |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/amyevans in version: 1.3.98-0 🚀
|
🚀 Deployed to production by https://github.com/roryabraham in version: 1.3.98-5 🚀
|
🚀 Deployed to staging by https://github.com/amyevans in version: 1.3.99-0 🚀
|
🚀 Deployed to production by https://github.com/roryabraham in version: 1.3.99-0 🚀
|
Details
This PR introduces basic testing primitives for working with collections. The goal of these APIs is to provide a solid, unified base for all the tests and reduce boilerplate needed anytime you need to work with a collection (or a collection item).
API
The
createCollection(): Record<string, T>
utility generates an N-length (default=500) map based on the provided key and item functions. The output can be used later on to eg. populate Onyx.createRandomPolicy(): Policy
andcreateRandomReport(): Report
are the first item utilities introduced to better explain the idea - they can be altered at any stage to provide good defaults and more should come with time.Generating random collection of policies (default length=500):
Same thing, but with overrides:
Fixed Issues
$ #30994
PROPOSAL: https://expensify.slack.com/archives/C01GTK53T8Q/p1699275209779529
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
N/A - this PR only includes testing utilities.
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop