-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/invite-event-handling
- Loading branch information
Showing
10 changed files
with
200 additions
and
98 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { act, renderHook } from '@testing-library/react' | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
||
import { useSelectProjectConfigFile } from './mutations/file-system' | ||
|
||
describe('useSelectProjectConfigFile', () => { | ||
beforeEach(() => { | ||
window.runtime = { | ||
getLocale: vi.fn().mockResolvedValue('en'), | ||
updateLocale: vi.fn(), | ||
selectFile: vi.fn(), | ||
} | ||
}) | ||
|
||
function createWrapper() { | ||
const queryClient = new QueryClient() | ||
return ({ children }: { children: React.ReactNode }) => ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
) | ||
} | ||
|
||
it('returns filename and filepath from window.runtime.selectFile', async () => { | ||
vi.spyOn(window.runtime, 'selectFile').mockResolvedValue({ | ||
name: 'myFile.comapeocat', | ||
path: '/Users/cindy/documents/myFile.comapeocat', | ||
}) | ||
|
||
const { result } = renderHook(() => useSelectProjectConfigFile(), { | ||
wrapper: createWrapper(), | ||
}) | ||
|
||
await act(async () => { | ||
const val = await result.current.mutateAsync(undefined) | ||
expect(val).toEqual({ | ||
name: 'myFile.comapeocat', | ||
path: '/Users/cindy/documents/myFile.comapeocat', | ||
}) | ||
}) | ||
}) | ||
|
||
it('returns undefined if user cancels', async () => { | ||
vi.spyOn(window.runtime, 'selectFile').mockResolvedValue(undefined) | ||
|
||
const { result } = renderHook(() => useSelectProjectConfigFile(), { | ||
wrapper: createWrapper(), | ||
}) | ||
|
||
await act(async () => { | ||
const val = await result.current.mutateAsync(undefined) | ||
expect(val).toBeUndefined() | ||
}) | ||
}) | ||
|
||
it('throws if the returned object has invalid shape', async () => { | ||
vi.spyOn(window.runtime, 'selectFile').mockRejectedValue( | ||
new Error('Value has invalid shape'), | ||
) | ||
|
||
const { result } = renderHook(() => useSelectProjectConfigFile(), { | ||
wrapper: createWrapper(), | ||
}) | ||
|
||
await expect( | ||
act(async () => { | ||
await result.current.mutateAsync() | ||
}), | ||
).rejects.toThrow('Value has invalid shape') | ||
}) | ||
}) |
Oops, something went wrong.