@operato/utils 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.
@@ -1,6 +1,6 @@
1
1
  import { expect } from '@open-wc/testing'
2
2
 
3
- import { acceptsFile, fileUploadLimits, registerFileUploadLimits, sortPickedFiles } from '../src/file-acceptance.js'
3
+ import { acceptsFile, fileUploadLimits, narrowLimits, registerFileUploadLimits, sortPickedFiles } from '../src/file-acceptance.js'
4
4
  import { FileDropHelper } from '../src/file-drop-helper.js'
5
5
 
6
6
  /**
@@ -49,6 +49,21 @@ describe('file acceptance', () => {
49
49
  expect(refused.map(one => `${one.file.name}:${one.reason}`)).to.deep.equal(['b.txt:type', 'c.png:size', 'e.png:count'])
50
50
  })
51
51
 
52
+ it('takes the tighter of a screen limit and the server limit, never a looser one', () => {
53
+ expect(narrowLimits({ maxFileSize: 5, maxFiles: 10 }, { maxFileSize: 10, maxFiles: 3 })).to.deep.equal({ maxFileSize: 5, maxFiles: 3 })
54
+ expect(narrowLimits({ maxFileSize: 50 }, { maxFileSize: 10 }), 'a screen loosened the server').to.deep.equal({ maxFileSize: 10 })
55
+ expect(narrowLimits(undefined, {})).to.deep.equal({})
56
+ })
57
+
58
+ it('reads a file description as well as a file', () => {
59
+ const { taken, refused } = sortPickedFiles([{ name: 'a.png', type: 'image/png', size: 5 }, { name: 'b.png', type: 'image/png', size: 50 }], {
60
+ accept: 'image/*',
61
+ limits: { maxFileSize: 20 }
62
+ })
63
+ expect(taken.map(one => one.name)).to.deep.equal(['a.png'])
64
+ expect(refused.map(one => one.reason)).to.deep.equal(['size'])
65
+ })
66
+
52
67
  it('reads the registered limits once and asks again after a failure', async () => {
53
68
  let calls = 0
54
69
  registerFileUploadLimits(async () => {