Mailspring/app/spec/components/fixed-popover-spec.tsx
Ben Gotow 149b389508
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404)
* Switch to using Typescript instead of Babel

* Switch all es6 / jsx file extensions to ts / tsx

* Convert Utils to a TS module from module.exports style module

* Move everything from module.exports to typescript exports

* Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :(

* Load up on those @types

* Synthesize TS types from PropTypes for standard components

* Add types to Model classes and move constructor constants to instance vars

* 9800 => 7700 TS errors

* 7700 => 5600 TS errors

* 5600 => 5330 TS errors

* 5330 => 4866 TS errors

* 4866 => 4426 TS errors

* 4426 => 2411 TS errors

* 2411 > 1598 TS errors

* 1598 > 769 TS errors

* 769 > 129 TS errors

* 129 > 22 TS errors

* Fix runtime errors

* More runtime error fixes

* Remove support for custom .es6 file extension

* Remove a few odd remaining references to Nylas

* Don’t ship Typescript support in the compiled app for now

* Fix issues in compiled app - module resolution in TS is case sensitive?

* README updates

* Fix a few more TS errors

* Make “No Signature” option clickable + selectable

* Remove flicker when saving file and reloading keymaps

* Fix mail rule item height in preferences

* Fix missing spacing in thread sharing popover

* Fix scrollbar ticks being nested incorrectly

* Add Japanese as a manually reviewed language

* Prevent the thread list from “sticking”

* Re-use Sheet when switching root tabs, prevent sidebar from resetting

* Ensure specs run

* Update package configuration to avoid shpping types

* Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-04 11:03:12 -08:00

234 lines
7.2 KiB
TypeScript

import React from 'react';
import FixedPopover from '../../src/components/fixed-popover';
import MTestUtils from '../mailspring-test-utils';
const { Directions: { Up, Down, Left, Right } } = FixedPopover;
const makePopover = (props = {}) => {
const originRect = props.originRect ? props.originRect : {};
const popover = MTestUtils.renderIntoDocument(
<FixedPopover {...props} originRect={originRect} />
);
if (props.initialState) {
popover.setState(props.initialState);
}
return popover;
};
describe('FixedPopover', function fixedPopover() {
describe('computeAdjustedOffsetAndDirection', () => {
beforeEach(() => {
this.popover = makePopover();
this.PADDING = 10;
this.windowDimensions = {
height: 500,
width: 500,
};
});
const compute = (direction, { fallback, top, left, bottom, right }) => {
return this.popover.computeAdjustedOffsetAndDirection({
direction,
windowDimensions: this.windowDimensions,
currentRect: {
top,
left,
bottom,
right,
},
fallback,
offsetPadding: this.PADDING,
});
};
it('returns null when no overflows present', () => {
const res = compute(Up, { top: 10, left: 10, right: 20, bottom: 20 });
expect(res).toBe(null);
});
describe('when overflowing on 1 side of the window', () => {
it('returns fallback direction when it is specified', () => {
const { offset, direction } = compute(Up, {
fallback: Left,
top: -10,
left: 10,
right: 20,
bottom: 10,
});
expect(offset).toEqual({});
expect(direction).toEqual(Left);
});
it('inverts direction if is Up and overflows on the top', () => {
const { offset, direction } = compute(Up, { top: -10, left: 10, right: 20, bottom: 10 });
expect(offset).toEqual({});
expect(direction).toEqual(Down);
});
it('inverts direction if is Down and overflows on the bottom', () => {
const { offset, direction } = compute(Down, { top: 490, left: 10, right: 20, bottom: 510 });
expect(offset).toEqual({});
expect(direction).toEqual(Up);
});
it('inverts direction if is Right and overflows on the right', () => {
const { offset, direction } = compute(Right, {
top: 10,
left: 490,
right: 510,
bottom: 20,
});
expect(offset).toEqual({});
expect(direction).toEqual(Left);
});
it('inverts direction if is Left and overflows on the left', () => {
const { offset, direction } = compute(Left, { top: 10, left: -10, right: 10, bottom: 20 });
expect(offset).toEqual({});
expect(direction).toEqual(Right);
});
[Up, Down, Left, Right].forEach(dir => {
if (dir === Up || dir === Down) {
it('moves left if its overflowing on the right', () => {
const { offset, direction } = compute(dir, {
top: 10,
left: 490,
right: 510,
bottom: 20,
});
expect(offset).toEqual({ x: -20 });
expect(direction).toEqual(dir);
});
it('moves right if overflows on the left', () => {
const { offset, direction } = compute(dir, {
top: 10,
left: -10,
right: 10,
bottom: 20,
});
expect(offset).toEqual({ x: 20 });
expect(direction).toEqual(dir);
});
}
if (dir === Left || dir === Right) {
it('moves up if its overflowing on the bottom', () => {
const { offset, direction } = compute(dir, {
top: 490,
left: 10,
right: 20,
bottom: 510,
});
expect(offset).toEqual({ y: -20 });
expect(direction).toEqual(dir);
});
it('moves down if overflows on the top', () => {
const { offset, direction } = compute(dir, {
top: -10,
left: 10,
right: 20,
bottom: 10,
});
expect(offset).toEqual({ y: 20 });
expect(direction).toEqual(dir);
});
}
});
});
describe('when overflowing on 2 sides of the window', () => {
describe('when direction is up', () => {
it('computes correctly when it overflows up and right', () => {
const { offset, direction } = compute(Up, { top: -10, left: 10, right: 510, bottom: 10 });
expect(offset).toEqual({ x: -20 });
expect(direction).toEqual(Down);
});
it('computes correctly when it overflows up and left', () => {
const { offset, direction } = compute(Up, { top: -10, left: -10, right: 10, bottom: 10 });
expect(offset).toEqual({ x: 20 });
expect(direction).toEqual(Down);
});
});
describe('when direction is right', () => {
it('computes correctly when it overflows right and up', () => {
const { offset, direction } = compute(Right, {
top: -10,
left: 490,
right: 510,
bottom: 10,
});
expect(offset).toEqual({ y: 20 });
expect(direction).toEqual(Left);
});
it('computes correctly when it overflows right and down', () => {
const { offset, direction } = compute(Right, {
top: 490,
left: 490,
right: 510,
bottom: 510,
});
expect(offset).toEqual({ y: -20 });
expect(direction).toEqual(Left);
});
});
describe('when direction is left', () => {
it('computes correctly when it overflows left and up', () => {
const { offset, direction } = compute(Left, {
top: -10,
left: -10,
right: 10,
bottom: 10,
});
expect(offset).toEqual({ y: 20 });
expect(direction).toEqual(Right);
});
it('computes correctly when it overflows left and down', () => {
const { offset, direction } = compute(Left, {
top: 490,
left: -10,
right: 10,
bottom: 510,
});
expect(offset).toEqual({ y: -20 });
expect(direction).toEqual(Right);
});
});
describe('when direction is down', () => {
it('computes correctly when it overflows down and left', () => {
const { offset, direction } = compute(Down, {
top: 490,
left: -10,
right: 10,
bottom: 510,
});
expect(offset).toEqual({ x: 20 });
expect(direction).toEqual(Up);
});
it('computes correctly when it overflows down and right', () => {
const { offset, direction } = compute(Down, {
top: 490,
left: 490,
right: 510,
bottom: 510,
});
expect(offset).toEqual({ x: -20 });
expect(direction).toEqual(Up);
});
});
});
});
describe('computePopoverStyles', () => {
// TODO
});
});