Skip to content

Commit 0ec6973

Browse files
committed
Update tests
1 parent 8eafd07 commit 0ec6973

File tree

5 files changed

+71
-15
lines changed

5 files changed

+71
-15
lines changed

src/file-upload-input/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import * as fixedCss from './styles/file-upload-input.m.css';
1414
import * as labelCss from '../theme/default/label.m.css';
1515

1616
export interface FileUploadInputChildren {
17+
/** The label to be displayed above the input */
1718
label?: RenderResult;
19+
20+
/** Content to be rendered within the widget area */
1821
content?: RenderResult;
1922
}
2023

@@ -43,7 +46,7 @@ export interface FileUploadInputProperties {
4346
/** The `required` attribute of the input */
4447
required?: boolean;
4548

46-
/** Represents if the input value is valid */
49+
/** Represents if the selected files passed validation */
4750
valid?: ValidationInfo | boolean;
4851

4952
/** The id to be applied to the input */
@@ -122,7 +125,7 @@ export const FileUploadInput = factory(function FileUploadInput({
122125
} = properties();
123126
const { messages } = i18n.localize(bundle);
124127
const themeCss = theme.classes(css);
125-
const { content = null, label = null } = children()[0] || {};
128+
const [{ content, label } = { content: undefined, label: undefined }] = children();
126129
let isDndActive = icache.getOrSet('isDndActive', false);
127130

128131
function onDragEnter(event: DragEvent) {

src/file-upload-input/tests/unit/FileUploadInput.spec.tsx

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const { messages } = bundle;
1717

1818
describe('FileUploadInput', function() {
1919
const WrappedRoot = wrap('div');
20+
const WrappedWrapper = wrap('div');
2021
const WrappedLabel = wrap('span');
22+
2123
const baseRootProperties = {
2224
key: 'root',
2325
classes: [null, fixedCss.root, css.root, false, false],
@@ -29,7 +31,7 @@ describe('FileUploadInput', function() {
2931
const baseAssertion = assertion(function() {
3032
return (
3133
<WrappedRoot {...baseRootProperties}>
32-
<div classes={[css.wrapper]}>
34+
<WrappedWrapper classes={[css.wrapper]}>
3335
<input
3436
key="nativeInput"
3537
accept={undefined}
@@ -60,7 +62,7 @@ describe('FileUploadInput', function() {
6062
</Button>
6163

6264
<WrappedLabel classes={[css.dndLabel]}>{messages.orDropFilesHere}</WrappedLabel>
63-
</div>
65+
</WrappedWrapper>
6466
</WrappedRoot>
6567
);
6668
});
@@ -73,6 +75,22 @@ describe('FileUploadInput', function() {
7375
r.expect(baseAssertion);
7476
});
7577

78+
it('renders content', function() {
79+
const content = <div>some content</div>;
80+
81+
const r = renderer(function() {
82+
return (
83+
<FileUploadInput>
84+
{{
85+
content
86+
}}
87+
</FileUploadInput>
88+
);
89+
});
90+
91+
r.expect(baseAssertion.insertAfter(WrappedWrapper, () => [content]));
92+
});
93+
7694
it('renders label', function() {
7795
const label = 'Widget label';
7896

@@ -130,4 +148,39 @@ describe('FileUploadInput', function() {
130148
.remove(WrappedLabel)
131149
);
132150
});
151+
152+
it('handles dragenter, dragleave, and the overlay', function() {
153+
const r = renderer(function() {
154+
return <FileUploadInput />;
155+
});
156+
const WrappedOverlay = wrap('div');
157+
158+
r.expect(baseAssertion);
159+
r.property(WrappedRoot, 'ondragenter', { preventDefault: noop });
160+
161+
r.expect(
162+
baseAssertion
163+
.setProperty(WrappedRoot, 'classes', [
164+
null,
165+
fixedCss.root,
166+
css.root,
167+
css.dndActive,
168+
false
169+
])
170+
.append(WrappedRoot, function() {
171+
return [
172+
<WrappedOverlay
173+
key="overlay"
174+
classes={[fixedCss.dndOverlay, css.dndOverlay, false]}
175+
ondragleave={noop}
176+
/>
177+
];
178+
})
179+
);
180+
181+
// TODO: enable when testing bug is fixed
182+
// https://github.com/dojo/framework/issues/839
183+
// r.property(WrappedOverlay, 'ondragleave');
184+
// r.expect(baseAssertion);
185+
});
133186
});

src/file-uploader/index.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,17 @@ export const FileUploader = factory(function FileUploader({
177177
if (files.length) {
178178
inputChild.content = (
179179
<div key="fileList">
180-
{renderFiles({
181-
customValidator,
182-
files,
183-
maxSize,
184-
messages: { messages },
185-
remove,
186-
showSize,
187-
themeCss
188-
})}
180+
{function() {
181+
return renderFiles({
182+
customValidator,
183+
files,
184+
maxSize,
185+
messages: { messages },
186+
remove,
187+
showSize,
188+
themeCss
189+
});
190+
}}
189191
</div>
190192
);
191193
}

src/theme/dojo/file-uploader.m.css.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export const root: string;
2-
export const dndActive: string;
32
export const disabled: string;
43
export const fileItem: string;
54
export const fileInfo: string;

src/theme/material/file-uploader.m.css.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export const root: string;
2-
export const dndActive: string;
32
export const disabled: string;
43
export const fileItem: string;
54
export const fileInfo: string;

0 commit comments

Comments
 (0)