fix tests

This commit is contained in:
Aakansha Doshi 2023-05-22 13:40:35 +05:30
parent e68edb9f73
commit e3fa2905f2
6 changed files with 51785 additions and 35 deletions

View file

@ -28,6 +28,7 @@ import {
FONT_FAMILY,
ROUNDNESS,
DEFAULT_SIDEBAR,
DEFAULT_ELEMENT_PROPS,
} from "../constants";
import { getDefaultAppState } from "../appState";
import { LinearElementEditor } from "../element/linearElementEditor";
@ -81,7 +82,7 @@ const getFontFamilyByName = (fontFamilyName: string): FontFamilyValues => {
return DEFAULT_FONT_FAMILY;
};
const restoreElementWithProperties = <
export const restoreElementWithProperties = <
T extends Required<Omit<ExcalidrawElement, "customData">> & {
customData?: ExcalidrawElement["customData"];
/** @deprecated */
@ -112,18 +113,20 @@ const restoreElementWithProperties = <
versionNonce: element.versionNonce ?? 0,
isDeleted: element.isDeleted ?? false,
id: element.id || randomId(),
fillStyle: element.fillStyle || "hachure",
strokeWidth: element.strokeWidth || 1,
strokeStyle: element.strokeStyle ?? "solid",
roughness: element.roughness ?? 1,
opacity: element.opacity == null ? 100 : element.opacity,
fillStyle: element.fillStyle || DEFAULT_ELEMENT_PROPS.fillStyle,
strokeWidth: element.strokeWidth || DEFAULT_ELEMENT_PROPS.strokeWidth,
strokeStyle: element.strokeStyle ?? DEFAULT_ELEMENT_PROPS.strokeStyle,
roughness: element.roughness ?? DEFAULT_ELEMENT_PROPS.roughness,
opacity:
element.opacity == null ? DEFAULT_ELEMENT_PROPS.opacity : element.opacity,
angle: element.angle || 0,
x: extra.x ?? element.x ?? 0,
y: extra.y ?? element.y ?? 0,
strokeColor: element.strokeColor || oc.black,
backgroundColor: element.backgroundColor || "transparent",
width: element.width,
height: element.height,
strokeColor: element.strokeColor || DEFAULT_ELEMENT_PROPS.strokeColor,
backgroundColor:
element.backgroundColor || DEFAULT_ELEMENT_PROPS.backgroundColor,
width: element.width || 0,
height: element.height || 0,
seed: element.seed ?? 1,
groupIds: element.groupIds ?? [],
roundness: element.roundness
@ -196,7 +199,6 @@ const restoreElement = (
lineHeight,
);
element = restoreElementWithProperties(element, {
type: "text",
fontSize,
fontFamily,
text,

View file

@ -49,6 +49,7 @@ import {
import { isArrowElement } from "./typeChecks";
import { MarkOptional, Merge, Mutable } from "../utility-types";
import { ImportedDataState } from "../data/types";
import { restoreElementWithProperties } from "../data/restore";
export const ELEMENTS_SUPPORTING_PROGRAMMATIC_API = [
"rectangle",
@ -103,7 +104,6 @@ const _newElementBase = <T extends ExcalidrawElement>(
...rest
}: ElementConstructorOpts & Omit<Partial<ExcalidrawGenericElement>, "type">,
) => {
console.log("width", width);
// assign type to guard against excess properties
const element: Merge<ExcalidrawGenericElement, { type: T["type"] }> = {
id: rest.id || randomId(),
@ -668,8 +668,7 @@ export const convertToExcalidrawElements = (
return;
}
if (!ELEMENTS_SUPPORTING_PROGRAMMATIC_API.includes(element.type)) {
//@ts-ignore
res.push(element);
res.push(element as ExcalidrawElement);
return;
}
//@ts-ignore
@ -681,12 +680,11 @@ export const convertToExcalidrawElements = (
let excalidrawElement;
const { type, ...rest } = element;
if (element.type === "text") {
//@ts-ignore
excalidrawElement = newTextElement({
excalidrawElement = {
...element,
});
} as ExcalidrawTextElement;
} else if (type === "arrow" || type === "line") {
excalidrawElement = newLinearElement({
excalidrawElement = {
type,
width: 200,
height: 24,
@ -696,10 +694,9 @@ export const convertToExcalidrawElements = (
[200, 0],
],
...rest,
});
} as ExcalidrawLinearElement;
} else {
//@ts-ignore
excalidrawElement = newElement({
excalidrawElement = {
...element,
width:
element?.width ||
@ -711,9 +708,8 @@ export const convertToExcalidrawElements = (
(ELEMENTS_SUPPORTING_PROGRAMMATIC_API.includes(element.type)
? 100
: 0),
});
} as ExcalidrawGenericElement;
}
res.push(excalidrawElement);
}
});

View file

@ -91,7 +91,6 @@ export const redrawTextBoundingBox = (
textElement as ExcalidrawTextElementWithContainer,
);
const maxContainerWidth = getBoundTextMaxWidth(container);
console.log(metrics, maxContainerWidth, container);
if (metrics.height > maxContainerHeight) {
const nextHeight = computeContainerDimensionForBoundText(
metrics.height,

View file

@ -187,28 +187,17 @@ export default function App({ appTitle, useCustom, customArgs }: AppProps) {
[
{
type: "rectangle",
version: 141,
versionNonce: 361174001,
isDeleted: false,
id: "oDVXy8D6rom3H1-LLH2-f",
fillStyle: "hachure",
strokeWidth: 1,
strokeStyle: "solid",
roughness: 1,
opacity: 100,
angle: 0,
x: 100.50390625,
y: 93.67578125,
strokeColor: "#c92a2a",
backgroundColor: "transparent",
width: 186.47265625,
height: 141.9765625,
seed: 1968410350,
groupIds: [],
boundElements: null,
locked: false,
link: null,
updated: 1,
roundness: {
type: ROUNDNESS.ADAPTIVE_RADIUS,
value: 32,

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff