Skip to content

Commit 39a9895

Browse files
authored
Merge pull request #590 from Shopify/converts-missing-files
Converts ResizeMirror test to typescript
2 parents 717a4b5 + f05efb3 commit 39a9895

File tree

6 files changed

+48
-22
lines changed

6 files changed

+48
-22
lines changed

.changeset/smooth-coins-brush.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/draggable': patch
3+
---
4+
5+
Fixes VSCode search to exclude generated files/folders

.changeset/sour-ravens-pull.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/draggable': patch
3+
---
4+
5+
Converts ResizeMirror test to typescript

.vscode/settings.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"coverage": true
88
},
99
"search.exclude": {
10-
"**/node_modules": true,
11-
".rollup.cache": true,
12-
"coverage": true,
13-
"build": true,
14-
"docs": true
10+
"node_modules/**/*": true,
11+
".rollup.cache/**/*": true,
12+
"coverage/**/*": true,
13+
"build/**/*": true,
14+
"docs/**/*": true
1515
},
1616
"[typescript]": {
1717
"editor.formatOnSave": false,

src/Plugins/ResizeMirror/tests/ResizeMirror.test.js src/Plugins/ResizeMirror/tests/ResizeMirror.test.ts

+32-16
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import {
99
DRAG_DELAY,
1010
drag,
1111
} from 'helper';
12+
import {FixMeAny} from 'shared/types';
1213

13-
import {Draggable} from '../../..';
14+
/* eslint-disable @typescript-eslint/ban-ts-comment */
15+
// @ts-ignore
16+
import Draggable from '../../../Draggable';
17+
/* eslint-enable @typescript-eslint/ban-ts-comment */
1418
import ResizeMirror from '..';
1519

1620
const sampleMarkup = `
@@ -36,17 +40,17 @@ describe('ResizeMirror', () => {
3640
height: smallerDraggableDimensions.height * 2,
3741
};
3842

39-
let sandbox;
40-
let containers;
41-
let draggable;
42-
let draggables;
43-
let smallerDraggable;
44-
let largerDraggable;
43+
let sandbox: HTMLDivElement;
44+
let containers: HTMLElement[];
45+
let draggable: FixMeAny;
46+
let draggables: HTMLElement[];
47+
let smallerDraggable: HTMLElement;
48+
let largerDraggable: HTMLElement;
4549

4650
beforeEach(() => {
4751
sandbox = createSandbox(sampleMarkup);
48-
containers = sandbox.querySelectorAll('.Container');
49-
draggables = sandbox.querySelectorAll('li');
52+
containers = [...sandbox.querySelectorAll<HTMLElement>('.Container')];
53+
draggables = [...sandbox.querySelectorAll<HTMLElement>('li')];
5054

5155
smallerDraggable = draggables[0];
5256
largerDraggable = draggables[1];
@@ -71,7 +75,7 @@ describe('ResizeMirror', () => {
7175
waitForDragDelay();
7276
await waitForPromisesToResolve();
7377

74-
const mirror = document.querySelector('.draggable-mirror');
78+
const mirror = document.querySelector<HTMLElement>('.draggable-mirror')!;
7579

7680
expect(mirror.style).toMatchObject({
7781
width: `${smallerDraggableDimensions.width}px`,
@@ -104,7 +108,7 @@ describe('ResizeMirror', () => {
104108
waitForDragDelay();
105109
await waitForPromisesToResolve();
106110

107-
const mirror = document.querySelector('.draggable-mirror');
111+
const mirror = document.querySelector<HTMLElement>('.draggable-mirror')!;
108112

109113
moveMouse(largerDraggable);
110114
waitForRequestAnimationFrame();
@@ -119,7 +123,7 @@ describe('ResizeMirror', () => {
119123
waitForDragDelay();
120124
await waitForPromisesToResolve();
121125

122-
const mirror = document.querySelector('.draggable-mirror');
126+
const mirror = document.querySelector<HTMLElement>('.draggable-mirror')!;
123127

124128
const mockedAppendChild = withMockedAppendChild(() => {
125129
moveMouse(smallerDraggable);
@@ -145,19 +149,28 @@ describe('ResizeMirror', () => {
145149
});
146150
});
147151

148-
function mockDimensions(element, {width = 0, height = 0}) {
152+
function mockDimensions(element: HTMLElement, {width = 0, height = 0}) {
149153
Object.assign(element.style, {
150154
width: `${width}px`,
151155
height: `${height}px`,
152156
});
153157

154-
element.getBoundingClientRect = () => ({
158+
const properties = {
155159
width,
156160
height,
157161
top: 0,
158162
left: 0,
159163
right: width,
160164
bottom: height,
165+
x: 0,
166+
y: 0,
167+
};
168+
169+
element.getBoundingClientRect = () => ({
170+
...properties,
171+
toJSON() {
172+
return {...properties};
173+
},
161174
});
162175

163176
return element;
@@ -168,13 +181,16 @@ function waitForNextRequestAnimationFrame() {
168181
waitForRequestAnimationFrame();
169182
}
170183

171-
function withMockedAppendChild(callback) {
184+
function withMockedAppendChild(callback: () => void) {
172185
const mock = jest.fn();
173186
const appendChild = Node.prototype.appendChild;
174-
Node.prototype.appendChild = function (...args) {
187+
/* eslint-disable @typescript-eslint/ban-ts-comment */
188+
// @ts-ignore
189+
Node.prototype.appendChild = function (this: Node, ...args) {
175190
mock(...args);
176191
return appendChild.call(this, ...args);
177192
};
193+
/* eslint-enable @typescript-eslint/ban-ts-comment */
178194
callback();
179195
Node.prototype.appendChild = appendChild;
180196
return mock;
File renamed without changes.

test/helpers/module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
interface Options {
1616
from: HTMLElement;
1717
to: HTMLElement;
18-
sensor: 'mouse' | 'touch' | 'drag';
18+
sensor?: 'mouse' | 'touch' | 'drag';
1919
}
2020

2121
export function drag({from, to, sensor = 'mouse'}: Options) {

0 commit comments

Comments
 (0)