2023-01-29 04:58:06 +01:00
|
|
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
2022-11-16 00:14:59 +01:00
|
|
|
import Vcard from '.'
|
|
|
|
|
2024-02-05 16:16:18 +01:00
|
|
|
jest.mock('./imageToDataUrl', () => ({
|
|
|
|
__esModule: true,
|
|
|
|
imageToDataUrl: jest.fn().mockResolvedValue('data:image/png;base64,')
|
|
|
|
}))
|
|
|
|
|
2022-11-16 00:14:59 +01:00
|
|
|
describe('Vcard', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
global.URL.createObjectURL = jest.fn()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders correctly', () => {
|
|
|
|
const { container } = render(<Vcard />)
|
|
|
|
expect(container.firstChild).toBeInTheDocument()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Button click starts download', async () => {
|
|
|
|
render(<Vcard />)
|
|
|
|
const button = await screen.findByText('Add to addressbook')
|
|
|
|
fireEvent.click(button)
|
|
|
|
await waitFor(() => global.URL.createObjectURL)
|
|
|
|
// expect(global.URL.createObjectURL).toHaveBeenCalledTimes(1)
|
|
|
|
})
|
|
|
|
})
|