Skip to content
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

Merged
merged 5 commits into from
Dec 1, 2023

Conversation

eunjae-lee
Copy link
Contributor

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)

@eunjae-lee eunjae-lee marked this pull request as draft October 30, 2023 15:18
@vercel
Copy link

vercel bot commented Oct 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plugin-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 1, 2023 9:17am

@eunjae-lee eunjae-lee changed the base branch from main to chore/dev-vite-configs October 30, 2023 15:24
@eunjae-lee eunjae-lee force-pushed the EXT-2048-test-helper-for-field-plugin branch from bdbd2cb to 47fe2cd Compare October 30, 2023 15:24
@eunjae-lee
Copy link
Contributor Author

eunjae-lee commented Oct 30, 2023

spaceId: undefined,
storyLang: '',

const fakeContainer = (listener) => {
Copy link
Contributor Author

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).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about 'mockContainer' ?

Base automatically changed from chore/dev-vite-configs to main October 31, 2023 09:27
@eunjae-lee eunjae-lee force-pushed the EXT-2048-test-helper-for-field-plugin branch from 47fe2cd to 26b3cf9 Compare October 31, 2023 09:30
messageCallback({ data })
}
const container = fakeContainer(listener)
global.ResizeObserver = class ResizeObserver {
Copy link
Contributor

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,
}),
Copy link
Contributor

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;
          }

@BibiSebi
Copy link
Contributor

BibiSebi commented Nov 2, 2023

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 💯

@eunjae-lee eunjae-lee force-pushed the EXT-2048-test-helper-for-field-plugin branch from 4bbec28 to 92ee8ad Compare November 30, 2023 14:06
@eunjae-lee eunjae-lee changed the title fix(template): PoC - test helper feat(common): add test helper Nov 30, 2023
@eunjae-lee eunjae-lee marked this pull request as ready for review November 30, 2023 15:21
* clean up test helper WIP

* improve types

* update snapshot
@eunjae-lee eunjae-lee merged commit 7d2f396 into main Dec 1, 2023
@eunjae-lee eunjae-lee deleted the EXT-2048-test-helper-for-field-plugin branch December 1, 2023 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants