@operato/input 10.29.36 → 10.29.37

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.36",
5
+ "version": "10.29.37",
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.36",
254
+ "@operato/popup": "^10.29.37",
255
255
  "@operato/styles": "^10.29.30",
256
- "@operato/utils": "^10.29.36",
256
+ "@operato/utils": "^10.29.37",
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": "90c8bc8593e5d68745aeddd45752fab83c50cc16"
297
+ "gitHead": "38361a65226ee9f23814747b4f0520edf42c3184"
298
298
  }
@@ -123,6 +123,137 @@ describe('ox-input-file', () => {
123
123
  expect(el.value ?? [], 'a drop landed mid-upload').to.deep.equal([])
124
124
  })
125
125
 
126
+ it('keeps its button at the end where its place says so, with the refusal under it', async () => {
127
+ const wrap: any = await fixture(html`<div style="--ox-actions-align: end; display: flex; justify-content: flex-end; width: 400px">
128
+ <ox-input-file quiet accept="image/*"></ox-input-file>
129
+ </div>`)
130
+ const el: any = wrap.querySelector('ox-input-file')
131
+
132
+ drop(el, file('a-rather-long-file-name-that-was-refused.txt', 'text/plain'))
133
+ await settle(el)
134
+
135
+ const host = el.getBoundingClientRect()
136
+ const button = buttons(el)[0].getBoundingClientRect()
137
+ const refusal = el.renderRoot.querySelector('[role="alert"]')
138
+
139
+ expect(Math.abs(host.right - button.right), 'the button left the end').to.be.below(1)
140
+ expect(getComputedStyle(refusal).textAlign).to.equal('end')
141
+ })
142
+
143
+ it('writes the picked name at the size of its surroundings', async () => {
144
+ const wrap: any = await fixture(html`<div style="font-size: 11px"><ox-input-file quiet></ox-input-file></div>`)
145
+ const el: any = wrap.querySelector('ox-input-file')
146
+
147
+ drop(el, file('a.pdf', 'application/pdf'))
148
+ await settle(el)
149
+
150
+ expect(getComputedStyle(el.renderRoot.querySelector('.picked .name')).fontSize).to.equal('11px')
151
+ })
152
+
153
+ it('starts at the start when nothing says otherwise', async () => {
154
+ const el: any = await fixture(html`<ox-input-file quiet accept="image/*"></ox-input-file>`)
155
+
156
+ drop(el, file('a-rather-long-file-name-that-was-refused.txt', 'text/plain'))
157
+ await settle(el)
158
+
159
+ expect(Math.abs(el.getBoundingClientRect().left - buttons(el)[0].getBoundingClientRect().left)).to.be.below(1)
160
+ })
161
+
162
+ it('shows an icon only when given one, and takes its button height from its place', async () => {
163
+ const plain: any = await fixture(html`<ox-input-file quiet></ox-input-file>`)
164
+ expect(!!buttons(plain)[0].querySelector('md-icon'), 'an icon nobody asked for').to.equal(false)
165
+
166
+ const wrap: any = await fixture(html`<div style="--ox-input-file-action-height: 40px">
167
+ <ox-input-file quiet icon="photo_camera" label="take"></ox-input-file>
168
+ </div>`)
169
+ const camera: any = wrap.querySelector('ox-input-file')
170
+ const button = buttons(camera)[0]
171
+
172
+ expect(button.querySelector('md-icon')?.textContent).to.equal('photo_camera')
173
+ expect(button.getBoundingClientRect().height).to.equal(40)
174
+ })
175
+
176
+ it('draws no button of its own when a page action starts the pick, and still refuses in place', async () => {
177
+ const el: any = await fixture(html`<ox-input-file quiet outside-trigger accept="application/pdf"></ox-input-file>`)
178
+
179
+ expect(buttons(el).length, 'a second trigger beside the page action').to.equal(0)
180
+
181
+ let opened = 0
182
+ el.fileInput.click = () => opened++
183
+ el.pick()
184
+ expect(opened, 'pick() did not open the dialog').to.equal(1)
185
+
186
+ drop(el, file('register.xlsx', 'application/vnd.ms-excel'))
187
+ await settle(el)
188
+ expect(!!el.renderRoot.querySelector('[role="alert"]'), 'the refusal is not shown').to.equal(true)
189
+ })
190
+
191
+ it('leaves the server limits out for a file read in the browser, and still checks the type', async () => {
192
+ registerFileUploadLimits(async () => ({ maxFileSize: 20 }))
193
+ const el: any = await fixture(html`<ox-input-file quiet local accept=".json"></ox-input-file>`)
194
+
195
+ drop(el, file('samples.json', 'application/json', 50))
196
+ await settle(el)
197
+ expect(el.value.map((one: File) => one.name), 'a local file was held to the upload limit').to.deep.equal(['samples.json'])
198
+
199
+ drop(el, file('notes.txt', 'text/plain'))
200
+ await settle(el)
201
+ expect(el.value.map((one: File) => one.name)).to.deep.equal(['samples.json'])
202
+ expect(!!el.renderRoot.querySelector('[role="alert"]')).to.equal(true)
203
+ })
204
+
205
+ it('takes a screen limit tighter than the server, and never a looser one', async () => {
206
+ registerFileUploadLimits(async () => ({ maxFileSize: 100 }))
207
+ const el: any = await fixture(html`<ox-input-file quiet multiple .limits=${{ maxFileSize: 20 }}></ox-input-file>`)
208
+
209
+ drop(el, file('small.png', 'image/png', 10), file('middle.png', 'image/png', 50))
210
+ await settle(el)
211
+ expect(el.value.map((one: File) => one.name), 'the screen limit was not applied').to.deep.equal(['small.png'])
212
+
213
+ el.limits = { maxFileSize: 1000 }
214
+ drop(el, file('large.png', 'image/png', 500))
215
+ await settle(el)
216
+ expect(el.value.map((one: File) => one.name), 'a screen loosened the server limit').to.deep.equal(['small.png'])
217
+ })
218
+
219
+ it('shows a file name as written, in the box and in a refusal', async () => {
220
+ const el: any = await fixture(html`<ox-input-file accept="image/*"></ox-input-file>`)
221
+
222
+ drop(el, file('notes.txt', 'text/plain'))
223
+ await settle(el)
224
+ expect(getComputedStyle(el.renderRoot.querySelector('[role="alert"]')).textTransform, 'the refusal recased the name').to.equal('none')
225
+
226
+ el.accept = ''
227
+ drop(el, file('model.figpkg', ''))
228
+ await settle(el)
229
+ expect(getComputedStyle(el.renderRoot.querySelector('li')).textTransform, 'the list recased the name').to.equal('none')
230
+ })
231
+
232
+ it('lets a panel style its quiet buttons by part and give the attach button its own icon', async () => {
233
+ const el: any = await fixture(html`<ox-input-file quiet><span slot="icon" id="tile">▣</span></ox-input-file>`)
234
+
235
+ const attach = el.renderRoot.querySelector('[part="attach"]')
236
+ expect(!!attach, 'no attach part').to.equal(true)
237
+ const slot = attach.querySelector('slot[name="icon"]') as HTMLSlotElement
238
+ expect(slot.assignedElements().map(one => one.id)).to.deep.equal(['tile'])
239
+
240
+ drop(el, file('a.pdf', 'application/pdf'))
241
+ await settle(el)
242
+ expect([...el.renderRoot.querySelectorAll('[part]')].map((one: Element) => one.getAttribute('part'))).to.deep.equal(['replace', 'remove'])
243
+ })
244
+
245
+ it('hands its files to the form data as files', async () => {
246
+ const form: any = await fixture(html`<form><ox-input-file name="papers" multiple></ox-input-file></form>`)
247
+ const el: any = form.querySelector('ox-input-file')
248
+
249
+ drop(el, file('a.pdf', 'application/pdf'), file('b.png', 'image/png'))
250
+ await settle(el)
251
+
252
+ const sent = new FormData(form).getAll('papers') as File[]
253
+ expect(sent.every(one => one instanceof File), 'a file went as text').to.equal(true)
254
+ expect(sent.map(one => one.name)).to.deep.equal(['a.pdf', 'b.png'])
255
+ })
256
+
126
257
  it('keeps the drop box when not quiet', async () => {
127
258
  const el: any = await fixture(html`<ox-input-file></ox-input-file>`)
128
259