mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Fix test failing
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
9f3550be14
commit
23f124791a
@ -1 +1,13 @@
|
|||||||
module.exports = require("@k8slens/jest").monorepoPackageConfig(__dirname).configForReact;
|
const { configForReact } = require("@k8slens/jest").monorepoPackageConfig(__dirname);
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
...configForReact,
|
||||||
|
coverageThreshold: {
|
||||||
|
global: {
|
||||||
|
statements: 84,
|
||||||
|
branches: 67,
|
||||||
|
lines: 84,
|
||||||
|
functions: 92,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
@ -1,17 +1,5 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`<Tooltip /> does not render to DOM if not visibile 1`] = `
|
|
||||||
<body>
|
|
||||||
<div>
|
|
||||||
<div
|
|
||||||
id="my-target"
|
|
||||||
>
|
|
||||||
Target Text
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`<Tooltip /> does not render to DOM if not visible 1`] = `
|
exports[`<Tooltip /> does not render to DOM if not visible 1`] = `
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
@ -24,25 +12,6 @@ exports[`<Tooltip /> does not render to DOM if not visible 1`] = `
|
|||||||
</body>
|
</body>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`<Tooltip /> renders to DOM when forced to by visibile prop 1`] = `
|
|
||||||
<body>
|
|
||||||
<div>
|
|
||||||
<div
|
|
||||||
class="Tooltip right visible"
|
|
||||||
role="tooltip"
|
|
||||||
style="left: 10px; top: 0px;"
|
|
||||||
>
|
|
||||||
I am a tooltip
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
id="my-target"
|
|
||||||
>
|
|
||||||
Target Text
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`<Tooltip /> renders to DOM when forced to by visible prop 1`] = `
|
exports[`<Tooltip /> renders to DOM when forced to by visible prop 1`] = `
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import { createPortal } from "react-dom";
|
|||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import type { IClassName } from "@k8slens/utilities";
|
import type { IClassName } from "@k8slens/utilities";
|
||||||
import { cssNames } from "@k8slens/utilities";
|
import { cssNames } from "@k8slens/utilities";
|
||||||
import { observable, makeObservable, action } from "mobx";
|
import { observable, makeObservable, action, runInAction } from "mobx";
|
||||||
import autoBindReact from "auto-bind/react";
|
import autoBindReact from "auto-bind/react";
|
||||||
|
|
||||||
export enum TooltipPosition {
|
export enum TooltipPosition {
|
||||||
@ -45,13 +45,13 @@ export interface TooltipContentFormatters {
|
|||||||
tableView?: boolean;
|
tableView?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultProps: Partial<TooltipProps> = {
|
const defaultProps = {
|
||||||
usePortal: true,
|
usePortal: true,
|
||||||
offset: 10,
|
offset: 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class Tooltip extends React.Component<TooltipProps> {
|
class DefaultedTooltip extends React.Component<TooltipProps & typeof defaultProps> {
|
||||||
static defaultProps = defaultProps as object;
|
static defaultProps = defaultProps as object;
|
||||||
|
|
||||||
@observable.ref elem: HTMLDivElement | null = null;
|
@observable.ref elem: HTMLDivElement | null = null;
|
||||||
@ -62,7 +62,7 @@ export class Tooltip extends React.Component<TooltipProps> {
|
|||||||
|
|
||||||
@observable isContentVisible = false; // animation manager
|
@observable isContentVisible = false; // animation manager
|
||||||
|
|
||||||
constructor(props: TooltipProps) {
|
constructor(props: TooltipProps & typeof defaultProps) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
autoBindReact(this);
|
autoBindReact(this);
|
||||||
@ -141,8 +141,10 @@ export class Tooltip extends React.Component<TooltipProps> {
|
|||||||
left >= 0 && top >= 0 && right <= viewportWidth && bottom <= viewportHeight;
|
left >= 0 && top >= 0 && right <= viewportWidth && bottom <= viewportHeight;
|
||||||
|
|
||||||
if (fitsToWindow) {
|
if (fitsToWindow) {
|
||||||
|
runInAction(() => {
|
||||||
this.activePosition = pos;
|
this.activePosition = pos;
|
||||||
this.setPosition(elem, { top, left });
|
this.setPosition(elem, { top, left });
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -164,8 +166,7 @@ export class Tooltip extends React.Component<TooltipProps> {
|
|||||||
protected getPosition(position: TooltipPosition, tooltipBounds: DOMRect, targetBounds: DOMRect) {
|
protected getPosition(position: TooltipPosition, tooltipBounds: DOMRect, targetBounds: DOMRect) {
|
||||||
let left: number;
|
let left: number;
|
||||||
let top: number;
|
let top: number;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
const offset = this.props.offset;
|
||||||
const offset = this.props.offset!;
|
|
||||||
const horizontalCenter = targetBounds.left + (targetBounds.width - tooltipBounds.width) / 2;
|
const horizontalCenter = targetBounds.left + (targetBounds.width - tooltipBounds.width) / 2;
|
||||||
const verticalCenter = targetBounds.top + (targetBounds.height - tooltipBounds.height) / 2;
|
const verticalCenter = targetBounds.top + (targetBounds.height - tooltipBounds.height) / 2;
|
||||||
const topCenter = targetBounds.top - tooltipBounds.height - offset;
|
const topCenter = targetBounds.top - tooltipBounds.height - offset;
|
||||||
@ -205,7 +206,7 @@ export class Tooltip extends React.Component<TooltipProps> {
|
|||||||
left = targetBounds.right - tooltipBounds.width;
|
left = targetBounds.right - tooltipBounds.width;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new TypeError("Invalid props.postition value");
|
throw new TypeError("Invalid props.position value");
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -240,3 +241,5 @@ export class Tooltip extends React.Component<TooltipProps> {
|
|||||||
return tooltip;
|
return tooltip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const Tooltip = DefaultedTooltip as React.ComponentClass<TooltipProps>;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user