Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #126 from prompt-engineering/dev
Browse files Browse the repository at this point in the history
merge for fixed bugs
  • Loading branch information
phodal committed Mar 20, 2023
2 parents cf6a290 + 6420608 commit cafd5a3
Show file tree
Hide file tree
Showing 25 changed files with 317 additions and 851 deletions.
18 changes: 16 additions & 2 deletions __tests__/flows/jsonPath.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "@testing-library/jest-dom";
import { jsonPath } from "@/flows/flow-functions/jsonPath";
import "@testing-library/jest-dom";

describe("Json Parse for function", () => {
it("parse", () => {
Expand All @@ -10,7 +10,21 @@ describe("Json Parse for function", () => {
{ name: "Rome", population: 2870528 },
];

const names = jsonPath(cities, "$..name");
const names = jsonPath(cities, "$..name", ["name"]);
expect(names.length).toEqual(4);
expect(names[0]).toEqual({ name: "London" });
});

it("match name and population", () => {
const cities = [
{ name: "London", population: 8615246 },
{ name: "Berlin", population: 3517424 },
{ name: "Madrid", population: 3165235 },
{ name: "Rome", population: 2870528 },
];

const result = jsonPath(cities, "$..[name,population]", ["name", "population"]);
expect(result.length).toEqual(4);
expect(result[0]).toEqual({ name: "London", population: 8615246 });
});
});
50 changes: 50 additions & 0 deletions __tests__/flows/math.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import "@testing-library/jest-dom";
import { math } from "@/flows/flow-functions/math";

describe("Math Evaluator", () => {
it("simple eval", () => {
expect(math("value + 1", 1)).toEqual(2);
});

it("with object", () => {
const demoObject = {
x: 123,
y: 456,
};

expect(math("value.x + 3", demoObject, "x")).toEqual({
x: 126,
y: 456,
});
});

it("with array", () => {
const demoArray = [1, 2, 3, 4, 5];
const result = math("value + 1", demoArray);
expect(result).toEqual([2, 3, 4, 5, 6]);
});

it("with object array", () => {
const demoArray = [
{
x: 1,
y: 2,
},
{
x: 3,
y: 4,
},
];
const result = math("value.x + 1", demoArray, "x");
expect(result).toEqual([
{
x: 2,
y: 2,
},
{
x: 4,
y: 4,
},
]);
});
});
4 changes: 4 additions & 0 deletions __tests__/step-detail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ describe("Step Valued", () => {
values: {
placeholder: "用户通过主菜单进入“权限管理”模块,选择“账号管理”Tab页,可以看到“新增账号”按钮。",
},
preActions: [],
postActions: [],
};
let result = fillStepWithValued(step, {});
expect(result.replaced).toEqual(true);
Expand All @@ -24,6 +26,8 @@ describe("Step Valued", () => {
ask: "story: $$response:1$$",
cachedResponseRegex: "/.*/",
values: {},
preActions: [],
postActions: [],
};
let result = fillStepWithValued(step, {
1: "Cached Value",
Expand Down
Empty file removed docs/development.md
Empty file.
4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ const createJestConfig = nextJest({
const customJestConfig = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],

testEnvironment: "jest-environment-jsdom",
moduleNameMapper: {
"^jsonpath-plus": require.resolve("jsonpath-plus"),
"^lodash-es$": "lodash",
"^@/(.*)": "<rootDir>/src/$1",
},
transformIgnorePatterns: ["/node_modules/", "^.+\\.module\\.(css|sass|scss)$"],
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
Expand Down

0 comments on commit cafd5a3

Please sign in to comment.