@coreui/vue-pro 5.16.0 → 5.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/components/autocomplete/CAutocomplete.js +17 -16
- package/dist/cjs/components/autocomplete/CAutocomplete.js.map +1 -1
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.js +4 -0
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/components/one-time-password-input/COneTimePassword.d.ts +278 -0
- package/dist/cjs/components/one-time-password-input/COneTimePassword.js +393 -0
- package/dist/cjs/components/one-time-password-input/COneTimePassword.js.map +1 -0
- package/dist/cjs/components/one-time-password-input/COneTimePasswordInput.d.ts +4 -0
- package/dist/cjs/components/one-time-password-input/COneTimePasswordInput.js +19 -0
- package/dist/cjs/components/one-time-password-input/COneTimePasswordInput.js.map +1 -0
- package/dist/cjs/components/one-time-password-input/index.d.ts +3 -0
- package/dist/cjs/components/one-time-password-input/utils.d.ts +2 -0
- package/dist/cjs/components/one-time-password-input/utils.js +18 -0
- package/dist/cjs/components/one-time-password-input/utils.js.map +1 -0
- package/dist/cjs/components/stepper/CStepper.d.ts +1 -1
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/autocomplete/CAutocomplete.js +17 -16
- package/dist/esm/components/autocomplete/CAutocomplete.js.map +1 -1
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/components/one-time-password-input/COneTimePassword.d.ts +278 -0
- package/dist/esm/components/one-time-password-input/COneTimePassword.js +391 -0
- package/dist/esm/components/one-time-password-input/COneTimePassword.js.map +1 -0
- package/dist/esm/components/one-time-password-input/COneTimePasswordInput.d.ts +4 -0
- package/dist/esm/components/one-time-password-input/COneTimePasswordInput.js +17 -0
- package/dist/esm/components/one-time-password-input/COneTimePasswordInput.js.map +1 -0
- package/dist/esm/components/one-time-password-input/index.d.ts +3 -0
- package/dist/esm/components/one-time-password-input/utils.d.ts +2 -0
- package/dist/esm/components/one-time-password-input/utils.js +15 -0
- package/dist/esm/components/one-time-password-input/utils.js.map +1 -0
- package/dist/esm/components/stepper/CStepper.d.ts +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +6 -6
- package/src/components/autocomplete/CAutocomplete.ts +17 -16
- package/src/components/index.ts +1 -0
- package/src/components/one-time-password-input/COneTimePassword.ts +459 -0
- package/src/components/one-time-password-input/COneTimePasswordInput.ts +21 -0
- package/src/components/one-time-password-input/__tests__/COneTimePassword.spec.ts +210 -0
- package/src/components/one-time-password-input/__tests__/__snapshots__/COneTimePassword.spec.ts.snap +32 -0
- package/src/components/one-time-password-input/index.ts +4 -0
- package/src/components/one-time-password-input/utils.ts +13 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils'
|
|
2
|
+
import { COneTimePassword as Component, COneTimePasswordInput } from '../../../index'
|
|
3
|
+
|
|
4
|
+
const ComponentName = 'COneTimePassword'
|
|
5
|
+
|
|
6
|
+
const defaultWrapper = mount(Component, {
|
|
7
|
+
propsData: {},
|
|
8
|
+
slots: {
|
|
9
|
+
default: [
|
|
10
|
+
'<COneTimePasswordInput />',
|
|
11
|
+
'<COneTimePasswordInput />',
|
|
12
|
+
'<COneTimePasswordInput />',
|
|
13
|
+
'<COneTimePasswordInput />',
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const customWrapper = mount(Component, {
|
|
19
|
+
propsData: {
|
|
20
|
+
disabled: true,
|
|
21
|
+
readonly: true,
|
|
22
|
+
invalid: true,
|
|
23
|
+
size: 'lg',
|
|
24
|
+
type: 'text',
|
|
25
|
+
placeholder: '•',
|
|
26
|
+
masked: true,
|
|
27
|
+
},
|
|
28
|
+
slots: {
|
|
29
|
+
default: [
|
|
30
|
+
'<COneTimePasswordInput />',
|
|
31
|
+
'<COneTimePasswordInput />',
|
|
32
|
+
'<COneTimePasswordInput />',
|
|
33
|
+
'<COneTimePasswordInput />',
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const withValueWrapper = mount(Component, {
|
|
39
|
+
propsData: {
|
|
40
|
+
defaultValue: '1234',
|
|
41
|
+
},
|
|
42
|
+
slots: {
|
|
43
|
+
default: [
|
|
44
|
+
'<COneTimePasswordInput />',
|
|
45
|
+
'<COneTimePasswordInput />',
|
|
46
|
+
'<COneTimePasswordInput />',
|
|
47
|
+
'<COneTimePasswordInput />',
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe(`Loads and display ${ComponentName} component`, () => {
|
|
53
|
+
it('has a name', () => {
|
|
54
|
+
expect(Component.name).toMatch(ComponentName)
|
|
55
|
+
})
|
|
56
|
+
it('renders correctly', () => {
|
|
57
|
+
expect(defaultWrapper.html()).toMatchSnapshot()
|
|
58
|
+
})
|
|
59
|
+
it('contain correct classes', () => {
|
|
60
|
+
expect(defaultWrapper.find('.form-otp').exists()).toBe(true)
|
|
61
|
+
expect(defaultWrapper.find('input[type="hidden"]').exists()).toBe(true)
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
describe(`Customize ${ComponentName} component`, () => {
|
|
66
|
+
it('renders correctly', () => {
|
|
67
|
+
expect(customWrapper.html()).toMatchSnapshot()
|
|
68
|
+
})
|
|
69
|
+
it('contain size classes', () => {
|
|
70
|
+
expect(customWrapper.find('.form-otp-lg').exists()).toBe(true)
|
|
71
|
+
})
|
|
72
|
+
it('has hidden input', () => {
|
|
73
|
+
expect(customWrapper.find('input[type="hidden"]').exists()).toBe(true)
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe(`${ComponentName} with default value`, () => {
|
|
78
|
+
it('renders correctly', () => {
|
|
79
|
+
expect(withValueWrapper.html()).toMatchSnapshot()
|
|
80
|
+
})
|
|
81
|
+
it('has hidden input with value', () => {
|
|
82
|
+
const hiddenInput = withValueWrapper.find('input[type="hidden"]')
|
|
83
|
+
expect(hiddenInput.exists()).toBe(true)
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe(`${ComponentName} form integration`, () => {
|
|
88
|
+
it('works in a form', () => {
|
|
89
|
+
const wrapper = mount({
|
|
90
|
+
components: { COneTimePassword: Component, COneTimePasswordInput },
|
|
91
|
+
template: `
|
|
92
|
+
<form>
|
|
93
|
+
<COneTimePassword name="otp" id="test-otp">
|
|
94
|
+
<COneTimePasswordInput />
|
|
95
|
+
<COneTimePasswordInput />
|
|
96
|
+
<COneTimePasswordInput />
|
|
97
|
+
<COneTimePasswordInput />
|
|
98
|
+
</COneTimePassword>
|
|
99
|
+
</form>
|
|
100
|
+
`,
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const hiddenInput = wrapper.find('input[type="hidden"]')
|
|
104
|
+
expect(hiddenInput.exists()).toBe(true)
|
|
105
|
+
expect(hiddenInput.attributes('name')).toBe('otp')
|
|
106
|
+
expect(hiddenInput.attributes('id')).toBe('test-otp')
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
describe(`${ComponentName} accessibility`, () => {
|
|
111
|
+
it('has proper role attributes', () => {
|
|
112
|
+
const wrapper = mount({
|
|
113
|
+
components: { COneTimePassword: Component, COneTimePasswordInput },
|
|
114
|
+
template: `
|
|
115
|
+
<COneTimePassword>
|
|
116
|
+
<COneTimePasswordInput />
|
|
117
|
+
<COneTimePasswordInput />
|
|
118
|
+
<COneTimePasswordInput />
|
|
119
|
+
<COneTimePasswordInput />
|
|
120
|
+
</COneTimePassword>
|
|
121
|
+
`,
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
expect(wrapper.find('[role="group"]').exists()).toBe(true)
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
describe(`${ComponentName} validation`, () => {
|
|
129
|
+
it('applies validation classes when invalid', () => {
|
|
130
|
+
const wrapper = mount({
|
|
131
|
+
components: { COneTimePassword: Component, COneTimePasswordInput },
|
|
132
|
+
template: `
|
|
133
|
+
<COneTimePassword invalid>
|
|
134
|
+
<COneTimePasswordInput />
|
|
135
|
+
<COneTimePasswordInput />
|
|
136
|
+
<COneTimePasswordInput />
|
|
137
|
+
<COneTimePasswordInput />
|
|
138
|
+
</COneTimePassword>
|
|
139
|
+
`,
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
expect(wrapper.html()).toContain('is-invalid')
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('applies validation classes when valid', () => {
|
|
146
|
+
const wrapper = mount({
|
|
147
|
+
components: { COneTimePassword: Component, COneTimePasswordInput },
|
|
148
|
+
template: `
|
|
149
|
+
<COneTimePassword valid>
|
|
150
|
+
<COneTimePasswordInput />
|
|
151
|
+
<COneTimePasswordInput />
|
|
152
|
+
<COneTimePasswordInput />
|
|
153
|
+
<COneTimePasswordInput />
|
|
154
|
+
</COneTimePassword>
|
|
155
|
+
`,
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
expect(wrapper.html()).toContain('is-valid')
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
describe(`${ComponentName} props`, () => {
|
|
163
|
+
it('applies disabled state', () => {
|
|
164
|
+
const wrapper = mount({
|
|
165
|
+
components: { COneTimePassword: Component, COneTimePasswordInput },
|
|
166
|
+
template: `
|
|
167
|
+
<COneTimePassword disabled>
|
|
168
|
+
<COneTimePasswordInput />
|
|
169
|
+
<COneTimePasswordInput />
|
|
170
|
+
<COneTimePasswordInput />
|
|
171
|
+
<COneTimePasswordInput />
|
|
172
|
+
</COneTimePassword>
|
|
173
|
+
`,
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
expect(wrapper.html()).toContain('disabled')
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('applies readonly state', () => {
|
|
180
|
+
const wrapper = mount({
|
|
181
|
+
components: { COneTimePassword: Component, COneTimePasswordInput },
|
|
182
|
+
template: `
|
|
183
|
+
<COneTimePassword readonly>
|
|
184
|
+
<COneTimePasswordInput />
|
|
185
|
+
<COneTimePasswordInput />
|
|
186
|
+
<COneTimePasswordInput />
|
|
187
|
+
<COneTimePasswordInput />
|
|
188
|
+
</COneTimePassword>
|
|
189
|
+
`,
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
expect(wrapper.html()).toContain('readonly')
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
it('applies masked state', () => {
|
|
196
|
+
const wrapper = mount({
|
|
197
|
+
components: { COneTimePassword: Component, COneTimePasswordInput },
|
|
198
|
+
template: `
|
|
199
|
+
<COneTimePassword masked>
|
|
200
|
+
<COneTimePasswordInput />
|
|
201
|
+
<COneTimePasswordInput />
|
|
202
|
+
<COneTimePasswordInput />
|
|
203
|
+
<COneTimePasswordInput />
|
|
204
|
+
</COneTimePassword>
|
|
205
|
+
`,
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
expect(wrapper.html()).toContain('type="password"')
|
|
209
|
+
})
|
|
210
|
+
})
|
package/src/components/one-time-password-input/__tests__/__snapshots__/COneTimePassword.spec.ts.snap
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`COneTimePassword Component rendering COneTimePassword customize props 1`] = `"<div class="form-otp" role="group"><input type="text" class="form-otp-control" tabindex="0" aria-label="Digit 1 of 0" inputmode="numeric" pattern="[0-9]*" maxlength="1" autocomplete="off" value=""><input type="text" class="form-otp-control" tabindex="-1" aria-label="Digit 2 of 0" inputmode="numeric" pattern="[0-9]*" maxlength="1" autocomplete="off" value=""><input type="text" class="form-otp-control" tabindex="-1" aria-label="Digit 3 of 0" inputmode="numeric" pattern="[0-9]*" maxlength="1" autocomplete="off" value=""><input type="text" class="form-otp-control" tabindex="-1" aria-label="Digit 4 of 0" inputmode="numeric" pattern="[0-9]*" maxlength="1" autocomplete="off" value=""><input type="hidden" value=""></div>"`;
|
|
4
|
+
|
|
5
|
+
exports[`COneTimePassword Component rendering loads and displays COneTimePassword component 1`] = `"<div class="form-otp" role="group"><input type="text" class="form-otp-control" tabindex="0" aria-label="Digit 1 of 0" inputmode="numeric" pattern="[0-9]*" maxlength="1" autocomplete="off" value=""><input type="text" class="form-otp-control" tabindex="-1" aria-label="Digit 2 of 0" inputmode="numeric" pattern="[0-9]*" maxlength="1" autocomplete="off" value=""><input type="text" class="form-otp-control" tabindex="-1" aria-label="Digit 3 of 0" inputmode="numeric" pattern="[0-9]*" maxlength="1" autocomplete="off" value=""><input type="text" class="form-otp-control" tabindex="-1" aria-label="Digit 4 of 0" inputmode="numeric" pattern="[0-9]*" maxlength="1" autocomplete="off" value=""><input type="hidden" value=""></div>"`;
|
|
6
|
+
|
|
7
|
+
exports[`COneTimePassword with default value renders correctly 1`] = `
|
|
8
|
+
"<div class="form-otp" role="group">
|
|
9
|
+
<conetimepasswordinput></conetimepasswordinput>
|
|
10
|
+
<conetimepasswordinput></conetimepasswordinput>
|
|
11
|
+
<conetimepasswordinput></conetimepasswordinput>
|
|
12
|
+
<conetimepasswordinput></conetimepasswordinput><input type="hidden" value="">
|
|
13
|
+
</div>"
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
exports[`Customize COneTimePassword component renders correctly 1`] = `
|
|
17
|
+
"<div class="form-otp form-otp-lg" role="group">
|
|
18
|
+
<conetimepasswordinput></conetimepasswordinput>
|
|
19
|
+
<conetimepasswordinput></conetimepasswordinput>
|
|
20
|
+
<conetimepasswordinput></conetimepasswordinput>
|
|
21
|
+
<conetimepasswordinput></conetimepasswordinput><input type="hidden" disabled="" value="">
|
|
22
|
+
</div>"
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
exports[`Loads and display COneTimePassword component renders correctly 1`] = `
|
|
26
|
+
"<div class="form-otp" role="group">
|
|
27
|
+
<conetimepasswordinput></conetimepasswordinput>
|
|
28
|
+
<conetimepasswordinput></conetimepasswordinput>
|
|
29
|
+
<conetimepasswordinput></conetimepasswordinput>
|
|
30
|
+
<conetimepasswordinput></conetimepasswordinput><input type="hidden" value="">
|
|
31
|
+
</div>"
|
|
32
|
+
`;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const isValidInput = (value: string, type: 'number' | 'text'): boolean => {
|
|
2
|
+
if (type === 'number') {
|
|
3
|
+
return /^\d$/.test(value)
|
|
4
|
+
}
|
|
5
|
+
return /^.$/u.test(value)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const extractValidChars = (value: string, type: 'number' | 'text'): string => {
|
|
9
|
+
if (type === 'number') {
|
|
10
|
+
return value.replace(/\D/g, '')
|
|
11
|
+
}
|
|
12
|
+
return value
|
|
13
|
+
}
|