@instructure/ui-file-drop 10.19.2-snapshot-2 → 10.19.2-snapshot-4

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,158 +0,0 @@
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 { render } from '@testing-library/react'
26
- import { vi } from 'vitest'
27
- import { runAxeCheck } from '@instructure/ui-axe-check'
28
- import '@testing-library/jest-dom'
29
-
30
- import { FileDrop } from '../index'
31
- import { FileDropProps } from '../props'
32
-
33
- describe('<FileDrop/>', () => {
34
- it('should focus the input when focus is called', async () => {
35
- let inputEl: any
36
- const { container } = render(
37
- <FileDrop
38
- renderLabel="filedrop"
39
- inputRef={(el: HTMLInputElement | null) => {
40
- inputEl = el
41
- }}
42
- />
43
- )
44
- const input = container.querySelector('input[class$="-fileDrop__input"]')
45
-
46
- inputEl.focus()
47
-
48
- expect(input).toHaveFocus()
49
- })
50
-
51
- it('should provide an inputRef prop', async () => {
52
- const inputRef = vi.fn()
53
- const { container } = render(
54
- <FileDrop renderLabel="filedrop" inputRef={inputRef} />
55
- )
56
- const input = container.querySelector('input[class$="-fileDrop__input"]')
57
-
58
- expect(inputRef).toHaveBeenCalledWith(input)
59
- })
60
-
61
- it('should render', async () => {
62
- const { container } = render(<FileDrop renderLabel="fake label" />)
63
- const fileDrop = container.querySelector('[class$="-fileDrop__input"]')
64
-
65
- expect(fileDrop).toBeInTheDocument()
66
- })
67
-
68
- it('should meet a11y standards', async () => {
69
- const { container } = render(<FileDrop renderLabel="fake label" />)
70
- const axeCheck = await runAxeCheck(container)
71
- expect(axeCheck).toBe(true)
72
- })
73
-
74
- describe('interactions', async () => {
75
- it('should functionally disable the input if `interaction` is set to disabled', async () => {
76
- const { container } = render(
77
- <FileDrop renderLabel="Some label" interaction="disabled" />
78
- )
79
- const fileDrop = container.querySelector('[class$="-fileDrop__input"]')
80
-
81
- expect(fileDrop).toBeDisabled()
82
- })
83
-
84
- it('should functionally disable the input if `disabled` is set', async () => {
85
- const { container } = render(
86
- <FileDrop renderLabel="Some label" disabled />
87
- )
88
- const fileDrop = container.querySelector('[class$="-fileDrop__input"]')
89
-
90
- expect(fileDrop).toBeDisabled()
91
- })
92
-
93
- it('should functionally disable the input if `interaction` is set to readonly', async () => {
94
- const { container } = render(
95
- <FileDrop renderLabel="Some label" interaction="readonly" />
96
- )
97
- const fileDrop = container.querySelector('[class$="-fileDrop__input"]')
98
-
99
- expect(fileDrop).toBeDisabled()
100
- })
101
-
102
- it('should functionally disable the input if `readOnly` is set', async () => {
103
- const { container } = render(
104
- <FileDrop renderLabel="Some label" readOnly />
105
- )
106
- const fileDrop = container.querySelector('[class$="-fileDrop__input"]')
107
-
108
- expect(fileDrop).toBeDisabled()
109
- })
110
- })
111
-
112
- describe('label handling', async () => {
113
- it('renders element label directly', async () => {
114
- const label = <section id="test-id">This is an element label</section>
115
- const { container } = render(<FileDrop renderLabel={label} />)
116
-
117
- const renderedLabel = container.querySelector('[id="test-id"]')
118
-
119
- expect(renderedLabel).toBeInTheDocument()
120
- })
121
-
122
- it('passes isDragAccepted and isDragRejected boolean props to component label', async () => {
123
- type RenderLabelProps = {
124
- isDragAccepted: boolean
125
- isDragRejected: boolean
126
- interaction?: string
127
- }
128
- let result: RenderLabelProps = {} as RenderLabelProps
129
- const label: FileDropProps['renderLabel'] = (props) => {
130
- result = { ...props }
131
- return null
132
- }
133
-
134
- render(<FileDrop renderLabel={label} />)
135
-
136
- expect(typeof result.isDragAccepted).toBe('boolean')
137
- expect(typeof result.isDragRejected).toBe('boolean')
138
- })
139
-
140
- it(`label component's props are false by default`, async () => {
141
- type RenderLabelProps = {
142
- isDragAccepted: boolean
143
- isDragRejected: boolean
144
- interaction?: string
145
- }
146
- let result: RenderLabelProps = {} as RenderLabelProps
147
- const label: FileDropProps['renderLabel'] = (props) => {
148
- result = { ...props }
149
- return null
150
- }
151
-
152
- render(<FileDrop renderLabel={label} />)
153
-
154
- expect(result.isDragAccepted).toBe(false)
155
- expect(result.isDragRejected).toBe(false)
156
- })
157
- })
158
- })
@@ -1,72 +0,0 @@
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
-
27
- describe('accepts', () => {
28
- const dropImage = new File([], 'whale whale whale.jpg', {
29
- type: 'image/jpeg'
30
- })
31
- const dropFile = new File([], 'whale oil production.pdf', {
32
- type: 'application/pdf'
33
- })
34
- const chromeDragEnterFile = new File([], '', { type: 'image/jpeg' })
35
- const firefoxDragEnterFile = new File([], '', {
36
- type: 'application/x-moz-file'
37
- })
38
-
39
- it('should take image/* to mean any image type', () => {
40
- expect(accepts(dropImage, 'image/*')).toBe(true)
41
- })
42
-
43
- it('should reject anything that is not an image, given image/*', () => {
44
- expect(accepts(dropFile, 'image/*')).toBe(false)
45
- })
46
-
47
- it('should match the exact file extensions given', () => {
48
- expect(accepts(dropImage, '.jpg')).toBe(true)
49
- expect(accepts(dropImage, '.jpg, .png')).toBe(true)
50
- expect(accepts(dropImage, '.png')).toBe(false)
51
- expect(accepts(dropFile, '.jpg, .pdf')).toBe(true)
52
- expect(accepts(dropFile, '.jpg, .pdf')).toBe(true)
53
- })
54
-
55
- it('should handle chrome dragenter file data', () => {
56
- expect(accepts(chromeDragEnterFile, 'image/*')).toBe(true)
57
- expect(accepts(chromeDragEnterFile, '.jpeg')).toBe(true)
58
- expect(accepts(chromeDragEnterFile, '.png')).not.toBe(true)
59
- expect(accepts(chromeDragEnterFile, '.pdf')).not.toBe(true)
60
- })
61
-
62
- it(`should always be true for firefox's dragenter file data`, () => {
63
- expect(accepts(firefoxDragEnterFile, 'image/*')).toBe(true)
64
- expect(accepts(firefoxDragEnterFile, '.jpeg')).toBe(true)
65
- expect(accepts(firefoxDragEnterFile, '.png')).toBe(true)
66
- expect(accepts(firefoxDragEnterFile, '.pdf')).toBe(true)
67
- })
68
-
69
- it('allows extensions without leading dot', () => {
70
- expect(accepts(dropImage, 'jpg, png')).toBe(true)
71
- })
72
- })
@@ -1,86 +0,0 @@
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 React from 'react'
26
- import { expect } from 'vitest'
27
- import { getEventFiles } from '../getEventFiles'
28
-
29
- describe('getEventFiles', () => {
30
- const chromeDragEnter = {
31
- dataTransfer: {
32
- dropEffect: 'none',
33
- effectAllowed: 'all',
34
- files: [],
35
- items: [
36
- {
37
- kind: 'file',
38
- type: 'image/jpeg'
39
- }
40
- ],
41
- types: ['Files']
42
- }
43
- }
44
-
45
- const firefoxDragEnter = {
46
- dataTransfer: {
47
- dropEffect: 'move',
48
- effectAllowed: 'uninitialized',
49
- files: [],
50
- items: [
51
- {
52
- kind: 'file',
53
- type: 'application/x-moz-file'
54
- }
55
- ],
56
- types: ['application/x-moz-file', 'Files']
57
- }
58
- }
59
-
60
- const safariDragEnter = {
61
- dataTransfer: {
62
- dropEffect: 'none',
63
- effectAllowed: 'all',
64
- files: [],
65
- types: []
66
- }
67
- }
68
-
69
- it('should return items on chrome dragenter event', () => {
70
- expect(
71
- getEventFiles(chromeDragEnter as unknown as React.DragEvent)
72
- ).toEqual(chromeDragEnter.dataTransfer.items)
73
- })
74
-
75
- it('should return items on a firefox dragenter event', () => {
76
- expect(
77
- getEventFiles(firefoxDragEnter as unknown as React.DragEvent)
78
- ).toEqual(firefoxDragEnter.dataTransfer.items)
79
- })
80
-
81
- it('should return empty array on a safari dragenter event', () => {
82
- expect(
83
- getEventFiles(safariDragEnter as unknown as React.DragEvent).length
84
- ).toEqual(0)
85
- })
86
- })
@@ -1,2 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- //# sourceMappingURL=FileDrop.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FileDrop.test.d.ts","sourceRoot":"","sources":["../../../src/FileDrop/__new-tests__/FileDrop.test.tsx"],"names":[],"mappings":"AA2BA,OAAO,2BAA2B,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=accepts.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accepts.test.d.ts","sourceRoot":"","sources":["../../../../src/FileDrop/utils/__new-tests__/accepts.test.tsx"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=getEventFiles.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getEventFiles.test.d.ts","sourceRoot":"","sources":["../../../../src/FileDrop/utils/__new-tests__/getEventFiles.test.tsx"],"names":[],"mappings":""}