|
| 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