@osimatic/helpers-js 1.5.31 → 1.5.33

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/location.js CHANGED
@@ -24,7 +24,7 @@ class Country {
24
24
  return [...countryCode.toUpperCase()].map(c => String.fromCodePoint(0x1F1E6 - 65 + c.charCodeAt(0))).join('');
25
25
  }
26
26
 
27
- static fillSelect(select, defaultValue=null, showFlags=false, locale='fr-FR', countriesList=null, addNoneValue=false, noneLabel='- Aucun -') {
27
+ static fillSelect(select, defaultValue=null, locale='fr-FR', showFlags=false, countriesList=null, addNoneValue=false, noneLabel='- Aucun -') {
28
28
  select = toEl(select);
29
29
  if (!select) {
30
30
  return;
@@ -54,7 +54,7 @@ class Country {
54
54
  }
55
55
 
56
56
  static fillSelectWithFlags(select, defaultValue=null, locale='fr-FR', countriesList=null, addNoneValue=false, noneLabel='- Aucun -') {
57
- return Country.fillSelect(select, defaultValue, true, locale, countriesList, addNoneValue, noneLabel);
57
+ return Country.fillSelect(select, defaultValue, locale, true, countriesList, addNoneValue, noneLabel);
58
58
  }
59
59
 
60
60
  static getCountryName(countryCode, locale='fr-FR') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.5.31",
3
+ "version": "1.5.33",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -123,6 +123,74 @@ describe('Country', () => {
123
123
  expect(typeof result).toBe('object');
124
124
  });
125
125
  });
126
+
127
+ describe('fillSelect', () => {
128
+ function makeSelect() {
129
+ const options = [];
130
+ return {
131
+ children: options,
132
+ value: null,
133
+ insertAdjacentHTML(position, html) { options.push(html); },
134
+ };
135
+ }
136
+
137
+ test('should populate with all countries in given locale', () => {
138
+ const select = makeSelect();
139
+ Country.fillSelect(select, null, 'fr-FR');
140
+ expect(select.children.length).toBeGreaterThan(0);
141
+ expect(select.children.some(h => h.includes('value="FR"'))).toBe(true);
142
+ expect(select.children.some(h => h.includes('France'))).toBe(true);
143
+ });
144
+
145
+ test('should restrict to provided countriesList', () => {
146
+ const select = makeSelect();
147
+ Country.fillSelect(select, null, 'fr-FR', false, ['FR', 'DE', 'US']);
148
+ expect(select.children).toHaveLength(3);
149
+ expect(select.children.some(h => h.includes('value="FR"'))).toBe(true);
150
+ expect(select.children.some(h => h.includes('value="DE"'))).toBe(true);
151
+ });
152
+
153
+ test('should add none option when addNoneValue is true', () => {
154
+ const select = makeSelect();
155
+ Country.fillSelect(select, null, 'fr-FR', false, ['FR'], true, '-- Aucun --');
156
+ expect(select.children[0]).toContain('value=""');
157
+ expect(select.children[0]).toContain('-- Aucun --');
158
+ expect(select.children).toHaveLength(2);
159
+ });
160
+
161
+ test('should add data-content with flag-icons when showFlags is true', () => {
162
+ const select = makeSelect();
163
+ Country.fillSelect(select, null, 'fr-FR', true, ['FR']);
164
+ expect(select.children[0]).toContain('data-content=');
165
+ expect(select.children[0]).toContain('fi fi-fr');
166
+ });
167
+
168
+ test('should not add options if select already has children', () => {
169
+ const select = makeSelect();
170
+ select.children.push('<option value="FR">France</option>');
171
+ Country.fillSelect(select, null, 'fr-FR');
172
+ expect(select.children).toHaveLength(1);
173
+ });
174
+ });
175
+
176
+ describe('fillSelectWithFlags', () => {
177
+ function makeSelect() {
178
+ const options = [];
179
+ return {
180
+ children: options,
181
+ value: null,
182
+ insertAdjacentHTML(position, html) { options.push(html); },
183
+ };
184
+ }
185
+
186
+ test('should add data-content with flag-icons', () => {
187
+ const select = makeSelect();
188
+ Country.fillSelectWithFlags(select, null, 'fr-FR', ['FR', 'US']);
189
+ expect(select.children).toHaveLength(2);
190
+ expect(select.children[0]).toContain('fi fi-fr');
191
+ expect(select.children[1]).toContain('fi fi-us');
192
+ });
193
+ });
126
194
  });
127
195
 
128
196
  describe('Locale', () => {