-
Notifications
You must be signed in to change notification settings - Fork 131
4284 client - Fix component filter flicker and add loading spinner #4285
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
115 changes: 115 additions & 0 deletions
115
...nt/src/pages/platform/workflow-editor/hooks/tests/useFilteredComponentDefinitions.test.ts
This file contains hidden or 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 @@ | ||
| import {act, renderHook} from '@testing-library/react'; | ||
| import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'; | ||
|
|
||
| const hoisted = vi.hoisted(() => { | ||
| const mockQueryResult = { | ||
| data: null as Array<{actionsCount: number; name: string; triggersCount: number; version: number}> | null, | ||
| isFetching: false, | ||
| }; | ||
|
|
||
| return {mockQueryResult}; | ||
| }); | ||
|
|
||
| vi.mock('use-debounce', () => ({ | ||
| useDebounce: (value: string) => [value], | ||
| })); | ||
|
|
||
| vi.mock('@/shared/queries/platform/componentDefinitionsGraphQL.queries', () => ({ | ||
| useGetComponentDefinitionsWithActionsQuery: () => hoisted.mockQueryResult, | ||
| })); | ||
|
|
||
| const componentDefinitions = [ | ||
| {actionsCount: 3, name: 'gmail', triggersCount: 1, version: 1}, | ||
| {actionsCount: 2, name: 'slack', triggersCount: 0, version: 1}, | ||
| {actionsCount: 1, name: 'github', triggersCount: 2, version: 1}, | ||
| ]; | ||
|
|
||
| describe('useFilteredComponentDefinitions', () => { | ||
| beforeEach(() => { | ||
| hoisted.mockQueryResult.data = null; | ||
| hoisted.mockQueryResult.isFetching = false; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should return original componentDefinitions when filter is empty', async () => { | ||
| const {useFilteredComponentDefinitions} = await import('../useFilteredComponentDefinitions'); | ||
|
|
||
| const {result} = renderHook(() => useFilteredComponentDefinitions(componentDefinitions)); | ||
|
|
||
| expect(result.current.componentsWithActions).toBe(componentDefinitions); | ||
| expect(result.current.filter).toBe(''); | ||
| expect(result.current.isSearchFetching).toBe(false); | ||
| }); | ||
|
|
||
| it('should return search results when filter is set and data is available', async () => { | ||
| const searchResults = [{actionsCount: 3, name: 'gmail', triggersCount: 1, version: 1}]; | ||
|
|
||
| hoisted.mockQueryResult.data = searchResults; | ||
| hoisted.mockQueryResult.isFetching = false; | ||
|
|
||
| const {useFilteredComponentDefinitions} = await import('../useFilteredComponentDefinitions'); | ||
|
|
||
| const {result} = renderHook(() => useFilteredComponentDefinitions(componentDefinitions)); | ||
|
|
||
| act(() => { | ||
| result.current.setFilter('gmail'); | ||
| }); | ||
|
|
||
| expect(result.current.componentsWithActions).toBe(searchResults); | ||
| }); | ||
|
|
||
| it('should return isSearchFetching as true when query is in flight', async () => { | ||
| hoisted.mockQueryResult.isFetching = true; | ||
|
|
||
| const {useFilteredComponentDefinitions} = await import('../useFilteredComponentDefinitions'); | ||
|
|
||
| const {result} = renderHook(() => useFilteredComponentDefinitions(componentDefinitions)); | ||
|
|
||
| expect(result.current.isSearchFetching).toBe(true); | ||
| }); | ||
|
|
||
| it('should return previous search results while fetching new ones (keepPreviousData)', async () => { | ||
| const previousResults = [{actionsCount: 3, name: 'gmail', triggersCount: 1, version: 1}]; | ||
|
|
||
| hoisted.mockQueryResult.data = previousResults; | ||
| hoisted.mockQueryResult.isFetching = true; | ||
|
|
||
| const {useFilteredComponentDefinitions} = await import('../useFilteredComponentDefinitions'); | ||
|
|
||
| const {result} = renderHook(() => useFilteredComponentDefinitions(componentDefinitions)); | ||
|
|
||
| act(() => { | ||
| result.current.setFilter('gma'); | ||
| }); | ||
|
|
||
| expect(result.current.componentsWithActions).toBe(previousResults); | ||
| expect(result.current.isSearchFetching).toBe(true); | ||
| }); | ||
|
|
||
| it('should return original componentDefinitions when filter is whitespace only', async () => { | ||
| const {useFilteredComponentDefinitions} = await import('../useFilteredComponentDefinitions'); | ||
|
|
||
| const {result} = renderHook(() => useFilteredComponentDefinitions(componentDefinitions)); | ||
|
|
||
| act(() => { | ||
| result.current.setFilter(' '); | ||
| }); | ||
|
|
||
| expect(result.current.componentsWithActions).toBe(componentDefinitions); | ||
| }); | ||
|
|
||
| it('should expose trimmedFilter as debounced and trimmed value', async () => { | ||
| const {useFilteredComponentDefinitions} = await import('../useFilteredComponentDefinitions'); | ||
|
|
||
| const {result} = renderHook(() => useFilteredComponentDefinitions(componentDefinitions)); | ||
|
|
||
| act(() => { | ||
| result.current.setFilter(' gmail '); | ||
| }); | ||
|
|
||
| expect(result.current.trimmedFilter).toBe('gmail'); | ||
| }); | ||
| }); |
This file contains hidden or 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
92 changes: 92 additions & 0 deletions
92
...t/src/pages/platform/workflow-editor/tests/WorkflowNodesPopoverMenuComponentList.test.tsx
This file contains hidden or 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,92 @@ | ||
| import {render, resetAll, screen, windowResizeObserver} from '@/shared/util/test-utils'; | ||
| import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'; | ||
|
|
||
| const hoisted = vi.hoisted(() => ({ | ||
| mockFilterResult: { | ||
| componentsWithActions: [ | ||
| {actionsCount: 3, name: 'gmail', triggersCount: 1, version: 1}, | ||
| {actionsCount: 2, name: 'slack', triggersCount: 0, version: 1}, | ||
| ], | ||
| filter: '', | ||
| isSearchFetching: false, | ||
| setFilter: vi.fn(), | ||
| trimmedFilter: '', | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock('../hooks/useFilteredComponentDefinitions', () => ({ | ||
| useFilteredComponentDefinitions: () => hoisted.mockFilterResult, | ||
| })); | ||
|
|
||
| vi.mock('../stores/useWorkflowDataStore', () => ({ | ||
| default: Object.assign( | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| (selector: any) => | ||
| selector({ | ||
| componentDefinitions: [ | ||
| {actionsCount: 3, name: 'gmail', triggersCount: 1, version: 1}, | ||
| {actionsCount: 2, name: 'slack', triggersCount: 0, version: 1}, | ||
| ], | ||
| nodes: [], | ||
| taskDispatcherDefinitions: [], | ||
| }), | ||
| {getState: vi.fn()} | ||
| ), | ||
| })); | ||
|
|
||
| vi.mock('@/shared/stores/useFeatureFlagsStore', () => ({ | ||
| useFeatureFlagsStore: () => () => false, | ||
| })); | ||
|
|
||
| vi.mock('@/shared/stores/useApplicationInfoStore', () => ({ | ||
| useApplicationInfoStore: () => false, | ||
| })); | ||
|
|
||
| vi.mock('../components/workflow-nodes-tabs/WorkflowNodesTabs', () => ({ | ||
| default: () => <div data-testid="workflow-nodes-tabs">Tabs</div>, | ||
| })); | ||
|
|
||
| describe('WorkflowNodesPopoverMenuComponentList', () => { | ||
| beforeEach(() => { | ||
| windowResizeObserver(); | ||
|
|
||
| hoisted.mockFilterResult.isSearchFetching = false; | ||
| hoisted.mockFilterResult.filter = ''; | ||
| hoisted.mockFilterResult.trimmedFilter = ''; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| resetAll(); | ||
| }); | ||
|
|
||
| it('should render filter input', async () => { | ||
| const {default: WorkflowNodesPopoverMenuComponentList} = | ||
| await import('../components/WorkflowNodesPopoverMenuComponentList'); | ||
|
|
||
| render(<WorkflowNodesPopoverMenuComponentList actionPanelOpen={false} />); | ||
|
|
||
| expect(screen.getByPlaceholderText('Filter components')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should show loading spinner when search is fetching', async () => { | ||
| hoisted.mockFilterResult.isSearchFetching = true; | ||
|
|
||
| const {default: WorkflowNodesPopoverMenuComponentList} = | ||
| await import('../components/WorkflowNodesPopoverMenuComponentList'); | ||
|
|
||
| render(<WorkflowNodesPopoverMenuComponentList actionPanelOpen={false} />); | ||
|
|
||
| expect(screen.getByRole('status')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should not show loading spinner when search is not fetching', async () => { | ||
| hoisted.mockFilterResult.isSearchFetching = false; | ||
|
|
||
| const {default: WorkflowNodesPopoverMenuComponentList} = | ||
| await import('../components/WorkflowNodesPopoverMenuComponentList'); | ||
|
|
||
| render(<WorkflowNodesPopoverMenuComponentList actionPanelOpen={false} />); | ||
|
|
||
| expect(screen.queryByRole('status')).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.