-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reset expanded directories list on category change (#11725)
Partially closes: cloud-v2/1592 Closes: enso-org/cloud-v2#1606 This PR also adds needed configuration for unit tests and adjust it to run using vscode vite extension
- Loading branch information
1 parent
2894618
commit 1676545
Showing
19 changed files
with
324 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/gui/src/dashboard/providers/__test__/DriveProvider.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { Category } from '#/layouts/CategorySwitcher/Category' | ||
import { act, renderHook, type RenderHookOptions, type RenderHookResult } from '#/test' | ||
import { describe, expect, it } from 'vitest' | ||
import { useStore } from 'zustand' | ||
import { DirectoryId } from '../../services/Backend' | ||
import DriveProvider, { useDriveStore } from '../DriveProvider' | ||
|
||
function renderDriveProviderHook<Result, Props>( | ||
hook: (props: Props) => Result, | ||
options?: Omit<RenderHookOptions<Props>, 'wrapper'>, | ||
): RenderHookResult<Result, Props> { | ||
return renderHook(hook, { wrapper: DriveProvider, ...options }) | ||
} | ||
|
||
describe('<DriveProvider />', () => { | ||
it('Should reset expanded directory ids when category changes', () => { | ||
const driveAPI = renderDriveProviderHook(() => { | ||
const store = useDriveStore() | ||
return useStore(store, ({ setCategory, setExpandedDirectoryIds, expandedDirectoryIds }) => ({ | ||
expandedDirectoryIds, | ||
setCategory, | ||
setExpandedDirectoryIds, | ||
})) | ||
}) | ||
|
||
act(() => { | ||
driveAPI.result.current.setExpandedDirectoryIds([DirectoryId('test-123')]) | ||
}) | ||
|
||
expect(driveAPI.result.current.expandedDirectoryIds).toEqual([DirectoryId('test-123')]) | ||
|
||
act(() => { | ||
driveAPI.result.current.setCategory({} as Category) | ||
}) | ||
|
||
expect(driveAPI.result.current.expandedDirectoryIds).toEqual([]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* @file | ||
* | ||
* Barrel files for utility renderes | ||
*/ | ||
|
||
export * from './testUtils' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @file Global setup for dashboard tests. | ||
*/ | ||
|
||
import * as matchers from '@testing-library/jest-dom/matchers' | ||
import { cleanup } from '@testing-library/react' | ||
import { MotionGlobalConfig } from 'framer-motion' | ||
import { afterEach, expect } from 'vitest' | ||
|
||
MotionGlobalConfig.skipAnimations = true | ||
|
||
expect.extend(matchers) | ||
|
||
afterEach(() => { | ||
cleanup() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** | ||
* @file Utility functions for testing. | ||
* | ||
* **IMPORTANT**: This file is supposed to be used instead of `@testing-library/react` | ||
* It is used to provide a portal root and locale to all tests. | ||
*/ | ||
|
||
import { Form, type FormProps, type TSchema } from '#/components/AriaComponents' | ||
import UIProviders from '#/components/UIProviders' | ||
import { | ||
render, | ||
renderHook, | ||
type RenderHookOptions, | ||
type RenderHookResult, | ||
type RenderOptions, | ||
type RenderResult, | ||
} from '@testing-library/react' | ||
import { type PropsWithChildren, type ReactElement } from 'react' | ||
|
||
/** | ||
* A wrapper that passes through its children. | ||
*/ | ||
function PassThroughWrapper({ children }: PropsWithChildren) { | ||
return children | ||
} | ||
|
||
/** | ||
* A wrapper that provides the {@link UIProviders} context. | ||
*/ | ||
function UIProvidersWrapper({ children }: PropsWithChildren) { | ||
return ( | ||
<UIProviders portalRoot={document.body} locale="en"> | ||
{children} | ||
</UIProviders> | ||
) | ||
} | ||
|
||
/** | ||
* A wrapper that provides the {@link Form} context. | ||
*/ | ||
function FormWrapper<Schema extends TSchema, SubmitResult = void>( | ||
props: FormProps<Schema, SubmitResult>, | ||
) { | ||
return <Form {...props} /> | ||
} | ||
|
||
/** | ||
* Custom render function for tests. | ||
*/ | ||
function renderWithRoot(ui: ReactElement, options?: Omit<RenderOptions, 'queries'>): RenderResult { | ||
const { wrapper: Wrapper = PassThroughWrapper, ...rest } = options ?? {} | ||
|
||
return render(ui, { | ||
wrapper: ({ children }) => ( | ||
<UIProvidersWrapper> | ||
<Wrapper>{children}</Wrapper> | ||
</UIProvidersWrapper> | ||
), | ||
...rest, | ||
}) | ||
} | ||
|
||
/** | ||
* Adds a form wrapper to the component. | ||
*/ | ||
function renderWithForm<Schema extends TSchema, SubmitResult = void>( | ||
ui: ReactElement, | ||
options: Omit<RenderOptions, 'queries' | 'wrapper'> & { | ||
formProps: FormProps<Schema, SubmitResult> | ||
}, | ||
): RenderResult { | ||
const { formProps, ...rest } = options | ||
|
||
return renderWithRoot(ui, { | ||
wrapper: ({ children }) => <FormWrapper {...formProps}>{children}</FormWrapper>, | ||
...rest, | ||
}) | ||
} | ||
|
||
/** | ||
* A custom renderHook function for tests. | ||
*/ | ||
function renderHookWithRoot<Result, Props>( | ||
hook: (props: Props) => Result, | ||
options?: Omit<RenderHookOptions<Props>, 'queries'>, | ||
): RenderHookResult<Result, Props> { | ||
return renderHook(hook, { wrapper: UIProvidersWrapper, ...options }) | ||
} | ||
|
||
/** | ||
* A custom renderHook function for tests that provides the {@link Form} context. | ||
*/ | ||
function renderHookWithForm<Result, Props, Schema extends TSchema, SubmitResult = void>( | ||
hook: (props: Props) => Result, | ||
options: Omit<RenderHookOptions<Props>, 'queries' | 'wrapper'> & { | ||
formProps: FormProps<Schema, SubmitResult> | ||
}, | ||
): RenderHookResult<Result, Props> { | ||
const { formProps, ...rest } = options | ||
|
||
return renderHookWithRoot(hook, { | ||
wrapper: ({ children }) => <FormWrapper {...formProps}>{children}</FormWrapper>, | ||
...rest, | ||
}) | ||
} | ||
|
||
export * from '@testing-library/react' | ||
export { default as userEvent } from '@testing-library/user-event' | ||
// override render method | ||
export { | ||
renderWithRoot as render, | ||
renderHookWithRoot as renderHook, | ||
renderHookWithForm, | ||
renderWithForm, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.