-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
- Loading branch information
1 parent
c6d51d2
commit a3649e6
Showing
3 changed files
with
85 additions
and
44 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
48 changes: 48 additions & 0 deletions
48
packages/rmf-dashboard-framework/src/components/tasks/tasks-window.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,48 @@ | ||
import { fireEvent, screen } from '@testing-library/react'; | ||
import React, { act } from 'react'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { RmfApiProvider } from '../../hooks'; | ||
import { MockRmfApi, render, TestProviders } from '../../utils/test-utils.test'; | ||
import { AppEvents } from '../app-events'; | ||
import { TasksWindow } from './tasks-window'; | ||
|
||
vi.mock('../app-events', () => ({ | ||
AppEvents: { | ||
refreshTaskApp: { | ||
subscribe: vi.fn(() => ({ unsubscribe: vi.fn() })), | ||
next: vi.fn(), | ||
}, | ||
}, | ||
})); | ||
|
||
describe('Tasks window', () => { | ||
const rmfApi = new MockRmfApi(); | ||
rmfApi.tasksApi.queryTaskStatesTasksGet = vi.fn().mockResolvedValue({ data: [] }); | ||
|
||
const Base = (props: React.PropsWithChildren<{}>) => { | ||
return ( | ||
<TestProviders> | ||
<RmfApiProvider value={rmfApi}>{props.children}</RmfApiProvider> | ||
</TestProviders> | ||
); | ||
}; | ||
|
||
it('renders without crashing', () => { | ||
const root = render( | ||
<Base> | ||
<TasksWindow /> | ||
</Base>, | ||
); | ||
expect(root.getByText('Tasks')).toBeTruthy(); | ||
}); | ||
|
||
it('triggers task refresh when Refresh button is clicked', () => { | ||
render(<TasksWindow onClose={() => {}} />); | ||
const refreshButton = screen.getByTestId('refresh-button'); | ||
act(() => { | ||
fireEvent.click(refreshButton); | ||
}); | ||
expect(AppEvents.refreshTaskApp.next).toHaveBeenCalled(); | ||
}); | ||
}); |
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