Skip to content

Commit

Permalink
chore(types): migrate existing types to stable type compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
gilest committed Jul 21, 2023
1 parent f069571 commit ad0d314
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
5 changes: 2 additions & 3 deletions ember-file-upload/src/system/drag-listener.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { assert } from '@ember/debug';
import { cancel, next } from '@ember/runloop';
import { EmberRunTimer } from '@ember/runloop/types';
import { type Timer, cancel, next } from '@ember/runloop';
import {
DragEventListener,
QueuedDragEvent,
Expand All @@ -24,7 +23,7 @@ export default class DragListener {

_handlers: DragListenerHandlers = {};
_handlersAttached = false;
_scheduled: EmberRunTimer | null = null;
_scheduled: Timer | null = null;

constructor(dropzone: Element) {
this._dropzone = dropzone;
Expand Down
8 changes: 5 additions & 3 deletions test-app/tests/integration/components/file-dropzone-test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, triggerEvent, TestContext } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { hbs } from 'ember-cli-htmlbars';
import {
dragAndDrop,
dragEnter,
dragLeave,
} from 'ember-file-upload/test-support';
import { Queue } from 'ember-file-upload';
import type { UploadFile } from 'ember-file-upload';
import type { FileQueueService, UploadFile } from 'ember-file-upload';

interface LocalTestContext extends TestContext {
queue: Queue;
Expand All @@ -22,7 +22,9 @@ module('Integration | Component | FileDropzone', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (this: LocalTestContext) {
const fileQueueService = this.owner.lookup('service:file-queue');
const fileQueueService = this.owner.lookup(
'service:file-queue'
) as FileQueueService;
this.queue = new Queue({ name: 'test', fileQueue: fileQueueService });
});

Expand Down
2 changes: 1 addition & 1 deletion test-app/tests/integration/mirage-handler-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { hbs } from 'ember-cli-htmlbars';
import { uploadHandler } from 'ember-file-upload';
import { selectFiles } from 'ember-file-upload/test-support';
import {
Expand Down
6 changes: 4 additions & 2 deletions test-app/tests/integration/queue-listeners-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TestContext, render, settled } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { selectFiles } from 'ember-file-upload/test-support';
import { tracked } from '@glimmer/tracking';
import type { Queue, UploadFile } from 'ember-file-upload';
import type { FileQueueService, Queue, UploadFile } from 'ember-file-upload';

class State {
@tracked firstComponent = true;
Expand All @@ -23,7 +23,9 @@ module('Integration | queue listeners', function (hooks) {
setupRenderingTest(hooks);

const setupState = function (this: LocalTestContext) {
const fileQueueService = this.owner.lookup('service:file-queue');
const fileQueueService = this.owner.lookup(
'service:file-queue'
) as FileQueueService;

this.state = new State();
this.queue = fileQueueService.create('listener-test');
Expand Down
2 changes: 1 addition & 1 deletion test-app/tests/integration/services/file-queue-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module('Integration | Service | file queue', function (hooks) {
setupRenderingTest(hooks);

test('files is reactive', async function (this: LocalTestContext, assert) {
this.subject = this.owner.lookup('service:file-queue');
this.subject = this.owner.lookup('service:file-queue') as FileQueueService;

const existingQueue = this.subject.create('existing-queue');
const existingQueueFile = new UploadFile(
Expand Down
19 changes: 15 additions & 4 deletions test-app/tests/unit/services/file-queue-test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { FileSource, FileState, UploadFile } from 'ember-file-upload';
import {
type FileQueueService,
FileSource,
FileState,
UploadFile,
} from 'ember-file-upload';
import { TestContext } from '@ember/test-helpers';
import { png } from 'test-app/tests/utils/file-data';

module('Unit | Service | file-queue', function (hooks) {
setupTest(hooks);

test('the size of the queue is the aggregate of all queues', function (this: TestContext, assert) {
const fileQueueService = this.owner.lookup('service:file-queue');
const fileQueueService = this.owner.lookup(
'service:file-queue'
) as FileQueueService;
const queue1 = fileQueueService.create('queue1');
const queue2 = fileQueueService.create('queue2');
fileQueueService.create('queue3');
Expand Down Expand Up @@ -46,7 +53,9 @@ module('Unit | Service | file-queue', function (hooks) {
});

test('the uploaded size of the queue is the aggregate of all queues', function (this: TestContext, assert) {
const fileQueueService = this.owner.lookup('service:file-queue');
const fileQueueService = this.owner.lookup(
'service:file-queue'
) as FileQueueService;
const queue1 = fileQueueService.create('queue1');

assert.strictEqual(fileQueueService.files.length, 0);
Expand Down Expand Up @@ -90,7 +99,9 @@ module('Unit | Service | file-queue', function (hooks) {
});

test('the queue is emptied when all files are completed and flush is called', function (this: TestContext, assert) {
const fileQueueService = this.owner.lookup('service:file-queue');
const fileQueueService = this.owner.lookup(
'service:file-queue'
) as FileQueueService;
const queue = fileQueueService.create('queue');

const file = new File(png, 'test-filename.jpg');
Expand Down

0 comments on commit ad0d314

Please sign in to comment.