@kubex/zinc 1.1.115 → 1.1.116

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.
@@ -1,6 +1,8 @@
1
1
  import '../../../dist/zn.min.js';
2
2
  import { expect, fixture, html, waitUntil } from '@open-wc/testing';
3
3
  import type ZnInlineEdit from '../inline-edit/inline-edit.component';
4
+ import type ZnInput from '../input/input.component';
5
+ import type ZnSelect from '../select/select.component';
4
6
  import type ZnSlashMenu from '../slash-menu/slash-menu.component';
5
7
  import type ZnTextarea from '../textarea/textarea.component';
6
8
  import type ZnTranslations from './translations.component';
@@ -37,7 +39,7 @@ describe('<zn-translations>', () => {
37
39
  el.values = { 'en': 'Hello' };
38
40
  await el.updateComplete;
39
41
 
40
- const input = el.shadowRoot!.querySelector('zn-inline-edit') as ZnInlineEdit | null;
42
+ const input = el.shadowRoot!.querySelector('zn-input') as ZnInput | null;
41
43
  expect(input).to.exist;
42
44
  expect(input!.value).to.equal('Hello');
43
45
 
@@ -50,6 +52,113 @@ describe('<zn-translations>', () => {
50
52
  await expect(JSON.parse(el.value)).to.deep.equal({'en': 'Hello World'});
51
53
  });
52
54
 
55
+ describe('language select', () => {
56
+ function selectOf(el: ZnTranslations) {
57
+ return el.shadowRoot!.querySelector<ZnSelect>('zn-select');
58
+ }
59
+
60
+ it('is not rendered for a single language', async () => {
61
+ const el = await fixture<ZnTranslations>(html`<zn-translations></zn-translations>`);
62
+ await el.updateComplete;
63
+
64
+ expect(selectOf(el)).to.be.null;
65
+ });
66
+
67
+ it('offers every configured language, translated or not', async () => {
68
+ const el = await fixture<ZnTranslations>(html`
69
+ <zn-translations
70
+ languages='{"en":"English","fr":"French","de":"German"}'
71
+ values='{"en":"Hello","de":"Hallo"}'></zn-translations>`);
72
+ await el.updateComplete;
73
+
74
+ const options = [...selectOf(el)!.querySelectorAll('zn-option')];
75
+ expect(options.map(option => option.value)).to.deep.equal(['en', 'fr', 'de']);
76
+ });
77
+
78
+ it('marks a language with a value translated and a blank one as falling back to English', async () => {
79
+ const el = await fixture<ZnTranslations>(html`
80
+ <zn-translations
81
+ languages='{"en":"English","fr":"French"}'
82
+ values='{"en":"Hello"}'></zn-translations>`);
83
+ await el.updateComplete;
84
+
85
+ const chips = [...selectOf(el)!.querySelectorAll('zn-option zn-chip')];
86
+ expect(chips.map(chip => chip.textContent?.trim())).to.deep.equal(['Translated', 'English']);
87
+ expect(chips.map(chip => chip.getAttribute('type'))).to.deep.equal(['success', 'error']);
88
+ });
89
+
90
+ it('summarises progress on the closed select, leaving the options their own states', async () => {
91
+ const el = await fixture<ZnTranslations>(html`
92
+ <zn-translations
93
+ languages='{"en":"English","fr":"French","de":"German"}'
94
+ values='{"en":"Hello","de":"Hallo"}'></zn-translations>`);
95
+ await el.updateComplete;
96
+
97
+ const summary = selectOf(el)!.querySelector('zn-chip[slot="suffix"]')!;
98
+ expect(summary.textContent?.trim()).to.equal('1/2');
99
+ expect(summary.getAttribute('type')).to.equal('warning');
100
+
101
+ const options = [...selectOf(el)!.querySelectorAll('zn-option zn-chip')];
102
+ expect(options.map(chip => chip.textContent?.trim())).to.deep.equal(['Translated', 'English', 'Translated']);
103
+ });
104
+
105
+ it('switches the edited language when the select changes', async () => {
106
+ const el = await fixture<ZnTranslations>(html`
107
+ <zn-translations
108
+ languages='{"en":"English","fr":"French"}'
109
+ values='{"en":"Hello","fr":"Bonjour"}'></zn-translations>`);
110
+ await el.updateComplete;
111
+
112
+ const select = selectOf(el)!;
113
+ select.value = 'fr';
114
+ select.dispatchEvent(new CustomEvent('zn-change', {bubbles: true, composed: true}));
115
+ await el.updateComplete;
116
+
117
+ expect(el.getActiveLanguage()).to.equal('fr');
118
+ expect(el.shadowRoot!.querySelector<ZnInput>('zn-input')!.value).to.equal('Bonjour');
119
+ });
120
+
121
+ it("does not report the select's own change as a value change", async () => {
122
+ const el = await fixture<ZnTranslations>(html`
123
+ <zn-translations
124
+ languages='{"en":"English","fr":"French"}'
125
+ values='{"en":"Hello"}'></zn-translations>`);
126
+ await el.updateComplete;
127
+
128
+ let changes = 0;
129
+ el.addEventListener('zn-change', () => changes++);
130
+
131
+ const select = selectOf(el)!;
132
+ select.value = 'fr';
133
+ select.dispatchEvent(new CustomEvent('zn-change', {bubbles: true, composed: true}));
134
+ await el.updateComplete;
135
+
136
+ expect(changes).to.equal(0);
137
+ });
138
+
139
+ it('leaves a browsed language out of the submitted value until it is typed into', async () => {
140
+ const el = await fixture<ZnTranslations>(html`
141
+ <zn-translations
142
+ languages='{"en":"English","fr":"French"}'
143
+ values='{"en":"Hello"}'></zn-translations>`);
144
+ el.setActiveLanguage('fr');
145
+ await el.updateComplete;
146
+
147
+ expect(JSON.parse(el.value)).to.deep.equal({en: 'Hello'});
148
+ });
149
+
150
+ it('shows the English text as the placeholder for a blank language', async () => {
151
+ const el = await fixture<ZnTranslations>(html`
152
+ <zn-translations
153
+ languages='{"en":"English","fr":"French"}'
154
+ values='{"en":"Hello"}'></zn-translations>`);
155
+ el.setActiveLanguage('fr');
156
+ await el.updateComplete;
157
+
158
+ expect(el.shadowRoot!.querySelector<ZnInput>('zn-input')!.placeholder).to.equal('Hello');
159
+ });
160
+ });
161
+
53
162
  describe('help text', () => {
54
163
  function helpTextOf(el: ZnTranslations) {
55
164
  return el.shadowRoot!.querySelector<HTMLElement>('[part="form-control-help-text"]');
@@ -92,18 +201,113 @@ describe('<zn-translations>', () => {
92
201
  });
93
202
  });
94
203
 
95
- describe('slash menu', () => {
96
- /** Puts the active language's field into edit mode, the way clicking it does. */
97
- async function textareaOf(el: ZnTranslations) {
204
+ describe('field', () => {
205
+ it('renders a plain input by default', async () => {
206
+ const el = await fixture<ZnTranslations>(html`<zn-translations></zn-translations>`);
207
+ await el.updateComplete;
208
+
209
+ expect(el.shadowRoot!.querySelector('zn-input')).to.exist;
210
+ expect(el.shadowRoot!.querySelector('zn-inline-edit')).to.be.null;
211
+ });
212
+
213
+ it('renders a plain textarea for input-type="textarea"', async () => {
214
+ const el = await fixture<ZnTranslations>(html`
215
+ <zn-translations input-type="textarea"></zn-translations>`);
98
216
  await el.updateComplete;
99
- const inlineEdit = el.shadowRoot!.querySelector<ZnInlineEdit>('zn-inline-edit')!;
100
- await inlineEdit.updateComplete;
101
217
 
102
- inlineEdit.shadowRoot!.querySelector<HTMLElement>('.ai__left')!
103
- .dispatchEvent(new MouseEvent('click', {bubbles: true, composed: true}));
104
- await inlineEdit.updateComplete;
218
+ expect(el.shadowRoot!.querySelector('zn-textarea')).to.exist;
219
+ expect(el.shadowRoot!.querySelector('zn-input')).to.be.null;
220
+ });
221
+
222
+ it('renders an inline edit when asked for one', async () => {
223
+ const el = await fixture<ZnTranslations>(html`
224
+ <zn-translations inline-edit values='{"en":"Hello"}'></zn-translations>`);
225
+ await el.updateComplete;
105
226
 
106
- const textarea = inlineEdit.shadowRoot!.querySelector<ZnTextarea>('zn-textarea')!;
227
+ const inlineEdit = el.shadowRoot!.querySelector<ZnInlineEdit>('zn-inline-edit');
228
+ expect(inlineEdit).to.exist;
229
+ expect(inlineEdit!.value).to.equal('Hello');
230
+ expect(el.shadowRoot!.querySelector('zn-input')).to.be.null;
231
+ });
232
+
233
+ it('takes no slotted actions of its own', async () => {
234
+ const el = await fixture<ZnTranslations>(html`
235
+ <zn-translations label="Name">
236
+ <zn-button slot="actions">Auto translate</zn-button>
237
+ </zn-translations>`);
238
+ await el.updateComplete;
239
+
240
+ expect(el.shadowRoot!.querySelector('slot[name="actions"]')).to.be.null;
241
+ });
242
+
243
+ it('passes disabled down to the field', async () => {
244
+ const el = await fixture<ZnTranslations>(html`<zn-translations disabled></zn-translations>`);
245
+ await el.updateComplete;
246
+
247
+ expect(el.shadowRoot!.querySelector<ZnInput>('zn-input')!.disabled).to.be.true;
248
+ });
249
+ });
250
+
251
+ describe('form reset', () => {
252
+ it('restores the value the attribute rendered', async () => {
253
+ const form = await fixture<HTMLFormElement>(html`
254
+ <form>
255
+ <zn-translations name="heading" value='{"en":"Chat to us","fr":"Parlez-nous"}'></zn-translations>
256
+ </form>`);
257
+ const el = form.querySelector<ZnTranslations>('zn-translations')!;
258
+ await el.updateComplete;
259
+
260
+ el.values = {en: 'Edited', fr: ''};
261
+ await el.updateComplete;
262
+
263
+ form.reset();
264
+ await el.updateComplete;
265
+
266
+ expect(el.values).to.deep.equal({en: 'Chat to us', fr: 'Parlez-nous'});
267
+ expect(el.shadowRoot!.querySelector<ZnInput>('zn-input')!.value).to.equal('Chat to us');
268
+ });
269
+
270
+ it('restores translations given through the values attribute', async () => {
271
+ const form = await fixture<HTMLFormElement>(html`
272
+ <form>
273
+ <zn-translations name="heading" values='{"en":"Chat to us"}'></zn-translations>
274
+ </form>`);
275
+ const el = form.querySelector<ZnTranslations>('zn-translations')!;
276
+ await el.updateComplete;
277
+
278
+ el.values = {en: ''};
279
+ await el.updateComplete;
280
+
281
+ form.reset();
282
+ await el.updateComplete;
283
+
284
+ expect(el.values).to.deep.equal({en: 'Chat to us'});
285
+ });
286
+
287
+ it('follows the value attribute when the form is re-rendered around it', async () => {
288
+ const form = await fixture<HTMLFormElement>(html`
289
+ <form>
290
+ <zn-translations name="heading" value='{"en":"Chat to us"}'></zn-translations>
291
+ </form>`);
292
+ const el = form.querySelector<ZnTranslations>('zn-translations')!;
293
+ await el.updateComplete;
294
+
295
+ el.setAttribute('value', '{"en":"Talk to us"}');
296
+ await el.updateComplete;
297
+ el.values = {en: 'Edited'};
298
+ await el.updateComplete;
299
+
300
+ form.reset();
301
+ await el.updateComplete;
302
+
303
+ expect(el.values).to.deep.equal({en: 'Talk to us'});
304
+ });
305
+ });
306
+
307
+ describe('slash menu', () => {
308
+ async function textareaOf(el: ZnTranslations) {
309
+ await el.updateComplete;
310
+ const textarea = el.shadowRoot!.querySelector<ZnTextarea>('zn-textarea')!;
107
311
  await textarea.updateComplete;
108
312
 
109
313
  return textarea;