mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
test(source): linkItem() tested (#211)
* linkItem() tested * set line coverage to 1
This commit is contained in:
parent
edb0172a8e
commit
e68ca0817a
44
src/Components/Profile/ItemFunctions.spec.tsx
Normal file
44
src/Components/Profile/ItemFunctions.spec.tsx
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { describe, it, expect, vi } from 'vitest'
|
||||||
|
|
||||||
|
import { linkItem } from './itemFunctions'
|
||||||
|
|
||||||
|
const toastErrorMock: (t: string) => void = vi.fn()
|
||||||
|
const toastSuccessMock: (t: string) => void = vi.fn()
|
||||||
|
|
||||||
|
vi.mock('react-toastify', () => ({
|
||||||
|
toast: {
|
||||||
|
error: (t: string) => toastErrorMock(t),
|
||||||
|
success: (t: string) => toastSuccessMock(t),
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
describe('linkItem', () => {
|
||||||
|
const id = 'some-id'
|
||||||
|
let updateApi: () => void = vi.fn()
|
||||||
|
const item = { layer: { api: { updateItem: () => updateApi() } } }
|
||||||
|
const updateItem = vi.fn()
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
updateApi = vi.fn()
|
||||||
|
vi.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('api rejects', () => {
|
||||||
|
it('toasts an error', async () => {
|
||||||
|
updateApi = vi.fn().mockRejectedValue('autsch')
|
||||||
|
await linkItem(id, item, updateItem)
|
||||||
|
expect(toastErrorMock).toHaveBeenCalledWith('autsch')
|
||||||
|
expect(updateItem).not.toHaveBeenCalled()
|
||||||
|
expect(toastSuccessMock).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('api resolves', () => {
|
||||||
|
it('toasts success and calls updateItem()', async () => {
|
||||||
|
await linkItem(id, item, updateItem)
|
||||||
|
expect(toastErrorMock).not.toHaveBeenCalled()
|
||||||
|
expect(updateItem).toHaveBeenCalledTimes(1)
|
||||||
|
expect(toastSuccessMock).toHaveBeenCalledWith('Item linked')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -16,9 +16,6 @@ export default defineConfig({
|
|||||||
reporter: ['html', 'json-summary'],
|
reporter: ['html', 'json-summary'],
|
||||||
thresholds: {
|
thresholds: {
|
||||||
lines: 1,
|
lines: 1,
|
||||||
functions: 56,
|
|
||||||
branches: 58,
|
|
||||||
statements: 1,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user