-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat(nova-react-test-utils): add storybook decorator for nova #72
feat(nova-react-test-utils): add storybook decorator for nova #72
Conversation
a41fdaa
to
21d1437
Compare
381a363
to
03009b2
Compare
03009b2
to
3a02c2f
Compare
move operation utils make mock environment a bit more generic add first version of the decorator add peer dependency try bumping graphitation relay complier as well Change files initial example use older version of complier generate types add storybook [DO NOT MERGE] add autogenerated stories fix lage config remove stories align version of test types use makeDecorator api add codegen add initial story add more loaders use proper loader
5913109
to
42a0671
Compare
Feedback: () => sampleFeedback, | ||
}, | ||
}, | ||
} satisfies NovaEnvironmentDecoratorParameters<TypeMap>, |
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.
Would be nice if we can get rid of this in the future.
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.
of satisfies
? Then probably no, we won't get rid of it. We still need a way to strongly type parameters
(by default it's just generic Record
) so we either need to use satisfies or adjust story type itself
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.
Yeah the satisfies part. I figured this was the reason, but I’m thinking that it should be very possible to explain users how they can create their own StoryObj type that composed the normal StoryObj and a resolvers map with their schema.
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.
(To be clear, this is not a blocker!)
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.
One can always do const Primary: Story & {parameters: NovaEnvironmentDecoratorParameters<TypeMap>}
but I personally like satisfies part :)
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.
Absolutely amazing! 🤩
Really solid job, @sjwilczynski—thanks 👏
Co-authored-by: Eloy Durán <[email protected]>
…lczynski/nova-facade into user/stwilczy/novaDecorator
In scope of this PR we add a nova storybook decorator that should cover #17. The whole purpose of the decorator is to expose all the power of existing nova test utils (based on apollo-mock-client and mock-payload-generator) also inside storybook. For usage details check the README from nova/react-test-utils package.
Some important implementation considerations:
enableQueuedMockResolvers: false
mode, which doesn't generate any mocks by default but instantiates a nova environment for your component which you can get usinggetEnvForStory
insideplay
function and perform any actions you'd normally perform during unit testsenableQueuedMockResolvers: true
mode can be used to queue all resolvers up front, so that users can interact with the story live and also makes it simpler in case someone is interested in just resolving a single query/fragment. You can also pass custom resolvers usingresolvers
field which can be strongly typed withTypeMap
examples
folder, so that we can test our decorator on real components. In future the number of examples should increase, including leveraging decorator for fragment only based component, or components leveraging pagination/refetchable fragments, or subscriptions.nova-react-test-utils
. We landed on normal deps similarly how@apollo/client
to graphitation utilities are added. On clean repo depending on @storybook/addon-actions adds around ~500 lines in lock file, which is acceptable.TODO:
Closes #17