blessing-skin-server/resources/assets/tests/views/widgets/EmailVerification.test.tsx
2020-03-28 12:18:52 +08:00

37 lines
1.3 KiB
TypeScript

import React from 'react'
import { render, fireEvent, waitFor } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import EmailVerification from '@/views/widgets/EmailVerification'
jest.mock('@/scripts/net')
describe('send email', () => {
it('succeeded', async () => {
fetch.post.mockResolvedValue({ code: 0, message: 'success' })
const { getByText, getByRole, queryByText } = render(<EmailVerification />)
fireEvent.click(getByText(t('user.verification.resend')))
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/email-verification'),
)
expect(queryByText('success')).toBeInTheDocument()
expect(getByRole('status')).toHaveClass('alert-success')
})
it('failed', async () => {
fetch.post.mockResolvedValue({ code: 1, message: 'failed' })
const { getByText, getByRole, queryByText } = render(<EmailVerification />)
fireEvent.click(getByText(t('user.verification.resend')))
await waitFor(() =>
expect(fetch.post).toBeCalledWith('/user/email-verification'),
)
expect(fetch.post).toBeCalledWith('/user/email-verification')
expect(queryByText('failed')).toBeInTheDocument()
expect(getByRole('alert')).toHaveClass('alert-danger')
})
})