primevue-mirror/components/lib/password/Password.spec.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-09-14 11:26:01 +00:00
import { config, mount } from '@vue/test-utils';
2022-09-06 12:03:37 +00:00
import Password from './Password.vue';
2022-09-14 11:26:01 +00:00
config.global.mocks = {
$primevue: {
config: {
'z-index': 5,
inputStyle: 'filled',
ripple: false,
locale: {}
}
}
};
2022-12-08 11:04:25 +00:00
2022-09-06 12:03:37 +00:00
describe('Password.vue', () => {
let wrapper;
2022-09-14 11:26:01 +00:00
const event = { target: { value: 'P' } };
2022-09-06 12:03:37 +00:00
beforeEach(async () => {
wrapper = mount(Password, {
global: {
stubs: {
teleport: true
}
},
props: {
modelValue: null
}
});
await wrapper.vm.onFocus();
});
it('should exist', () => {
expect(wrapper.find('.p-password.p-component').exists()).toBe(true);
expect(wrapper.find('.p-password-panel').exists()).toBe(true);
});
it('should update modelValue', async () => {
await wrapper.vm.onInput(event);
expect(wrapper.emitted()['update:modelValue'][0]).toEqual(['P']);
});
it('should meter update', async () => {
2022-09-14 11:26:01 +00:00
expect(wrapper.find('.p-password-info').text()).toBe('');
2022-09-06 12:03:37 +00:00
await wrapper.vm.onKeyUp(event);
2022-09-14 11:26:01 +00:00
expect(wrapper.find('.p-password-info').text()).toBe('');
2022-09-06 12:03:37 +00:00
expect(wrapper.find('.p-password-strength').classes()).toContain('weak');
});
it('should toggle mask', async () => {
await wrapper.setProps({ toggleMask: true });
expect(wrapper.find('.pi.pi-eye').exists()).toBe(true);
await wrapper.vm.onMaskToggle();
expect(wrapper.find('.pi.pi-eye').exists()).toBe(false);
expect(wrapper.find('.pi.pi-eye-slash').exists()).toBe(true);
});
2022-09-14 11:26:01 +00:00
});