Skip to content

Commit

Permalink
Migrate all tests to "strict mode" (#1049)
Browse files Browse the repository at this point in the history
Rebased off #1048 so the diff will include those changes until they are merged
  • Loading branch information
gilest authored Dec 25, 2023
1 parent 19803b7 commit 5eddbe4
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 356 deletions.
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions test-app/app/helpers/to-string.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, triggerEvent, type TestContext } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import {
dragAndDrop,
dragEnter,
dragLeave,
} from 'ember-file-upload/test-support';
import { Queue } from 'ember-file-upload';
import type { FileQueueService, UploadFile } from 'ember-file-upload';
import FileDropzone from 'ember-file-upload/components/file-dropzone';
import fileQueue from 'ember-file-upload/helpers/file-queue';

interface LocalTestContext extends TestContext {
queue: Queue;
filter: (file: File, files: File[], index: number) => boolean;
onDragEnter: (files: File[]) => void;
onDragLeave: (files: File[]) => void;
onDrop: (files: UploadFile[]) => void;
}

module('Integration | Component | FileDropzone', function (hooks) {
Expand All @@ -29,31 +26,35 @@ module('Integration | Component | FileDropzone', function (hooks) {
});

test('onDragEnter is called when a file is dragged over', async function (this: LocalTestContext, assert) {
this.onDragEnter = () => assert.step('onDragEnter');
const onDragEnter = () => assert.step('onDragEnter');
const queue = this.queue;

await render<LocalTestContext>(hbs`
<FileDropzone
class="test-dropzone"
@queue={{this.queue}}
@onDragEnter={{this.onDragEnter}} />
`);
await render(<template>
<FileDropzone
class='test-dropzone'
@queue={{queue}}
@onDragEnter={{onDragEnter}}
/>
</template>);

await dragEnter('.test-dropzone');

assert.verifySteps(['onDragEnter']);
});

test('filter and onDrop', async function (this: LocalTestContext, assert) {
this.filter = (file) => file.name.includes('.txt');
this.onDrop = (files) => files.forEach((file) => assert.step(file.name));
await render<LocalTestContext>(hbs`
<FileDropzone
class="test-dropzone"
@queue={{this.queue}}
@filter={{this.filter}}
@onDrop={{this.onDrop}}
/>
`);
const queue = this.queue;
const filter = (file: File) => file.name.includes('.txt');
const onDrop = (files: UploadFile[]) =>
files.forEach((file) => assert.step(file.name));
await render(<template>
<FileDropzone
class='test-dropzone'
@queue={{queue}}
@filter={{filter}}
@onDrop={{onDrop}}
/>
</template>);

await dragAndDrop(
'.test-dropzone',
Expand All @@ -66,29 +67,30 @@ module('Integration | Component | FileDropzone', function (hooks) {
});

test('dropping a file calls onDrop', async function (this: LocalTestContext, assert) {
this.onDrop = (files) => files.forEach((file) => assert.step(file.name));
const queue = this.queue;
const onDrop = (files: UploadFile[]) =>
files.forEach((file) => assert.step(file.name));

await render<LocalTestContext>(hbs`
<FileDropzone
class="test-dropzone"
@queue={{this.queue}}
@onDrop={{this.onDrop}} />
`);
await render(<template>
<FileDropzone class='test-dropzone' @queue={{queue}} @onDrop={{onDrop}} />
</template>);

await dragAndDrop('.test-dropzone', new File([], 'dingus.txt'));

assert.verifySteps(['dingus.txt']);
});

test('onDragLeave is called when a file is dragged out', async function (this: LocalTestContext, assert) {
this.onDragLeave = () => assert.step('onDragLeave');
const queue = this.queue;
const onDragLeave = () => assert.step('onDragLeave');

await render<LocalTestContext>(hbs`
<FileDropzone
class="test-dropzone"
@queue={{this.queue}}
@onDragLeave={{this.onDragLeave}} />
`);
await render(<template>
<FileDropzone
class='test-dropzone'
@queue={{queue}}
@onDragLeave={{onDragLeave}}
/>
</template>);

await dragEnter('.test-dropzone', new File([], 'dingus.txt'));
await dragLeave('.test-dropzone', new File([], 'dingus.txt'));
Expand All @@ -97,30 +99,30 @@ module('Integration | Component | FileDropzone', function (hooks) {
});

test('yielded properties', async function (this: LocalTestContext, assert) {
await render<LocalTestContext>(hbs`
{{#let (file-queue name='test') as |helperQueue|}}
<FileDropzone @queue={{helperQueue}} as |dropzone queue|>
<div class="supported">{{dropzone.supported}}</div>
<div class="active">{{dropzone.active}}</div>
<div class="queue-name">{{to-string queue.name}}</div>
</FileDropzone>
{{/let}}
`);
await render(<template>
{{#let (fileQueue name='test') as |helperQueue|}}
<FileDropzone @queue={{helperQueue}} as |dropzone queue|>
<div class='supported'>{{dropzone.supported}}</div>
<div class='active'>{{dropzone.active}}</div>
{{! @glint-ignore }}
<div class='queue-name'>{{queue.name}}</div>
</FileDropzone>
{{/let}}
</template>);

assert.dom('.supported').hasText('true');
assert.dom('.active').hasText('false');
assert.dom('.queue-name').hasText('test');
});

test('dropping multiple files calls onDrop with both files', async function (this: LocalTestContext, assert) {
this.onDrop = (files) => files.forEach((file) => assert.step(file.name));
const queue = this.queue;
const onDrop = (files: UploadFile[]) =>
files.forEach((file) => assert.step(file.name));

await render<LocalTestContext>(hbs`
<FileDropzone
class="test-dropzone"
@queue={{this.queue}}
@onDrop={{this.onDrop}} />
`);
await render(<template>
<FileDropzone class='test-dropzone' @queue={{queue}} @onDrop={{onDrop}} />
</template>);

await dragAndDrop(
'.test-dropzone',
Expand All @@ -132,15 +134,18 @@ module('Integration | Component | FileDropzone', function (hooks) {
});

test('multiple=true dropping multiple files calls onDrop with both files', async function (this: LocalTestContext, assert) {
this.onDrop = (files) => files.forEach((file) => assert.step(file.name));

await render<LocalTestContext>(hbs`
<FileDropzone
class="test-dropzone"
@queue={{this.queue}}
@multiple={{true}}
@onDrop={{this.onDrop}} />
`);
const queue = this.queue;
const onDrop = (files: UploadFile[]) =>
files.forEach((file) => assert.step(file.name));

await render(<template>
<FileDropzone
class='test-dropzone'
@queue={{queue}}
@multiple={{true}}
@onDrop={{onDrop}}
/>
</template>);

await dragAndDrop(
'.test-dropzone',
Expand All @@ -152,15 +157,18 @@ module('Integration | Component | FileDropzone', function (hooks) {
});

test('multiple=false dropping multiple files calls onDrop with one file', async function (this: LocalTestContext, assert) {
this.onDrop = (files) => files.forEach((file) => assert.step(file.name));

await render<LocalTestContext>(hbs`
<FileDropzone
class="test-dropzone"
@queue={{this.queue}}
@multiple={{false}}
@onDrop={{this.onDrop}} />
`);
const queue = this.queue;
const onDrop = (files: UploadFile[]) =>
files.forEach((file) => assert.step(file.name));

await render(<template>
<FileDropzone
class='test-dropzone'
@queue={{queue}}
@multiple={{false}}
@onDrop={{onDrop}}
/>
</template>);

await dragAndDrop(
'.test-dropzone',
Expand All @@ -173,13 +181,14 @@ module('Integration | Component | FileDropzone', function (hooks) {

// Check for regression of: https://github.com/adopted-ember-addons/ember-file-upload/issues/446
test('regression: drop events from other DOM nodes are not prevented', async function (this: LocalTestContext, assert) {
const queue = this.queue;
const documentDragListener = () =>
assert.step('documentDragListener called');
await render<LocalTestContext>(hbs`
<FileDropzone @queue={{this.queue}} />
await render(<template>
<FileDropzone @queue={{queue}} />

<div class="independent-drag-target"></div>
`);
<div class='independent-drag-target'></div>
</template>);
document.addEventListener('drop', documentDragListener);

await triggerEvent('.independent-drag-target', 'drop');
Expand Down
Loading

0 comments on commit 5eddbe4

Please sign in to comment.