Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,23 @@ import {
mockSentimentPredicate,
mockSentimentResultLink,
} from "./mock-workflow-data";
import { WorkflowGraph } from "./workflow-graph";
import {
DUAL_INPUT_PORTS_PYTHON_UDF_V2_OP_TYPE,
isPythonUdf,
isSink,
PYTHON_UDF_SOURCE_V2_OP_TYPE,
PYTHON_UDF_V2_OP_TYPE,
VIEW_RESULT_OP_TYPE,
WorkflowGraph,
} from "./workflow-graph";
import { Observable } from "rxjs";
import { Comment, OperatorLink, PortDescription, PortProperty } from "../../../types/workflow-common.interface";
import {
Comment,
OperatorLink,
OperatorPredicate,
PortDescription,
PortProperty,
} from "../../../types/workflow-common.interface";

describe("WorkflowGraph", () => {
let workflowGraph: WorkflowGraph;
Expand Down Expand Up @@ -815,4 +829,70 @@ describe("WorkflowGraph", () => {
sub.unsubscribe();
});
});

describe("isSink", () => {
const makeOperator = (operatorType: string): OperatorPredicate => ({
operatorID: "op",
operatorType,
operatorVersion: "v",
operatorProperties: {},
inputPorts: [],
outputPorts: [],
showAdvanced: true,
isDisabled: false,
});

it("should return true for the view-result sink operator type", () => {
expect(isSink(makeOperator(VIEW_RESULT_OP_TYPE))).toBe(true);
});

it("should return true whenever the operator type contains 'sink' as a substring", () => {
expect(isSink(makeOperator("CsvFileSink"))).toBe(true);
expect(isSink(makeOperator("SinkOperator"))).toBe(true);
});

it("should match case-insensitively", () => {
expect(isSink(makeOperator("SINK"))).toBe(true);
expect(isSink(makeOperator("SiNk"))).toBe(true);
expect(isSink(makeOperator("mySINKop"))).toBe(true);
});
Comment thread
Ma77Ball marked this conversation as resolved.

it("should return false for operator types that do not contain 'sink'", () => {
expect(isSink(makeOperator("ScanSource"))).toBe(false);
expect(isSink(makeOperator("NlpSentiment"))).toBe(false);
expect(isSink(makeOperator(""))).toBe(false);
});
});

describe("isPythonUdf", () => {
const makeOperator = (operatorType: string): OperatorPredicate => ({
operatorID: "op",
operatorType,
operatorVersion: "v",
operatorProperties: {},
inputPorts: [],
outputPorts: [],
showAdvanced: true,
isDisabled: false,
});

it("should return true for the single-input Python UDF v2 type", () => {
expect(isPythonUdf(makeOperator(PYTHON_UDF_V2_OP_TYPE))).toBe(true);
});

it("should return true for the Python UDF source v2 type", () => {
expect(isPythonUdf(makeOperator(PYTHON_UDF_SOURCE_V2_OP_TYPE))).toBe(true);
});

it("should return true for the dual-input-ports Python UDF v2 type", () => {
expect(isPythonUdf(makeOperator(DUAL_INPUT_PORTS_PYTHON_UDF_V2_OP_TYPE))).toBe(true);
});

it("should return false for operator types outside the Python UDF list", () => {
expect(isPythonUdf(makeOperator("JavaUDF"))).toBe(false);
expect(isPythonUdf(makeOperator("ScanSource"))).toBe(false);
// membership is exact and case-sensitive, so a differently-cased variant must not match
expect(isPythonUdf(makeOperator(PYTHON_UDF_V2_OP_TYPE.toLowerCase()))).toBe(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const VIEW_RESULT_OP_TYPE = "SimpleSink";
export const VIEW_RESULT_OP_NAME = "View Results";

export function isSink(operator: OperatorPredicate): boolean {
return operator.operatorType.toLocaleLowerCase().includes("sink");
return operator.operatorType.toLowerCase().includes("sink");
}

export function isPythonUdf(operator: OperatorPredicate): boolean {
Expand Down
Loading