Implement

This commit is contained in:
yuto-yuto
2021-07-09 03:49:18 +02:00
parent ed05952bd1
commit 9211a8308a
26 changed files with 3596 additions and 301 deletions

View File

@@ -0,0 +1,57 @@
import "mocha";
import { expect } from "chai";
// import * as helper from "node-red-node-test-helper";
import helper = require("node-red-node-test-helper");
import valueChangeNode = require("../lib/PasswordGeneratorNode");
describe("PasswordGeneratorNode", () => {
before(() => {
helper.init(require.resolve('node-red'));
});
beforeEach((done) => {
helper.startServer(done);
});
afterEach((done) => {
helper.unload().then(() => helper.stopServer(done));
});
const nodeId = "node-id";
const outNodeId = "out-node-id";
const flows = [
{
id: nodeId,
type: "password-generator",
size: 10,
setTo: "payload.value",
name: "generator-name",
wires: [[outNodeId]]
},
{
id: outNodeId,
type: "helper",
}
];
it("should be loaded", (done) => {
helper.load([valueChangeNode], flows, () => {
const node = helper.getNode(nodeId);
expect(node.name).to.equal("generator-name");
done();
}).catch(done);
});
it("should set value to the property specified in setTo", (done) => {
helper.load([valueChangeNode], flows, () => {
const node = helper.getNode(nodeId);
const outNode = helper.getNode(outNodeId);
outNode.on("input", (msg: any) => {
expect(msg.payload.value).not.to.be.undefined;
done();
});
node.receive({ payload: 1 });
}).catch(done);
});
});

View File

@@ -0,0 +1,11 @@
import "mocha";
import { expect } from "chai";
import { generatePassword } from "../lib/PasswordGenerator";
describe.only("PasswordGenerator", () => {
it("should return true for the first time", async () => {
const result = await generatePassword(10);
console.log(`before: "${result}"`)
expect(result).to.lengthOf(10);
});
});

View File

@@ -1,43 +0,0 @@
import "mocha";
import { expect } from "chai";
import { ValueChangeDetector } from "../lib/ValueChangeDetector";
describe("ValueChangeDetector", () => {
let instance: ValueChangeDetector;
beforeEach(() => {
instance = new ValueChangeDetector();
});
describe("isUpdated", () => {
it("should return true for the first time", () => {
const result = instance.isUpdated({ key: 1, value: 1 });
expect(result).to.equal(true);
});
it("should return false when specifying the same data", () => {
const data = { key: "key", value: "value" };
instance.update(data);
const result = instance.isUpdated({ ...data });
expect(result).to.equal(false);
});
it("should return true for different key", () => {
instance.update({ key: "key", value: "value" });
const result = instance.isUpdated({ key: "key2", value: "value" });
expect(result).to.equal(true);
});
it("should convert number to string for key", () => {
instance.update({ key: 1, value: "value" });
const result = instance.isUpdated({ key: "1", value: "value" });
expect(result).to.equal(false);
});
it("should convert object to string for key", () => {
instance.update({ key: { obj: 1 }, value: "value" });
const result = instance.isUpdated({ key: { obj: 1 }, value: "value" });
expect(result).to.equal(false);
});
});
});