Skip to content

Commit

Permalink
add tests for TypeScript definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
samueldmeyer committed Jan 23, 2025
1 parent a848797 commit b79c89a
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 35 deletions.
8 changes: 5 additions & 3 deletions canvas_modules/common-canvas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"types": "./types/index.d.ts",
"scripts": {
"build": "npx stylelint '**/*.scss' && grunt && rollup -c",
"test": "NODE_ENV=test jest",
"test:jest": "NODE_ENV=test jest",
"test:typescript": "tsd",
"test": "npm run test:jest && npm run test:typescript",
"test-coverage": "NODE_ENV=test jest --coverage",
"bundle-report": "BUNDLE_REPORT=true rollup -c",
"debug": "NODE_ENV=test node --inspect-brk node_modules/.bin/jest --runInBand"
Expand Down Expand Up @@ -106,6 +108,7 @@
"sass": "1.71.1",
"sinon": "9.0.3",
"stylelint": "13.13.1",
"tsd": "^0.31.2",
"url": "0.11.3"
},
"peerDependencies": {
Expand All @@ -116,8 +119,7 @@
},
"jest": {
"testEnvironment": "jest-fixed-jsdom",
"transformIgnorePatterns": [
],
"transformIgnorePatterns": [],
"moduleFileExtensions": [
"js",
"jsx",
Expand Down
61 changes: 29 additions & 32 deletions canvas_modules/common-canvas/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ export declare class CanvasController {
categoryLabel?: string,
categoryDescription?: string,
categoryImage?: string
);
): void;
/**
* Removes nodetypes from a palette category
* @param selObjectIds - an array of object IDs to identify the nodetypes to be
Expand Down Expand Up @@ -756,12 +756,6 @@ export declare class CanvasController {
pipelineId?: string
): void;

openPalette(): void;
setLinkDecorations(
id: string,
decorations: LinkDecoration[],
pipelineId: string
);
/**
* Deletes the node specified.
* @param nodeId - The ID of the node
Expand Down Expand Up @@ -1080,7 +1074,7 @@ export declare class CanvasController {
* used (e.g. the toolbar button was clicked).
* pipelineId - The ID of the pipeline
*/
getNewCommentPosition(pipelineId): { x: number; y: number };
getNewCommentPosition(pipelineId: string): { x: number; y: number };
/**
* Creates a comment for the pipeline.
* @param source - Input data
Expand Down Expand Up @@ -1911,23 +1905,23 @@ export interface CommonPropertiesConfig {
* Default true to show (required) indicator. If set to false, show
* (optional) indicator next to properties label.
*/
showRequiredIndicator: boolean;
showRequiredIndicator?: boolean;
/**
* Default true to show “Alerts” tab whenever there are error or warning
* messages. If set to false, Alerts tab won’t be displayed.
*/
showAlertsTab: boolean;
showAlertsTab?: boolean;
/**
* Default []. When set this will filter out any values in the array in
* the parameters returned when applyPropertyChanges is call. Only
* primitive data types are currently supported.
*/
returnValueFiltering: unknown[] | string;
returnValueFiltering?: unknown[] | string;
/**
* View categories in right-flyout. Can be "accordions" or "tabs".
* default: "accordions".
*/
categoryView: "accordions" | "tabs";
categoryView?: "accordions" | "tabs";
}

/**
Expand Down Expand Up @@ -2562,34 +2556,37 @@ export interface ToolbarConfig {
export interface NotificationConfig {
action: string;
label: string;
enable: boolean;
notificationHeader: string;
notificationSubtitle: string;
enable?: boolean;
notificationHeader?: string;
notificationSubtitle?: string;
emptyMessage: string;
clearAllMessage: string;
keepOpen: boolean;
clearAllCallback: () => void;
clearAllMessage?: string;
keepOpen?: boolean;
clearAllCallback?: () => void;
secondaryButtonLabel?: string;
secondaryButtonCallback?: () => void;
secondaryButtonDisabled?: boolean;
}

export interface CtxMenuConfig {
enableCreateSupernodeNonContiguous: boolean;
defaultMenuEntries: {
saveToPalette: boolean;
createSupernode: boolean;
displaySupernodeFullPage: boolean;
colorBackground: boolean;
enableCreateSupernodeNonContiguous?: boolean;
defaultMenuEntries?: {
saveToPalette?: boolean;
createSupernode?: boolean;
displaySupernodeFullPage?: boolean;
colorBackground?: boolean;
};
}

export interface KeyboardConfig {
actions: {
delete: boolean;
undo: boolean;
redo: boolean;
selectAll: boolean;
cutToClipboard: boolean;
copyToClipboard: boolean;
pasteFromClipboard: boolean;
delete?: boolean;
undo?: boolean;
redo?: boolean;
selectAll?: boolean;
cutToClipboard?: boolean;
copyToClipboard?: boolean;
pasteFromClipboard?: boolean;
};
}

Expand Down Expand Up @@ -2760,7 +2757,7 @@ export interface CommonCanvasProps {
beforeEditActionHandler?: (
data: EditActionData,
command: EditActionCommand
) => EditActionCommand | void;
) => EditActionData | void;
/**
* https://elyra-ai.github.io/canvas/03.03.03-edit-action-handler/
*/
Expand Down
159 changes: 159 additions & 0 deletions canvas_modules/common-canvas/types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Copyright 2017-2025 Elyra Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
CanvasController,
CommonCanvas,
CommonProperties,
CommonPropertiesController,
} from ".";
import { expectType } from "tsd";

const canvasController = new CanvasController();

expectType<void>(canvasController.clearPipelineFlow());

expectType<void>(
canvasController.addNode({
id: "id1",
type: "execution_node",
op: "testOp",
x_pos: 5,
y_pos: 6,
app_data: {},
height: 10,
width: 20,
})
);
expectType<void>(
canvasController.addNode(
{
id: "id1",
type: "execution_node",
op: "testOp",
x_pos: 5,
y_pos: 6,
app_data: {},
height: 10,
width: 20,
},
"pipelineId1"
)
);
expectType<void>(
canvasController.addNode(
{
id: "id1",
type: "execution_node",
op: "testOp",
x_pos: 5,
y_pos: 6,
app_data: {
other_data: {
prop1: "Something interesting",
},
},
height: 10,
width: 20,
},
"pipelineId1"
)
);

expectType<void>(
canvasController.addNode(
canvasController.createNode({
nodeTemplate: { type: "execution_node", op: "testOp" },
offsetX: 1,
offsetY: 5,
})
)
);

class MyCustomControl {
static id() {
return "custom-control-1";
}

renderControl() {
return "react node";
}
}

let commonPropertiesController: CommonPropertiesController =
{} as CommonPropertiesController;

const commonProperties = new CommonProperties({
propertiesInfo: { parameterDef: {} },
callbacks: {
controllerHandler: (propertyController) => {
commonPropertiesController = propertyController;
},
},
customControls: [MyCustomControl],
propertiesConfig: { applyOnBlur: true },
});

expectType<unknown>(
commonPropertiesController.getControl({ name: "controlName" })
);
expectType<unknown>(
commonPropertiesController.getControl({ name: "controlName", row: 5 })
);
expectType<unknown>(
commonPropertiesController.getControl({ name: "controlName", row: 3, col: 2 })
);

const commonCanvasMinimal = new CommonCanvas({ canvasController });
expectType<CommonCanvas>(commonCanvasMinimal);

const commonCanvasAll = new CommonCanvas({
canvasController,
config: { enableLinkType: "Parallax" },
toolbarConfig: { leftBar: [], overrideAutoEnableDisable: true },
notificationConfig: {
action: "notification",
label: "label1",
emptyMessage: "No notifications",
},
contextMenuConfig: { enableCreateSupernodeNonContiguous: true },
keyboardConfig: { actions: { delete: false } },
contextMenuHandler: (source, defaultMenu) => defaultMenu,
beforeEditActionHandler: (data, command) => data,
editActionHandler: (data, command) => {
return undefined;
},
clickActionHandler: (source) => {
return undefined;
},
decorationActionHandler: (object, id, pipelineId) => {
return undefined;
},
layoutHandler: (data) => {
return { key1: "val1" };
},
tipHandler: (tipType, data) => "new tooltip text",
idGeneratorHandler: (action, data) => "new id",
selectionChangeHandler: (data) => {
return undefined;
},
actionLabelHandler: (action) => "Remove stuff",
showRightFlyout: true,
rightFlyoutContent: commonProperties.render(),
showBottomPanel: false,
bottomPanelContent: commonProperties.render(),
});
expectType<CommonCanvas>(commonCanvasAll);

0 comments on commit b79c89a

Please sign in to comment.