@operato/input 10.29.44 → 10.29.52

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@operato/input",
3
3
  "description": "Webcomponents for input following open-wc recommendations",
4
4
  "author": "heartyoh@hatiolab.com",
5
- "version": "10.29.44",
5
+ "version": "10.29.52",
6
6
  "type": "module",
7
7
  "main": "dist/src/index.js",
8
8
  "module": "dist/src/index.js",
@@ -251,9 +251,9 @@
251
251
  "@material/web": "^2.0.0",
252
252
  "@operato/i18n": "^10.29.27",
253
253
  "@operato/pickr": "^10.29.1",
254
- "@operato/popup": "^10.29.44",
254
+ "@operato/popup": "^10.29.52",
255
255
  "@operato/styles": "^10.29.30",
256
- "@operato/utils": "^10.29.44",
256
+ "@operato/utils": "^10.29.49",
257
257
  "@types/codemirror": "^5.60.5",
258
258
  "@undecaf/zbar-wasm": "^0.11.0",
259
259
  "codemirror": "^6.0.1",
@@ -294,5 +294,5 @@
294
294
  "prettier --write"
295
295
  ]
296
296
  },
297
- "gitHead": "112d3ac6ada895fc45c2010c2555d5fd88a0f8a5"
297
+ "gitHead": "2e34202735031117c1f096297dee7e48d3595144"
298
298
  }
@@ -0,0 +1,59 @@
1
+ import { expect, fixture } from '@open-wc/testing'
2
+ import { html } from 'lit'
3
+ import '../src/ox-input-barcode.js'
4
+ import type { OxInputBarcode } from '../src/ox-input-barcode.js'
5
+
6
+ /**
7
+ * One Enter is one `change`. Enter says the value at once; the browser would say the same value again when the
8
+ * field loses focus, since Enter kept it from saying it then. A host that looks something up on `change` (the band's
9
+ * ID Lens, ADR-0133) looked it up twice - the second time when another part of the page gave the field its focus back.
10
+ */
11
+ describe('ox-input-barcode change', () => {
12
+ async function field() {
13
+ const element = await fixture<OxInputBarcode>(html`<ox-input-barcode></ox-input-barcode>`)
14
+ const input = element.shadowRoot!.querySelector('input') as HTMLInputElement
15
+ const said: string[] = []
16
+ element.addEventListener('change', e => said.push((e as CustomEvent).detail))
17
+ return { element, input, said }
18
+ }
19
+
20
+ const type = (input: HTMLInputElement, text: string) => {
21
+ input.value = text
22
+ input.dispatchEvent(new Event('input'))
23
+ }
24
+ const enter = (input: HTMLInputElement) => input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true }))
25
+ /* What the browser does on blur when the value differs from the one at focus. */
26
+ const leave = (input: HTMLInputElement) => input.dispatchEvent(new Event('change', { bubbles: true }))
27
+
28
+ it('Enter says the value once; leaving the field afterwards says nothing more', async () => {
29
+ const { input, said } = await field()
30
+ type(input, 'X-1')
31
+ enter(input)
32
+ leave(input)
33
+ expect(said).to.deep.equal(['X-1'])
34
+ })
35
+
36
+ it('Enter again on the same value is asked again - it is a request, not a change', async () => {
37
+ const { input, said } = await field()
38
+ type(input, 'X-1')
39
+ enter(input)
40
+ enter(input)
41
+ expect(said).to.deep.equal(['X-1', 'X-1'])
42
+ })
43
+
44
+ it('text changed after Enter and then left is still said on leaving', async () => {
45
+ const { input, said } = await field()
46
+ type(input, 'X-1')
47
+ enter(input)
48
+ type(input, 'X-2')
49
+ leave(input)
50
+ expect(said).to.deep.equal(['X-1', 'X-2'])
51
+ })
52
+
53
+ it('text typed and left without Enter is said on leaving, as before', async () => {
54
+ const { input, said } = await field()
55
+ type(input, 'X-3')
56
+ leave(input)
57
+ expect(said).to.deep.equal(['X-3'])
58
+ })
59
+ })