@instructure/ui-file-drop 10.14.1-snapshot-8 → 10.14.1-snapshot-11

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.
Files changed (28) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/es/FileDrop/__new-tests__/FileDrop.test.js +111 -12
  3. package/es/FileDrop/utils/__new-tests__/accepts.test.js +67 -0
  4. package/es/FileDrop/utils/__new-tests__/getEventFiles.test.js +69 -0
  5. package/lib/FileDrop/__new-tests__/FileDrop.test.js +111 -13
  6. package/lib/FileDrop/utils/__new-tests__/accepts.test.js +70 -0
  7. package/lib/FileDrop/utils/__new-tests__/getEventFiles.test.js +71 -0
  8. package/package.json +17 -15
  9. package/src/FileDrop/__new-tests__/FileDrop.test.tsx +106 -4
  10. package/src/FileDrop/utils/__new-tests__/accepts.test.tsx +72 -0
  11. package/src/FileDrop/utils/__new-tests__/getEventFiles.test.tsx +86 -0
  12. package/tsconfig.build.json +0 -1
  13. package/tsconfig.build.tsbuildinfo +1 -1
  14. package/types/FileDrop/__new-tests__/FileDrop.test.d.ts.map +1 -1
  15. package/types/FileDrop/utils/__new-tests__/accepts.test.d.ts +2 -0
  16. package/types/FileDrop/utils/__new-tests__/accepts.test.d.ts.map +1 -0
  17. package/types/FileDrop/utils/__new-tests__/getEventFiles.test.d.ts +2 -0
  18. package/types/FileDrop/utils/__new-tests__/getEventFiles.test.d.ts.map +1 -0
  19. package/es/FileDrop/FileDropLocator.js +0 -57
  20. package/es/FileDrop/locator.js +0 -27
  21. package/lib/FileDrop/FileDropLocator.js +0 -64
  22. package/lib/FileDrop/locator.js +0 -37
  23. package/src/FileDrop/FileDropLocator.ts +0 -42
  24. package/src/FileDrop/locator.ts +0 -28
  25. package/types/FileDrop/FileDropLocator.d.ts +0 -330
  26. package/types/FileDrop/FileDropLocator.d.ts.map +0 -1
  27. package/types/FileDrop/locator.d.ts +0 -4
  28. package/types/FileDrop/locator.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [10.14.1-snapshot-8](https://github.com/instructure/instructure-ui/compare/v10.14.0...v10.14.1-snapshot-8) (2025-03-28)
6
+ ## [10.14.1-snapshot-11](https://github.com/instructure/instructure-ui/compare/v10.14.0...v10.14.1-snapshot-11) (2025-03-28)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-file-drop
9
9
 
@@ -1,3 +1,4 @@
1
+ var _FileDrop, _FileDrop2, _FileDrop3, _FileDrop4, _FileDrop5, _FileDrop6, _section;
1
2
  /*
2
3
  * The MIT License (MIT)
3
4
  *
@@ -25,28 +26,126 @@
25
26
  import React from 'react';
26
27
  import { render } from '@testing-library/react';
27
28
  import { vi } from 'vitest';
29
+ import { runAxeCheck } from '@instructure/ui-axe-check';
28
30
  import '@testing-library/jest-dom';
29
31
  import { FileDrop } from '../index';
30
32
  describe('<FileDrop/>', () => {
31
33
  it('should focus the input when focus is called', async () => {
32
34
  let inputEl;
33
- render(/*#__PURE__*/React.createElement(FileDrop, {
34
- renderLabel: "filedrop",
35
- inputRef: el => {
36
- inputEl = el;
37
- }
38
- }));
39
- const input = document.querySelector('input[class$="-fileDrop__input"]');
35
+ const _render = render(/*#__PURE__*/React.createElement(FileDrop, {
36
+ renderLabel: "filedrop",
37
+ inputRef: el => {
38
+ inputEl = el;
39
+ }
40
+ })),
41
+ container = _render.container;
42
+ const input = container.querySelector('input[class$="-fileDrop__input"]');
40
43
  inputEl.focus();
41
44
  expect(input).toHaveFocus();
42
45
  });
43
46
  it('should provide an inputRef prop', async () => {
44
47
  const inputRef = vi.fn();
45
- render(/*#__PURE__*/React.createElement(FileDrop, {
46
- renderLabel: "filedrop",
47
- inputRef: inputRef
48
- }));
49
- const input = document.querySelector('input[class$="-fileDrop__input"]');
48
+ const _render2 = render(/*#__PURE__*/React.createElement(FileDrop, {
49
+ renderLabel: "filedrop",
50
+ inputRef: inputRef
51
+ })),
52
+ container = _render2.container;
53
+ const input = container.querySelector('input[class$="-fileDrop__input"]');
50
54
  expect(inputRef).toHaveBeenCalledWith(input);
51
55
  });
56
+ it('should render', async () => {
57
+ const _render3 = render(_FileDrop || (_FileDrop = /*#__PURE__*/React.createElement(FileDrop, {
58
+ renderLabel: "fake label"
59
+ }))),
60
+ container = _render3.container;
61
+ const fileDrop = container.querySelector('[class$="-fileDrop__input"]');
62
+ expect(fileDrop).toBeInTheDocument();
63
+ });
64
+ it('should meet a11y standards', async () => {
65
+ const _render4 = render(_FileDrop2 || (_FileDrop2 = /*#__PURE__*/React.createElement(FileDrop, {
66
+ renderLabel: "fake label"
67
+ }))),
68
+ container = _render4.container;
69
+ const axeCheck = await runAxeCheck(container);
70
+ expect(axeCheck).toBe(true);
71
+ });
72
+ describe('interactions', async () => {
73
+ it('should functionally disable the input if `interaction` is set to disabled', async () => {
74
+ const _render5 = render(_FileDrop3 || (_FileDrop3 = /*#__PURE__*/React.createElement(FileDrop, {
75
+ renderLabel: "Some label",
76
+ interaction: "disabled"
77
+ }))),
78
+ container = _render5.container;
79
+ const fileDrop = container.querySelector('[class$="-fileDrop__input"]');
80
+ expect(fileDrop).toBeDisabled();
81
+ });
82
+ it('should functionally disable the input if `disabled` is set', async () => {
83
+ const _render6 = render(_FileDrop4 || (_FileDrop4 = /*#__PURE__*/React.createElement(FileDrop, {
84
+ renderLabel: "Some label",
85
+ disabled: true
86
+ }))),
87
+ container = _render6.container;
88
+ const fileDrop = container.querySelector('[class$="-fileDrop__input"]');
89
+ expect(fileDrop).toBeDisabled();
90
+ });
91
+ it('should functionally disable the input if `interaction` is set to readonly', async () => {
92
+ const _render7 = render(_FileDrop5 || (_FileDrop5 = /*#__PURE__*/React.createElement(FileDrop, {
93
+ renderLabel: "Some label",
94
+ interaction: "readonly"
95
+ }))),
96
+ container = _render7.container;
97
+ const fileDrop = container.querySelector('[class$="-fileDrop__input"]');
98
+ expect(fileDrop).toBeDisabled();
99
+ });
100
+ it('should functionally disable the input if `readOnly` is set', async () => {
101
+ const _render8 = render(_FileDrop6 || (_FileDrop6 = /*#__PURE__*/React.createElement(FileDrop, {
102
+ renderLabel: "Some label",
103
+ readOnly: true
104
+ }))),
105
+ container = _render8.container;
106
+ const fileDrop = container.querySelector('[class$="-fileDrop__input"]');
107
+ expect(fileDrop).toBeDisabled();
108
+ });
109
+ });
110
+ describe('label handling', async () => {
111
+ it('renders element label directly', async () => {
112
+ const label = _section || (_section = /*#__PURE__*/React.createElement("section", {
113
+ id: "test-id"
114
+ }, "This is an element label"));
115
+ const _render9 = render(/*#__PURE__*/React.createElement(FileDrop, {
116
+ renderLabel: label
117
+ })),
118
+ container = _render9.container;
119
+ const renderedLabel = container.querySelector('[id="test-id"]');
120
+ expect(renderedLabel).toBeInTheDocument();
121
+ });
122
+ it('passes isDragAccepted and isDragRejected boolean props to component label', async () => {
123
+ let result = {};
124
+ const label = props => {
125
+ result = {
126
+ ...props
127
+ };
128
+ return null;
129
+ };
130
+ render(/*#__PURE__*/React.createElement(FileDrop, {
131
+ renderLabel: label
132
+ }));
133
+ expect(typeof result.isDragAccepted).toBe('boolean');
134
+ expect(typeof result.isDragRejected).toBe('boolean');
135
+ });
136
+ it(`label component's props are false by default`, async () => {
137
+ let result = {};
138
+ const label = props => {
139
+ result = {
140
+ ...props
141
+ };
142
+ return null;
143
+ };
144
+ render(/*#__PURE__*/React.createElement(FileDrop, {
145
+ renderLabel: label
146
+ }));
147
+ expect(result.isDragAccepted).toBe(false);
148
+ expect(result.isDragRejected).toBe(false);
149
+ });
150
+ });
52
151
  });
@@ -0,0 +1,67 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import { expect } from 'vitest';
25
+ import { accepts } from '../accepts';
26
+ describe('accepts', () => {
27
+ const dropImage = new File([], 'whale whale whale.jpg', {
28
+ type: 'image/jpeg'
29
+ });
30
+ const dropFile = new File([], 'whale oil production.pdf', {
31
+ type: 'application/pdf'
32
+ });
33
+ const chromeDragEnterFile = new File([], '', {
34
+ type: 'image/jpeg'
35
+ });
36
+ const firefoxDragEnterFile = new File([], '', {
37
+ type: 'application/x-moz-file'
38
+ });
39
+ it('should take image/* to mean any image type', () => {
40
+ expect(accepts(dropImage, 'image/*')).toBe(true);
41
+ });
42
+ it('should reject anything that is not an image, given image/*', () => {
43
+ expect(accepts(dropFile, 'image/*')).toBe(false);
44
+ });
45
+ it('should match the exact file extensions given', () => {
46
+ expect(accepts(dropImage, '.jpg')).toBe(true);
47
+ expect(accepts(dropImage, '.jpg, .png')).toBe(true);
48
+ expect(accepts(dropImage, '.png')).toBe(false);
49
+ expect(accepts(dropFile, '.jpg, .pdf')).toBe(true);
50
+ expect(accepts(dropFile, '.jpg, .pdf')).toBe(true);
51
+ });
52
+ it('should handle chrome dragenter file data', () => {
53
+ expect(accepts(chromeDragEnterFile, 'image/*')).toBe(true);
54
+ expect(accepts(chromeDragEnterFile, '.jpeg')).toBe(true);
55
+ expect(accepts(chromeDragEnterFile, '.png')).not.toBe(true);
56
+ expect(accepts(chromeDragEnterFile, '.pdf')).not.toBe(true);
57
+ });
58
+ it(`should always be true for firefox's dragenter file data`, () => {
59
+ expect(accepts(firefoxDragEnterFile, 'image/*')).toBe(true);
60
+ expect(accepts(firefoxDragEnterFile, '.jpeg')).toBe(true);
61
+ expect(accepts(firefoxDragEnterFile, '.png')).toBe(true);
62
+ expect(accepts(firefoxDragEnterFile, '.pdf')).toBe(true);
63
+ });
64
+ it('allows extensions without leading dot', () => {
65
+ expect(accepts(dropImage, 'jpg, png')).toBe(true);
66
+ });
67
+ });
@@ -0,0 +1,69 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { expect } from 'vitest';
26
+ import { getEventFiles } from '../getEventFiles';
27
+ describe('getEventFiles', () => {
28
+ const chromeDragEnter = {
29
+ dataTransfer: {
30
+ dropEffect: 'none',
31
+ effectAllowed: 'all',
32
+ files: [],
33
+ items: [{
34
+ kind: 'file',
35
+ type: 'image/jpeg'
36
+ }],
37
+ types: ['Files']
38
+ }
39
+ };
40
+ const firefoxDragEnter = {
41
+ dataTransfer: {
42
+ dropEffect: 'move',
43
+ effectAllowed: 'uninitialized',
44
+ files: [],
45
+ items: [{
46
+ kind: 'file',
47
+ type: 'application/x-moz-file'
48
+ }],
49
+ types: ['application/x-moz-file', 'Files']
50
+ }
51
+ };
52
+ const safariDragEnter = {
53
+ dataTransfer: {
54
+ dropEffect: 'none',
55
+ effectAllowed: 'all',
56
+ files: [],
57
+ types: []
58
+ }
59
+ };
60
+ it('should return items on chrome dragenter event', () => {
61
+ expect(getEventFiles(chromeDragEnter)).toEqual(chromeDragEnter.dataTransfer.items);
62
+ });
63
+ it('should return items on a firefox dragenter event', () => {
64
+ expect(getEventFiles(firefoxDragEnter)).toEqual(firefoxDragEnter.dataTransfer.items);
65
+ });
66
+ it('should return empty array on a safari dragenter event', () => {
67
+ expect(getEventFiles(safariDragEnter).length).toEqual(0);
68
+ });
69
+ });
@@ -4,8 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  var _react = _interopRequireDefault(require("react"));
5
5
  var _react2 = require("@testing-library/react");
6
6
  var _vitest = require("vitest");
7
+ var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
7
8
  require("@testing-library/jest-dom");
8
9
  var _index = require("../index");
10
+ var _FileDrop, _FileDrop2, _FileDrop3, _FileDrop4, _FileDrop5, _FileDrop6, _section;
9
11
  /*
10
12
  * The MIT License (MIT)
11
13
  *
@@ -29,27 +31,123 @@ var _index = require("../index");
29
31
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
32
  * SOFTWARE.
31
33
  */
32
-
33
34
  describe('<FileDrop/>', () => {
34
35
  it('should focus the input when focus is called', async () => {
35
36
  let inputEl;
36
- (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.FileDrop, {
37
- renderLabel: "filedrop",
38
- inputRef: el => {
39
- inputEl = el;
40
- }
41
- }));
42
- const input = document.querySelector('input[class$="-fileDrop__input"]');
37
+ const _render = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.FileDrop, {
38
+ renderLabel: "filedrop",
39
+ inputRef: el => {
40
+ inputEl = el;
41
+ }
42
+ })),
43
+ container = _render.container;
44
+ const input = container.querySelector('input[class$="-fileDrop__input"]');
43
45
  inputEl.focus();
44
46
  expect(input).toHaveFocus();
45
47
  });
46
48
  it('should provide an inputRef prop', async () => {
47
49
  const inputRef = _vitest.vi.fn();
48
- (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.FileDrop, {
49
- renderLabel: "filedrop",
50
- inputRef: inputRef
51
- }));
52
- const input = document.querySelector('input[class$="-fileDrop__input"]');
50
+ const _render2 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.FileDrop, {
51
+ renderLabel: "filedrop",
52
+ inputRef: inputRef
53
+ })),
54
+ container = _render2.container;
55
+ const input = container.querySelector('input[class$="-fileDrop__input"]');
53
56
  expect(inputRef).toHaveBeenCalledWith(input);
54
57
  });
58
+ it('should render', async () => {
59
+ const _render3 = (0, _react2.render)(_FileDrop || (_FileDrop = /*#__PURE__*/_react.default.createElement(_index.FileDrop, {
60
+ renderLabel: "fake label"
61
+ }))),
62
+ container = _render3.container;
63
+ const fileDrop = container.querySelector('[class$="-fileDrop__input"]');
64
+ expect(fileDrop).toBeInTheDocument();
65
+ });
66
+ it('should meet a11y standards', async () => {
67
+ const _render4 = (0, _react2.render)(_FileDrop2 || (_FileDrop2 = /*#__PURE__*/_react.default.createElement(_index.FileDrop, {
68
+ renderLabel: "fake label"
69
+ }))),
70
+ container = _render4.container;
71
+ const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
72
+ expect(axeCheck).toBe(true);
73
+ });
74
+ describe('interactions', async () => {
75
+ it('should functionally disable the input if `interaction` is set to disabled', async () => {
76
+ const _render5 = (0, _react2.render)(_FileDrop3 || (_FileDrop3 = /*#__PURE__*/_react.default.createElement(_index.FileDrop, {
77
+ renderLabel: "Some label",
78
+ interaction: "disabled"
79
+ }))),
80
+ container = _render5.container;
81
+ const fileDrop = container.querySelector('[class$="-fileDrop__input"]');
82
+ expect(fileDrop).toBeDisabled();
83
+ });
84
+ it('should functionally disable the input if `disabled` is set', async () => {
85
+ const _render6 = (0, _react2.render)(_FileDrop4 || (_FileDrop4 = /*#__PURE__*/_react.default.createElement(_index.FileDrop, {
86
+ renderLabel: "Some label",
87
+ disabled: true
88
+ }))),
89
+ container = _render6.container;
90
+ const fileDrop = container.querySelector('[class$="-fileDrop__input"]');
91
+ expect(fileDrop).toBeDisabled();
92
+ });
93
+ it('should functionally disable the input if `interaction` is set to readonly', async () => {
94
+ const _render7 = (0, _react2.render)(_FileDrop5 || (_FileDrop5 = /*#__PURE__*/_react.default.createElement(_index.FileDrop, {
95
+ renderLabel: "Some label",
96
+ interaction: "readonly"
97
+ }))),
98
+ container = _render7.container;
99
+ const fileDrop = container.querySelector('[class$="-fileDrop__input"]');
100
+ expect(fileDrop).toBeDisabled();
101
+ });
102
+ it('should functionally disable the input if `readOnly` is set', async () => {
103
+ const _render8 = (0, _react2.render)(_FileDrop6 || (_FileDrop6 = /*#__PURE__*/_react.default.createElement(_index.FileDrop, {
104
+ renderLabel: "Some label",
105
+ readOnly: true
106
+ }))),
107
+ container = _render8.container;
108
+ const fileDrop = container.querySelector('[class$="-fileDrop__input"]');
109
+ expect(fileDrop).toBeDisabled();
110
+ });
111
+ });
112
+ describe('label handling', async () => {
113
+ it('renders element label directly', async () => {
114
+ const label = _section || (_section = /*#__PURE__*/_react.default.createElement("section", {
115
+ id: "test-id"
116
+ }, "This is an element label"));
117
+ const _render9 = (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.FileDrop, {
118
+ renderLabel: label
119
+ })),
120
+ container = _render9.container;
121
+ const renderedLabel = container.querySelector('[id="test-id"]');
122
+ expect(renderedLabel).toBeInTheDocument();
123
+ });
124
+ it('passes isDragAccepted and isDragRejected boolean props to component label', async () => {
125
+ let result = {};
126
+ const label = props => {
127
+ result = {
128
+ ...props
129
+ };
130
+ return null;
131
+ };
132
+ (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.FileDrop, {
133
+ renderLabel: label
134
+ }));
135
+ expect(typeof result.isDragAccepted).toBe('boolean');
136
+ expect(typeof result.isDragRejected).toBe('boolean');
137
+ });
138
+ it(`label component's props are false by default`, async () => {
139
+ let result = {};
140
+ const label = props => {
141
+ result = {
142
+ ...props
143
+ };
144
+ return null;
145
+ };
146
+ (0, _react2.render)(/*#__PURE__*/_react.default.createElement(_index.FileDrop, {
147
+ renderLabel: label
148
+ }));
149
+ expect(result.isDragAccepted).toBe(false);
150
+ expect(result.isDragRejected).toBe(false);
151
+ });
152
+ });
55
153
  });
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _accepts = require("../accepts");
5
+ /*
6
+ * The MIT License (MIT)
7
+ *
8
+ * Copyright (c) 2015 - present Instructure, Inc.
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ * of this software and associated documentation files (the "Software"), to deal
12
+ * in the Software without restriction, including without limitation the rights
13
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ * copies of the Software, and to permit persons to whom the Software is
15
+ * furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all
18
+ * copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ * SOFTWARE.
27
+ */
28
+
29
+ describe('accepts', () => {
30
+ const dropImage = new File([], 'whale whale whale.jpg', {
31
+ type: 'image/jpeg'
32
+ });
33
+ const dropFile = new File([], 'whale oil production.pdf', {
34
+ type: 'application/pdf'
35
+ });
36
+ const chromeDragEnterFile = new File([], '', {
37
+ type: 'image/jpeg'
38
+ });
39
+ const firefoxDragEnterFile = new File([], '', {
40
+ type: 'application/x-moz-file'
41
+ });
42
+ it('should take image/* to mean any image type', () => {
43
+ (0, _vitest.expect)((0, _accepts.accepts)(dropImage, 'image/*')).toBe(true);
44
+ });
45
+ it('should reject anything that is not an image, given image/*', () => {
46
+ (0, _vitest.expect)((0, _accepts.accepts)(dropFile, 'image/*')).toBe(false);
47
+ });
48
+ it('should match the exact file extensions given', () => {
49
+ (0, _vitest.expect)((0, _accepts.accepts)(dropImage, '.jpg')).toBe(true);
50
+ (0, _vitest.expect)((0, _accepts.accepts)(dropImage, '.jpg, .png')).toBe(true);
51
+ (0, _vitest.expect)((0, _accepts.accepts)(dropImage, '.png')).toBe(false);
52
+ (0, _vitest.expect)((0, _accepts.accepts)(dropFile, '.jpg, .pdf')).toBe(true);
53
+ (0, _vitest.expect)((0, _accepts.accepts)(dropFile, '.jpg, .pdf')).toBe(true);
54
+ });
55
+ it('should handle chrome dragenter file data', () => {
56
+ (0, _vitest.expect)((0, _accepts.accepts)(chromeDragEnterFile, 'image/*')).toBe(true);
57
+ (0, _vitest.expect)((0, _accepts.accepts)(chromeDragEnterFile, '.jpeg')).toBe(true);
58
+ (0, _vitest.expect)((0, _accepts.accepts)(chromeDragEnterFile, '.png')).not.toBe(true);
59
+ (0, _vitest.expect)((0, _accepts.accepts)(chromeDragEnterFile, '.pdf')).not.toBe(true);
60
+ });
61
+ it(`should always be true for firefox's dragenter file data`, () => {
62
+ (0, _vitest.expect)((0, _accepts.accepts)(firefoxDragEnterFile, 'image/*')).toBe(true);
63
+ (0, _vitest.expect)((0, _accepts.accepts)(firefoxDragEnterFile, '.jpeg')).toBe(true);
64
+ (0, _vitest.expect)((0, _accepts.accepts)(firefoxDragEnterFile, '.png')).toBe(true);
65
+ (0, _vitest.expect)((0, _accepts.accepts)(firefoxDragEnterFile, '.pdf')).toBe(true);
66
+ });
67
+ it('allows extensions without leading dot', () => {
68
+ (0, _vitest.expect)((0, _accepts.accepts)(dropImage, 'jpg, png')).toBe(true);
69
+ });
70
+ });
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _getEventFiles = require("../getEventFiles");
5
+ /*
6
+ * The MIT License (MIT)
7
+ *
8
+ * Copyright (c) 2015 - present Instructure, Inc.
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ * of this software and associated documentation files (the "Software"), to deal
12
+ * in the Software without restriction, including without limitation the rights
13
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ * copies of the Software, and to permit persons to whom the Software is
15
+ * furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all
18
+ * copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ * SOFTWARE.
27
+ */
28
+
29
+ describe('getEventFiles', () => {
30
+ const chromeDragEnter = {
31
+ dataTransfer: {
32
+ dropEffect: 'none',
33
+ effectAllowed: 'all',
34
+ files: [],
35
+ items: [{
36
+ kind: 'file',
37
+ type: 'image/jpeg'
38
+ }],
39
+ types: ['Files']
40
+ }
41
+ };
42
+ const firefoxDragEnter = {
43
+ dataTransfer: {
44
+ dropEffect: 'move',
45
+ effectAllowed: 'uninitialized',
46
+ files: [],
47
+ items: [{
48
+ kind: 'file',
49
+ type: 'application/x-moz-file'
50
+ }],
51
+ types: ['application/x-moz-file', 'Files']
52
+ }
53
+ };
54
+ const safariDragEnter = {
55
+ dataTransfer: {
56
+ dropEffect: 'none',
57
+ effectAllowed: 'all',
58
+ files: [],
59
+ types: []
60
+ }
61
+ };
62
+ it('should return items on chrome dragenter event', () => {
63
+ (0, _vitest.expect)((0, _getEventFiles.getEventFiles)(chromeDragEnter)).toEqual(chromeDragEnter.dataTransfer.items);
64
+ });
65
+ it('should return items on a firefox dragenter event', () => {
66
+ (0, _vitest.expect)((0, _getEventFiles.getEventFiles)(firefoxDragEnter)).toEqual(firefoxDragEnter.dataTransfer.items);
67
+ });
68
+ it('should return empty array on a safari dragenter event', () => {
69
+ (0, _vitest.expect)((0, _getEventFiles.getEventFiles)(safariDragEnter).length).toEqual(0);
70
+ });
71
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-file-drop",
3
- "version": "10.14.1-snapshot-8",
3
+ "version": "10.14.1-snapshot-11",
4
4
  "description": "A flexible facade for an HTML file input",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -24,24 +24,26 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.26.0",
27
- "@instructure/console": "10.14.1-snapshot-8",
28
- "@instructure/emotion": "10.14.1-snapshot-8",
29
- "@instructure/shared-types": "10.14.1-snapshot-8",
30
- "@instructure/ui-color-utils": "10.14.1-snapshot-8",
31
- "@instructure/ui-form-field": "10.14.1-snapshot-8",
32
- "@instructure/ui-react-utils": "10.14.1-snapshot-8",
33
- "@instructure/ui-testable": "10.14.1-snapshot-8",
34
- "@instructure/ui-utils": "10.14.1-snapshot-8",
35
- "@instructure/ui-view": "10.14.1-snapshot-8",
36
- "@instructure/uid": "10.14.1-snapshot-8",
27
+ "@instructure/console": "10.14.1-snapshot-11",
28
+ "@instructure/emotion": "10.14.1-snapshot-11",
29
+ "@instructure/shared-types": "10.14.1-snapshot-11",
30
+ "@instructure/ui-color-utils": "10.14.1-snapshot-11",
31
+ "@instructure/ui-form-field": "10.14.1-snapshot-11",
32
+ "@instructure/ui-react-utils": "10.14.1-snapshot-11",
33
+ "@instructure/ui-testable": "10.14.1-snapshot-11",
34
+ "@instructure/ui-utils": "10.14.1-snapshot-11",
35
+ "@instructure/ui-view": "10.14.1-snapshot-11",
36
+ "@instructure/uid": "10.14.1-snapshot-11",
37
37
  "keycode": "^2",
38
38
  "prop-types": "^15.8.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@instructure/ui-babel-preset": "10.14.1-snapshot-8",
42
- "@instructure/ui-test-locator": "10.14.1-snapshot-8",
43
- "@instructure/ui-test-utils": "10.14.1-snapshot-8",
44
- "@instructure/ui-themes": "10.14.1-snapshot-8"
41
+ "@instructure/ui-babel-preset": "10.14.1-snapshot-11",
42
+ "@instructure/ui-test-utils": "10.14.1-snapshot-11",
43
+ "@instructure/ui-themes": "10.14.1-snapshot-11",
44
+ "@testing-library/jest-dom": "^6.6.3",
45
+ "@testing-library/react": "^16.0.1",
46
+ "vitest": "^2.1.8"
45
47
  },
46
48
  "peerDependencies": {
47
49
  "react": ">=16.14 <=18"