Skip to content

Commit 28bf9d2

Browse files
MichalBryxigilest
authored andcommitted
Propose a partial fix to #1085
1 parent 2d12346 commit 28bf9d2

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

ember-file-upload/src/services/file-queue.ts

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ export default class FileQueueService extends Service {
2626
*/
2727
#queues: Map<QueueName, Queue> = new Map();
2828

29+
constructor() {
30+
super();
31+
// Create default queue the first time this service is accessed and instantiated
32+
// Helps to avoid backtracking re-render issues
33+
this.create(DEFAULT_QUEUE);
34+
}
35+
2936
/**
3037
* Returns a queue with the given name
3138
*

test-app/tests/integration/helpers/file-queue-helper-test.gts

+58-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { render, click, settled, waitFor } from '@ember/test-helpers';
55
import { DEFAULT_QUEUE, FileState } from 'ember-file-upload';
66
import type { UploadFile } from 'ember-file-upload';
77
import { selectFiles } from 'ember-file-upload/test-support';
8-
import { uploadHandler } from 'ember-file-upload';
8+
import { type FileQueueService, uploadHandler } from 'ember-file-upload';
99
import { later } from '@ember/runloop';
1010
import fileQueue from 'ember-file-upload/helpers/file-queue';
1111
import { on } from '@ember/modifier';
@@ -274,4 +274,61 @@ module('Integration | Helper | file-queue', function (hooks) {
274274
await settled();
275275
assert.dom('[data-test-file]').doesNotExist('queue was flushed');
276276
});
277+
278+
// Service before helper issue ref: https://github.com/adopted-ember-addons/ember-file-upload/issues/1085
279+
test('service can be used before helper with DEFUALT_QUEUE', async function (assert) {
280+
const fileQueueService = this.owner.lookup(
281+
'service:file-queue',
282+
) as FileQueueService;
283+
284+
await render(
285+
<template>
286+
<ul>
287+
{{#each fileQueueService.files as |file|}}
288+
<li>
289+
{{file.name}}
290+
</li>
291+
{{/each}}
292+
</ul>
293+
294+
{{#let (fileQueue) as |queue|}}
295+
<label>
296+
<input type='file' {{queue.selectFile}} hidden />
297+
Select File
298+
</label>
299+
{{/let}}
300+
</template>,
301+
);
302+
303+
assert.dom('label').exists('regression would throw during rendering');
304+
});
305+
306+
test('service can be used before helper with named queue, provided FileQueueService.create is called first', async function (assert) {
307+
const fileQueueService = this.owner.lookup(
308+
'service:file-queue',
309+
) as FileQueueService;
310+
const customName = 'uploads';
311+
fileQueueService.create(customName);
312+
313+
await render(
314+
<template>
315+
<ul>
316+
{{#each fileQueueService.files as |file|}}
317+
<li>
318+
{{file.name}}
319+
</li>
320+
{{/each}}
321+
</ul>
322+
323+
{{#let (fileQueue name=customName) as |queue|}}
324+
<label>
325+
<input type='file' {{queue.selectFile}} hidden />
326+
Select File
327+
</label>
328+
{{/let}}
329+
</template>,
330+
);
331+
332+
assert.dom('label').exists('regression would throw during rendering');
333+
});
277334
});

0 commit comments

Comments
 (0)