Skip to content

Commit 2281dba

Browse files
committed
modifiers/restrict: add tests for restrictSize
* Basic tests for logic in restrictSize. Other changes are because require(modifiers) has side-effects that affect the mocked objects presented in other test.
1 parent ad114f0 commit 2281dba

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

tests/actions/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test('firePrepared function', t => {
1818
const interaction = new Interaction();
1919
const element = {};
2020
const interactable = new Interactable(element, { origin: { x: 0, y: 0 } });
21-
const action = { name: 'TEST' };
21+
const action = { name: 'resize' };
2222
const phase = 'TEST_PHASE';
2323

2424
let event = null;

tests/actions/drag.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ test('Interactable.draggable method', t => {
6363

6464
test('drag axis', t => {
6565
const Interaction = require('../../src/Interaction');
66+
const Interactable = require('../../src/Interactable');
6667
const InteractEvent = require('../../src/InteractEvent');
6768

6869
const opposites = { x: 'y', y: 'x' };
6970
const interaction = new Interaction();
71+
const element = {};
72+
const interactable = new Interactable(element, { origin: { x: 0, y: 0 } });
73+
interaction.target = interactable;
74+
7075
const iEvent = { type: 'dragmove' };
7176
const eventCoords = {
7277
pageX: -1, pageY: -2,

tests/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require('./pointerEvents/holdRepeat');
1515
// modifiers
1616
//require('./modifiers/snap');
1717
//require('./modifiers/restrict');
18+
require('./modifiers/restrictSize');
1819

1920
// delay
2021
//require('./autoStart/delay');

tests/modifiers/restrictSize.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const test = require('../test');
2+
3+
test('restrictSize', t => {
4+
const RestrictSize = require('../../src/modifiers/restrictSize');
5+
const Interaction = require('../../src/Interaction');
6+
7+
const interaction = new Interaction();
8+
interaction.prepared = {};
9+
interaction.prepared.edges = { top: true, bottom: true, left: true, right: true };
10+
interaction.resizeRects = {};
11+
interaction.resizeRects.inverted = { x: 10, y: 20, width: 300, height: 200 };
12+
interaction._interacting = true;
13+
14+
t.test('works with min and max options', tt => {
15+
const options = {
16+
min: { width: 60, height: 50 },
17+
max: { width: 600, height: 500 },
18+
};
19+
const status = {};
20+
const pageCoords = { x: 5, y: 15 };
21+
const offset = { top: 0, bottom: 0, left: 0, right: 0 };
22+
const arg = { interaction, options, status, pageCoords, offset };
23+
24+
RestrictSize.set(arg);
25+
tt.deepEqual(arg.options.inner, { top: 170, left: 250, bottom: -Infinity, right: -Infinity });
26+
tt.deepEqual(arg.options.outer, { top: -280, left: -290, bottom: Infinity, right: Infinity });
27+
tt.end();
28+
});
29+
30+
t.test('works with min option only', tt => {
31+
const options = {
32+
min: { width: 60, height: 50 },
33+
};
34+
const status = {};
35+
const pageCoords = { x: 5, y: 15 };
36+
const offset = { top: 0, bottom: 0, left: 0, right: 0 };
37+
const arg = { interaction, options, status, pageCoords, offset };
38+
39+
RestrictSize.set(arg);
40+
tt.deepEqual(arg.options.inner, { top: 170, left: 250, bottom: -Infinity, right: -Infinity });
41+
tt.deepEqual(arg.options.outer, { top: -Infinity, left: -Infinity, bottom: Infinity, right: Infinity });
42+
tt.end();
43+
});
44+
45+
t.test('works with max option only', tt => {
46+
const options = {
47+
max: { width: 600, height: 500 },
48+
};
49+
const status = {};
50+
const pageCoords = { x: 5, y: 15 };
51+
const offset = { top: 0, bottom: 0, left: 0, right: 0 };
52+
const arg = { interaction, options, status, pageCoords, offset };
53+
54+
RestrictSize.set(arg);
55+
tt.deepEqual(arg.options.inner, { top: Infinity, left: Infinity, bottom: -Infinity, right: -Infinity });
56+
tt.deepEqual(arg.options.outer, { top: -280, left: -290, bottom: Infinity, right: Infinity });
57+
tt.end();
58+
});
59+
60+
t.end();
61+
});

0 commit comments

Comments
 (0)