-
Notifications
You must be signed in to change notification settings - Fork 3
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(common): add test helper #307
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
bdbd2cb
to
47fe2cd
Compare
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
spaceId: undefined, | ||
storyLang: '', | ||
|
||
const fakeContainer = (listener) => { |
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.
It's not properly typed, and we should revisit all the namings. Once we improve this, we could possibly reuse this logic back into the Container. (the basic implementation of receiving what event and sending what event are the same).
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.
what about 'mockContainer' ?
47fe2cd
to
26b3cf9
Compare
packages/cli/templates/react/src/components/FieldPluginExample/index.spec.tsx
Outdated
Show resolved
Hide resolved
messageCallback({ data }) | ||
} | ||
const container = fakeContainer(listener) | ||
global.ResizeObserver = class ResizeObserver { |
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 could extract the observer mocking in a separate method, to shorten the setup function a bit.
stateMessage({ | ||
action: 'loaded', | ||
callbackId: data.callbackId, | ||
}), |
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.
instead of if --> if else --> if else ..... I think early exit of the function could make this logic a bit more readable.
if (isPluginLoadedMessage(data)) {
listener(
stateMessage({
action: 'loaded',
callbackId: data.callbackId,
}),
return;
}
if(isValueChangeMessage(data)){
....
return;
}
Great job @eunjae-lee. I like how you approached this problem 👍 I left some minor comments on code readability, even though this is just a draft PR and I am sure you would cover them anyway 💯 |
26b3cf9
to
37406c9
Compare
0368d2d
to
7f7df22
Compare
7f7df22
to
4bbec28
Compare
4bbec28
to
92ee8ad
Compare
* clean up test helper WIP * improve types * update snapshot
What?
This PR is a proof of concept for the test helper.
Why?
JIRA: EXT-2048
After creating a field plugin, users need a way to test their field plugins. Currently the field plugin is meant to be used with a container (Field Type Editor, Visual Editor, or the Sandbox). This makes it harder to write integration tests to test the components. So this proof of concept shows how to mock necessary parts of
window
, so that the field plugin can run with a fake (memory) container, which enables testing.How to test? (optional)