All files / tests/unit/tester layout.js

85.19% Statements 23/27
75% Branches 3/4
77.78% Functions 7/9
82.61% Lines 19/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 591x           18x 18x 1x 3x       3x       3x         1x         1x 3x   3x 1x 2x 2x             1x   3x       3x 3x         3x            
export const orientation = {
    HORIZONTAL: 'horizontal',
    VERTICAL: 'vertical',
    AMBIGUOUS: 'ambiguous',
};
 
const min = coord => (min, point) => Math.min(min, point[coord]);
const max = coord => (max, point) => Math.max(max, point[coord]);
const toPathSize = path => {
    const x = {
        min: path.reduce(min('x'), +Infinity),
        max: path.reduce(max('x'), -Infinity),
    };
    const y = {
        min: path.reduce(min('y'), Infinity),
        max: path.reduce(max('y'), -Infinity),
    };
    return {
        width: x.max - x.min,
        height: y.max - y.min,
    };
};
const toTotalPathSize = (total, transition) => {
    total.width += transition.width;
    total.height += transition.height;
};
 
export const orientationOf = path => {
    const total = path.map(toPathSize).reduce(toTotalPathSize);
 
    if (total.height > 2*total.width) {
        return orientation.VERTICAL;
    } else Eif (total.width > 2*total.height) {
        return orientation.HORIZONTAL;
    } else {
        return orientation.AMBIGUOUS;
    }
};
 
export function installOrientationMatcher() {
    expect.extend({
        toHaveOrientation(received, expected) {
            const options = {
                isNot: this.isNot,
                promise: this.promise,
            };
            const pass = orientationOf(received) === expected;
            const message = () =>
                this.utils.matcherHint('.toHaveOrientation', undefined, undefined, options)
                + `\n\nExpected orientation: ${this.utils.printExpected(expected)}\n`
                + `Received: ${this.utils.printReceived(received)}`;
 
            return { actual: received, message, pass };
        },
    });
}