25 lines
1.1 KiB
TypeScript
25 lines
1.1 KiB
TypeScript
import { renderToStaticMarkup } from 'react-dom/server'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { PasswordInput } from './PasswordInput'
|
|
|
|
describe('PasswordInput', () => {
|
|
it('masks the field by default and offers a visibility toggle', () => {
|
|
const markup = renderToStaticMarkup(<PasswordInput value="secret" autoComplete="current-password" onChange={() => undefined} />)
|
|
expect(markup).toContain('type="password"')
|
|
expect(markup).toContain('显示密码')
|
|
expect(markup).toContain('aria-pressed="false"')
|
|
})
|
|
|
|
it('renders revealed when initiallyRevealed is set', () => {
|
|
const markup = renderToStaticMarkup(<PasswordInput value="secret" autoComplete="off" initiallyRevealed onChange={() => undefined} />)
|
|
expect(markup).toContain('type="text"')
|
|
expect(markup).toContain('隐藏密码')
|
|
expect(markup).toContain('aria-pressed="true"')
|
|
})
|
|
|
|
it('toggle is a plain button so it never submits the form', () => {
|
|
const markup = renderToStaticMarkup(<PasswordInput value="secret" autoComplete="off" onChange={() => undefined} />)
|
|
expect(markup).toContain('type="button"')
|
|
})
|
|
})
|