blessing-skin-server/resources/assets/tests/views/auth/Forgot.test.tsx
Zephyr Lykos 178664ed83
refactor: migrate toolchain, part 1
- Switched to pnpm
- Updated to typescript 4.9.5
- JSX transforms switched to react-jsx
- Use swc for typescript transforms
- Remove deprecated dependencies
- Cleanup unused types
- Some ESM fixes
- PostCSS config now lives in package.json
- Bump support target

TODO:
- switch to vite or plain esbuild
- jest to vitest / uvu
- jquery to cash-dom
- pure ESM (lodash-es, etc.)
- drop prettier & husky (lint-staged is okay)
- drop wasm cli & xterm.js
- update bootstrap
2023-07-10 19:58:18 +08:00

52 lines
1.5 KiB
TypeScript

import { render, waitFor, fireEvent } from '@testing-library/react'
import { t } from '@/scripts/i18n'
import * as fetch from '@/scripts/net'
import urls from '@/scripts/urls'
import Forgot from '@/views/auth/Forgot'
jest.mock('@/scripts/net')
describe('submit', () => {
it('succeeded', async () => {
fetch.post.mockResolvedValue({ code: 0, message: 'ok' })
const { getByPlaceholderText, getByText, queryByText } = render(<Forgot />)
fireEvent.input(getByPlaceholderText(t('auth.email')), {
target: { value: 'a@b.c' },
})
fireEvent.input(getByPlaceholderText(t('auth.captcha')), {
target: { value: 'abc' },
})
fireEvent.click(getByText(t('auth.send')))
await waitFor(() =>
expect(fetch.post).toBeCalledWith(urls.auth.forgot(), {
email: 'a@b.c',
captcha: 'abc',
}),
)
expect(queryByText('ok')).toBeInTheDocument()
})
it('failed', async () => {
fetch.post.mockResolvedValue({ code: 1, message: 'failed' })
const { getByPlaceholderText, getByText, queryByText } = render(<Forgot />)
fireEvent.input(getByPlaceholderText(t('auth.email')), {
target: { value: 'a@b.c' },
})
fireEvent.input(getByPlaceholderText(t('auth.captcha')), {
target: { value: 'abc' },
})
fireEvent.click(getByText(t('auth.send')))
await waitFor(() =>
expect(fetch.post).toBeCalledWith(urls.auth.forgot(), {
email: 'a@b.c',
captcha: 'abc',
}),
)
expect(queryByText('failed')).toBeInTheDocument()
})
})