1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
import { GlFormInput, GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import PasswordInput from '~/authentication/password/components/password_input.vue';
import { SHOW_PASSWORD, HIDE_PASSWORD } from '~/authentication/password/constants';
describe('PasswordInput', () => {
let wrapper;
const propsData = {
title: 'This field is required',
id: 'new_user_password',
minimumPasswordLength: '8',
qaSelector: 'new_user_password_field',
testid: 'new_user_password',
autocomplete: 'new-password',
name: 'new_user',
};
const findPasswordInput = () => wrapper.findComponent(GlFormInput);
const findToggleButton = () => wrapper.findComponent(GlButton);
const createComponent = () => {
return shallowMount(PasswordInput, {
propsData,
});
};
beforeEach(() => {
wrapper = createComponent();
});
it('sets password input attributes correctly', () => {
expect(findPasswordInput().attributes('id')).toBe(propsData.id);
expect(findPasswordInput().attributes('autocomplete')).toBe(propsData.autocomplete);
expect(findPasswordInput().attributes('name')).toBe(propsData.name);
expect(findPasswordInput().attributes('minlength')).toBe(propsData.minimumPasswordLength);
expect(findPasswordInput().attributes('data-qa-selector')).toBe(propsData.qaSelector);
expect(findPasswordInput().attributes('data-testid')).toBe(propsData.testid);
expect(findPasswordInput().attributes('title')).toBe(propsData.title);
});
describe('when the show password button is clicked', () => {
beforeEach(() => {
findToggleButton().vm.$emit('click');
});
it('displays hide password button', () => {
expect(findPasswordInput().attributes('type')).toBe('text');
expect(findToggleButton().attributes('icon')).toBe('eye-slash');
expect(findToggleButton().attributes('aria-label')).toBe(HIDE_PASSWORD);
});
describe('when the hide password button is clicked', () => {
beforeEach(() => {
findToggleButton().vm.$emit('click');
});
it('displays show password button', () => {
expect(findPasswordInput().attributes('type')).toBe('password');
expect(findToggleButton().attributes('icon')).toBe('eye');
expect(findToggleButton().attributes('aria-label')).toBe(SHOW_PASSWORD);
});
});
});
});
|