You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
2.0 KiB
45 lines
2.0 KiB
import { describe, it, expect } from 'vitest'
|
|
import { mount } from '@vue/test-utils'
|
|
import PasswordStrength from '../PasswordStrength.vue'
|
|
|
|
describe('PasswordStrength', () => {
|
|
it('renders nothing for empty password', () => {
|
|
const wrapper = mount(PasswordStrength, { props: { password: '' } })
|
|
expect(wrapper.find('[data-testid="strength-bar"]').exists()).toBe(false)
|
|
})
|
|
|
|
it('score 1 for weak password (only letters, < 8)', () => {
|
|
const wrapper = mount(PasswordStrength, { props: { password: 'abc' } })
|
|
expect(wrapper.find('[data-testid="strength-bar"]').attributes('data-score')).toBe('1')
|
|
expect(wrapper.text()).toContain('弱')
|
|
})
|
|
|
|
it('score 1 for only digits', () => {
|
|
const wrapper = mount(PasswordStrength, { props: { password: '1234567' } })
|
|
expect(wrapper.find('[data-testid="strength-bar"]').attributes('data-score')).toBe('1')
|
|
})
|
|
|
|
it('score 2 for letters+digits >= 8 chars', () => {
|
|
const wrapper = mount(PasswordStrength, { props: { password: 'abc12345' } })
|
|
expect(wrapper.find('[data-testid="strength-bar"]').attributes('data-score')).toBe('2')
|
|
expect(wrapper.text()).toContain('中')
|
|
})
|
|
|
|
it('score 2 for uppercase letters+digits >= 8 chars', () => {
|
|
const wrapper = mount(PasswordStrength, { props: { password: 'ABC12345' } })
|
|
expect(wrapper.find('[data-testid="strength-bar"]').attributes('data-score')).toBe('2')
|
|
expect(wrapper.text()).toContain('中')
|
|
})
|
|
|
|
it('score 3 for upper+lower+digits >= 10 chars', () => {
|
|
const wrapper = mount(PasswordStrength, { props: { password: 'Abcdef1234' } })
|
|
expect(wrapper.find('[data-testid="strength-bar"]').attributes('data-score')).toBe('3')
|
|
expect(wrapper.text()).toContain('强')
|
|
})
|
|
|
|
it('score 4 for upper+lower+digits+special >= 12 chars', () => {
|
|
const wrapper = mount(PasswordStrength, { props: { password: 'Abcdef1234!@' } })
|
|
expect(wrapper.find('[data-testid="strength-bar"]').attributes('data-score')).toBe('4')
|
|
expect(wrapper.text()).toContain('很强')
|
|
})
|
|
})
|
|
|