-
Notifications
You must be signed in to change notification settings - Fork 2.1k
@uppy/provider-views: add e2e tests for Server side search #6015
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
base: main
Are you sure you want to change the base?
Conversation
|
|
|
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 should avoid sprinkling arbitrary setTimeout values around the tests
|
|
||
| afterEach(async () => { | ||
| if (uppy) { | ||
| // Small delay to allow Preact cleanup hooks to complete |
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.
which hooks are you talking about here? adding delays to tests is generally a bad idea because we want tests to be a fast as possible, and delays cause race conditions and flaky tests. we should try to find another way like listening to the hooks complete event.
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 don’t remember the exact reason I added it, but it was definitely after some error that got resolved once I introduced a delay. However, I agree with your point , removed it now.
| await userEvent.type(searchInput, 'target') | ||
|
|
||
| // Wait for debounce (500ms) + network response | ||
| await new Promise((resolve) => setTimeout(resolve, 600)) |
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.
again, we should probably disable debouncing for tests. 600ms is a long time to wait for each tests, as it adds up. AFAIK vitest browser mode and playwright already waits for UI/network to settle when looking for things. you can see goldenRetriever.browser.test.ts how i use a special Symbol to make a non-public API that allows changing the debounce timeout
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.
added.
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.
this took more time than I expected , tbh I didn't want to rush it as I wanted to get a bit more comfortable with vitest.
|
|
||
| await expect | ||
| .element( | ||
| page.getByRole('checkbox', { name: 'deep-file.txt', exact: true }), |
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.
In Normal mode (ListItem.tsx), folders are rendered as buttons, whereas files are rendered as checkboxes with a corresponding <label>.
In Search mode (SearchListItem.tsx), both files and folders are rendered as buttons.
Because of this, in Normal mode, when checking whether a file exists, I need to use:
await expect.element(page.getByRole('button', { name:'nested-target.pdf', exact: true }))whereas, in Search mode, I need to scope the query to the checkbox role instead when searching for a file
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.
maybe add exactly that as a comment :)
| if (this.opts.supportsSearch) { | ||
| // Test hook: allow tests to disable debounce by setting a special Symbol on the class | ||
| const ctor = this.constructor as unknown as Record<symbol, unknown> | ||
| const testDebounceMs = ctor[Symbol.for('uppy test: searchDebounceMs')] as | ||
| | number | ||
| | undefined | ||
| if (testDebounceMs === 0) { | ||
| void this.#search() | ||
| } else { | ||
| this.#searchDebounced() | ||
| } | ||
| } |
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.
AI was used in this part, so please give it special attention.
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.
Do we really need this? This is quite specific code just for tests, which I'm not a fan enough. Can we work our way around this?
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.
Maybe it can instead be done like how i did in golden rettiever tests
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.
looks great now. you're a vitest e2e master now!
once the type tests are green then this lgtm
| afterEach(async () => { | ||
| if (!uppy) return | ||
|
|
||
| // this is done to prevent the edgecase when all plugins are removed before dashboard is unmounted from UI |
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.
This sounds like a bug we should fix in the uppy code(instead of working around it in the tests). If it's a crash that users can also hit when calling destroy(). but we can do that in a different issue
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.
yes will reproduce this and open a separate issue.
|
|
||
| await expect | ||
| .element( | ||
| page.getByRole('checkbox', { name: 'deep-file.txt', exact: true }), |
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.
maybe add exactly that as a comment :)
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 last comment, then good to go
| if (this.opts.supportsSearch) { | ||
| // Test hook: allow tests to disable debounce by setting a special Symbol on the class | ||
| const ctor = this.constructor as unknown as Record<symbol, unknown> | ||
| const testDebounceMs = ctor[Symbol.for('uppy test: searchDebounceMs')] as | ||
| | number | ||
| | undefined | ||
| if (testDebounceMs === 0) { | ||
| void this.#search() | ||
| } else { | ||
| this.#searchDebounced() | ||
| } | ||
| } |
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.
Do we really need this? This is quite specific code just for tests, which I'm not a fan enough. Can we work our way around this?
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 think we need to fix the type test, or else we will have it on main after merge, right?
packages/@uppy/provider-views/src/ProviderView/ProviderView.tsx
Outdated
Show resolved
Hide resolved
|
|
but we still need to fix it here on CI, no? |
Tests added as discussed in slack_discussion
directory structure mocked :
Some of the mocked responses in CompanionHandler.ts aren’t used in the tests, but I’ve kept them to preserve the legitimacy of the above directory structure.