vue-tel-input 6.0.0-beta.7 → 6.0.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.
@@ -0,0 +1,261 @@
1
+ import Vue from 'vue';
2
+ import { shallowMount } from '@vue/test-utils';
3
+ import VueTelInput from './vue-tel-input.vue';
4
+ import * as utils from '../utils';
5
+
6
+ describe('vue-tel-input', () => {
7
+ beforeEach(() => {
8
+ jest.spyOn(utils, 'getCountry').mockImplementation(() => Promise.resolve('au'));
9
+ });
10
+
11
+ it('renders without crash', () => {
12
+ const wrapper = shallowMount(VueTelInput);
13
+
14
+ expect(wrapper.find('.vue-tel-input').exists()).toBeTruthy();
15
+ });
16
+ // TODO: Test validation of some specific phone numbers
17
+ });
18
+
19
+ describe('Props', () => {
20
+ beforeEach(() => {
21
+ jest.spyOn(utils, 'getCountry').mockImplementation(() => Promise.resolve('au'));
22
+ });
23
+
24
+ describe(':allCountries', () => {
25
+ it('overrides all pre-defined countries', async () => {
26
+ const wrapper = shallowMount(VueTelInput, {
27
+ propsData: {
28
+ allCountries: [{ iso2: 'AU' }],
29
+ autoDefaultCountry: false,
30
+ },
31
+ });
32
+ await Vue.nextTick();
33
+ expect(wrapper.vm.sortedCountries).toHaveLength(1);
34
+ expect(wrapper.findAll('.vti__dropdown-list li')).toHaveLength(1);
35
+ expect(wrapper.find('.vti__selection > .vti__flag').classes()).toContain('au');
36
+ });
37
+ });
38
+ // describe(':customValidate', () => {
39
+ // it('tests custom validation on type', () => {
40
+ // const wrapper = shallowMount(VueTelInput, {
41
+ // propsData: {
42
+ // customValidate: new RegExp('^[()-+0-9s]*$'),
43
+ // },
44
+ // });
45
+ // wrapper.vm.testCustomValidate = jest.fn();
46
+ // wrapper.vm.onInput();
47
+ // expect(wrapper.vm.testCustomValidate).toHaveBeenCalledTimes(1);
48
+ // });
49
+ // });
50
+ describe(':defaultCountry', () => {
51
+ it('shows correct default country', async () => {
52
+ const wrapper = shallowMount(VueTelInput, {
53
+ propsData: {
54
+ defaultCountry: 'AU',
55
+ },
56
+ });
57
+ await Vue.nextTick();
58
+ expect(wrapper.find('.vti__selection > .vti__flag').classes()).toContain('au');
59
+ });
60
+ });
61
+ describe(':defaultCountryByDialCode', () => {
62
+ it('shows correct default country by dial code', async () => {
63
+ const wrapper = shallowMount(VueTelInput, {
64
+ propsData: {
65
+ defaultCountry: 48,
66
+ },
67
+ });
68
+ await Vue.nextTick();
69
+ expect(wrapper.find('.vti__selection > .vti__flag').classes()).toContain('pl');
70
+ });
71
+ });
72
+ describe(':disabled', () => {
73
+ it('adds disabled class to component', () => {
74
+ const wrapper = shallowMount(VueTelInput, {
75
+ propsData: {
76
+ disabled: true,
77
+ },
78
+ });
79
+
80
+ expect(wrapper.find('.vue-tel-input').classes()).toContain('disabled');
81
+ expect(wrapper.find('.vti__input').attributes('disabled')).toBe('disabled');
82
+ });
83
+ it('stops showing dropdown list when true', () => {
84
+ const wrapper = shallowMount(VueTelInput, {
85
+ propsData: {
86
+ disabled: true,
87
+ },
88
+ });
89
+
90
+ wrapper.find('.vti__dropdown').trigger('click');
91
+ expect(wrapper.vm.open).toBe(false);
92
+ });
93
+ });
94
+ describe(':autoDefaultCountry', () => {
95
+ it('doesn\'t fetch the country by IP when set FALSE', async () => {
96
+ utils.getCountry.mockReset();
97
+ const wrapper = shallowMount(VueTelInput, {
98
+ propsData: {
99
+ autoDefaultCountry: false,
100
+ preferredCountries: ['AU'],
101
+ },
102
+ });
103
+ await Vue.nextTick();
104
+ expect(utils.getCountry).not.toHaveBeenCalled();
105
+ expect(wrapper.find('.vti__selection > .vti__flag').classes()).toContain('au');
106
+ });
107
+ });
108
+ describe(':dropdownOptions', () => {
109
+ it('.tabindex sets tabindex for dropdown', () => {
110
+ const wrapper = shallowMount(VueTelInput, {
111
+ propsData: {
112
+ dropdownOptions: {
113
+ tabindex: 1,
114
+ },
115
+ },
116
+ });
117
+
118
+ expect(wrapper.find('.vti__dropdown').attributes('tabindex')).toBe('1');
119
+ });
120
+ it('.showDialCodeInList hides dial code in the dropdown', () => {
121
+ const wrapper = shallowMount(VueTelInput, {
122
+ propsData: {
123
+ dropdownOptions: {
124
+ showDialCodeInList: false,
125
+ },
126
+ },
127
+ });
128
+
129
+ expect(wrapper.find('.vti__dropdown-item span').exists()).toBeFalsy();
130
+ });
131
+ it('.showDialCodeInSelection shows country code in the selection if TRUE', async () => {
132
+ const wrapper = shallowMount(VueTelInput, {
133
+ propsData: {
134
+ dropdownOptions: {
135
+ showDialCodeInSelection: true,
136
+ },
137
+ defaultCountry: 'au',
138
+ },
139
+ });
140
+ await Vue.nextTick();
141
+ expect(wrapper.find('.vti__selection > .vti__country-code').text()).toBe('+61');
142
+ });
143
+ it('.showFlags hides flags in the dropdown list if FALSE', () => {
144
+ const wrapper = shallowMount(VueTelInput, {
145
+ propsData: {
146
+ dropdownOptions: {
147
+ showFlags: false,
148
+ },
149
+ },
150
+ });
151
+
152
+ expect(wrapper.find('.vti__dropdown-item .vti__flag').exists()).toBeFalsy();
153
+ });
154
+ });
155
+ describe(':ignoredCountries', () => {
156
+ it('hides countries from the list', () => {
157
+ const wrapper = shallowMount(VueTelInput, {
158
+ propsData: {
159
+ ignoredCountries: ['AU'],
160
+ },
161
+ });
162
+
163
+ expect(wrapper.vm.filteredCountries.find(({ iso2 }) => iso2 === 'AU')).toBeUndefined();
164
+ expect(wrapper.find('.vti__dropdown-item > .vti__flag.au').exists()).toBeFalsy();
165
+ });
166
+ });
167
+ describe(':inputOptions', () => {
168
+ it('.id sets `id` native attribute of input', () => {
169
+ const wrapper = shallowMount(VueTelInput, {
170
+ propsData: {
171
+ inputOptions: { id: 'test' },
172
+ },
173
+ });
174
+
175
+ expect(wrapper.find('.vti__input').attributes('id')).toBe('test');
176
+ });
177
+ it('.maxlength sets `maxlength` native attribute of input', () => {
178
+ const wrapper = shallowMount(VueTelInput, {
179
+ propsData: {
180
+ inputOptions: { maxlength: 20 },
181
+ },
182
+ });
183
+
184
+ expect(wrapper.find('.vti__input').attributes('maxlength')).toBe('20');
185
+ });
186
+ it('.name sets `name` native attribute of input', () => {
187
+ const wrapper = shallowMount(VueTelInput, {
188
+ propsData: {
189
+ inputOptions: { name: 'test' },
190
+ },
191
+ });
192
+
193
+ expect(wrapper.find('.vti__input').attributes('name')).toBe('test');
194
+ });
195
+ it('.styleClasses sets classes along side with .vti__input', () => {
196
+ const wrapper = shallowMount(VueTelInput, {
197
+ propsData: {
198
+ inputOptions: { styleClasses: ['test'] },
199
+ },
200
+ });
201
+
202
+ expect(wrapper.find('.vti__input').classes()).toContain('test');
203
+ });
204
+ // it('.dynamicPlaceholder generates a random number as placeholder', async () => {
205
+ // const wrapper = shallowMount(VueTelInput, {
206
+ // propsData: {
207
+ // inputOptions: { dynamicPlaceholder: true },
208
+ // defaultCountry: 'au',
209
+ // },
210
+ // });
211
+ // await new Promise((res) => setTimeout(() => {
212
+ // expect(wrapper.find('.vti__input').attributes('placeholder')).toContain('+61 ');
213
+ // res();
214
+ // }, 2000));
215
+ // });
216
+ });
217
+ describe(':invalid-msg', () => {
218
+ // TODO
219
+ });
220
+ describe(':mode', () => {
221
+ // TODO
222
+ });
223
+ describe(':onlyCountries', () => {
224
+ it('limits the countries to be used', () => {
225
+ const wrapper = shallowMount(VueTelInput, {
226
+ propsData: {
227
+ onlyCountries: ['AU'],
228
+ },
229
+ });
230
+
231
+ expect(wrapper.findAll('.vti__dropdown-item')).toHaveLength(1);
232
+ expect(wrapper.vm.filteredCountries).toHaveLength(1);
233
+ });
234
+ });
235
+ describe(':preferredCountries', () => {
236
+ it('are highlighted and be on top of the dropdown', () => {
237
+ const wrapper = shallowMount(VueTelInput, {
238
+ propsData: {
239
+ preferredCountries: ['AU'],
240
+ },
241
+ });
242
+
243
+ expect(wrapper.vm.sortedCountries[0].iso2).toBe('AU');
244
+ expect(wrapper.find('.vti__dropdown-item > .vti__flag.au').element.parentElement.getAttribute('class')).toContain('preferred');
245
+ });
246
+ });
247
+ describe(':validCharactersOnly', () => {
248
+ // TODO
249
+ });
250
+ describe(':styleClasses', () => {
251
+ it('sets classes along side with .vue-tel-input', () => {
252
+ const wrapper = shallowMount(VueTelInput, {
253
+ propsData: {
254
+ styleClasses: ['test'],
255
+ },
256
+ });
257
+
258
+ expect(wrapper.find('.vue-tel-input').classes()).toContain('test');
259
+ });
260
+ });
261
+ });