Skip to content

Commit 9ffb246

Browse files
committed
Update tests
1 parent 25f3046 commit 9ffb246

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

src/file-upload-input/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ export const FileUploadInput = factory(function FileUploadInput({
165165
}
166166

167167
function onChange(event: DojoEvent<HTMLInputElement>) {
168-
console.log('onChange', event);
169168
if (onValue && event.target.files && event.target.files.length) {
170169
onValue(Array.from(event.target.files));
171170
}

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

+8-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { tsx } from '@dojo/framework/core/vdom';
22
import { assertion, renderer, wrap } from '@dojo/framework/testing/renderer';
3+
import * as sinon from 'sinon';
34
import { Button } from '../../../button';
45
import { FileUploadInput } from '../../index';
56
import { Label } from '../../../label';
@@ -209,11 +210,7 @@ describe('FileUploadInput', function() {
209210

210211
it('handles file drop event', function() {
211212
const testValues = [1, 2, 3];
212-
let receivedFiles: number[] = [];
213-
214-
function onValue(value: any[]) {
215-
receivedFiles = value;
216-
}
213+
const onValue = sinon.stub();
217214

218215
const r = renderer(function() {
219216
return <FileUploadInput onValue={onValue} />;
@@ -228,7 +225,7 @@ describe('FileUploadInput', function() {
228225
});
229226
r.expect(baseAssertion);
230227

231-
assert.sameOrderedMembers(receivedFiles, testValues);
228+
assert.sameOrderedMembers(onValue.firstCall.args[0], testValues);
232229
});
233230

234231
it('validates files based on "accept"', function() {
@@ -240,11 +237,7 @@ describe('FileUploadInput', function() {
240237
{ name: 'file4.doc', type: 'application/word' } // test match failure
241238
];
242239
const validFiles = testFiles.slice(0, 3);
243-
let receivedFiles: Array<typeof testFiles[0]> = [];
244-
245-
function onValue(value: any[]) {
246-
receivedFiles = value;
247-
}
240+
const onValue = sinon.stub();
248241

249242
const r = renderer(function() {
250243
return <FileUploadInput onValue={onValue} accept={accept} />;
@@ -260,16 +253,12 @@ describe('FileUploadInput', function() {
260253
});
261254
r.expect(acceptAssertion);
262255

263-
assert.sameOrderedMembers(receivedFiles, validFiles);
256+
assert.sameOrderedMembers(onValue.firstCall.args[0], validFiles);
264257
});
265258

266259
it('calls onValue when files are selected from input', function() {
267260
const testValues = [1, 2, 3];
268-
let receivedFiles: number[] = [];
269-
270-
function onValue(value: any[]) {
271-
receivedFiles = value;
272-
}
261+
const onValue = sinon.stub();
273262

274263
const r = renderer(function() {
275264
return <FileUploadInput onValue={onValue} />;
@@ -281,9 +270,9 @@ describe('FileUploadInput', function() {
281270
files: testValues
282271
}
283272
});
284-
// TODO: the queued onchange is not triggering because it is for a node with a different id than expected
285273
r.expect(baseAssertion);
286274

287-
assert.sameOrderedMembers(receivedFiles, testValues);
275+
// TODO: enable when https://github.com/dojo/framework/pull/840 is merged
276+
// assert.sameOrderedMembers(onValue.firstCall.args[0], testValues);
288277
});
289278
});

src/file-uploader/index.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import * as css from '../theme/default/file-uploader.m.css';
1616
import * as fileUploadInputCss from '../theme/default/file-upload-input.m.css';
1717
import * as fileUploadInputFixedCss from '../file-upload-input/styles/file-upload-input.m.css';
1818

19+
export interface FileUploaderChildren {
20+
label?: FileUploadInputChildren['label'];
21+
}
22+
1923
export interface FileUploaderProperties extends FileUploadInputProperties {
2024
/** Custom validator used to validate each file */
2125
customValidator?: (file: File) => ValidationInfo | void;
@@ -135,7 +139,7 @@ const icache = createICacheMiddleware<FileUploaderIcache>();
135139

136140
const factory = create({ fileDrop, i18n, icache, theme })
137141
.properties<FileUploaderProperties>()
138-
.children<Omit<FileUploadInputChildren, 'content'> | undefined>();
142+
.children<FileUploaderChildren | undefined>();
139143

140144
export const FileUploader = factory(function FileUploader({
141145
children,

0 commit comments

Comments
 (0)