Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 45791fa

Browse files
authored
Merge pull request #42 from agile-ts/tests/rewrite-tests
Tests/rewrite tests
2 parents d33dfd0 + 8937849 commit 45791fa

File tree

122 files changed

+20947
-11616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+20947
-11616
lines changed

examples/AwesomeTSProject/__tests__/App-test.tsx

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/react-typescript/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SKIP_PREFLIGHT_CHECK=true

examples/react-typescript/package-lock.json

Lines changed: 314 additions & 525 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/react-typescript/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
"typescript": "^3.9.7"
1616
},
1717
"devDependencies": {
18-
"@testing-library/jest-dom": "^4.2.4",
1918
"@testing-library/react": "^9.3.2",
2019
"@testing-library/user-event": "^7.1.2",
21-
"@types/jest": "^24.0.0",
2220
"@types/node": "^12.0.0",
2321
"@types/react": "^16.9.0",
2422
"@types/react-dom": "^16.9.0",

examples/react-typescript/src/App.tsx

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useEffect } from "react";
22
import "./App.css";
33
import { useAgile, useEvent, useWatcher } from "@agile-ts/react";
44
import {
5-
multiEditor,
65
MY_COLLECTION,
76
MY_COMPUTED,
87
MY_EVENT,
@@ -49,8 +48,6 @@ const App = (props: any) => {
4948
console.log("MY_STATE changes");
5049
});
5150

52-
useAgile(multiEditor.deps);
53-
5451
// Create global Instance of Core (for better debugging)
5552
useEffect(() => {
5653
globalBind("__core__", { ...require("./core") });
@@ -120,43 +117,8 @@ const App = (props: any) => {
120117
<button onClick={() => MY_COLLECTION.removeSelector("mySelector")}>
121118
Remove mySelector
122119
</button>
123-
</header>
124-
125-
<form>
126-
<label>Name</label>
127-
<input
128-
name={"name"}
129-
onChange={(e) => {
130-
multiEditor.setValue("name", e.target.value, { background: false });
131-
}}
132-
value={multiEditor.getValueById("name")}
133-
/>
134-
{multiEditor.getStatus("name")?.type === "error" && (
135-
<p style={{ color: "red" }}>
136-
{multiEditor.getStatus("name")?.message}
137-
</p>
138-
)}
139-
140-
<label>Email</label>
141-
<input
142-
name={"email"}
143-
onChange={(e) => multiEditor.setValue("email", e.target.value)}
144-
/>
145-
{multiEditor.getStatus("email")?.type === "error" && (
146-
<p style={{ color: "red" }}>
147-
{multiEditor.getStatus("email")?.message}
148-
</p>
149-
)}
150-
151120
<p>{rerenderCount}</p>
152-
</form>
153-
<button
154-
onClick={() => {
155-
multiEditor.submit();
156-
}}
157-
>
158-
Submit
159-
</button>
121+
</header>
160122
</div>
161123
);
162124
};

examples/react-typescript/src/core/index.ts

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { Agile } from "@agile-ts/core";
2-
import { MultiEditor, Validator } from "@agile-ts/multieditor";
1+
import { Agile, clone, Logger } from "@agile-ts/core";
32

43
export const App = new Agile({
5-
logConfig: { active: true },
4+
logConfig: { level: Logger.level.DEBUG },
65
});
76

8-
export const MY_STATE = App.State<string>("MyState", "my-state"); //.persist();
9-
export const MY_STATE_2 = App.State<string>("MyState2").persist("my-state2");
7+
export const MY_STATE = App.State<string>("MyState", { key: "my-state" }); //.persist();
8+
export const MY_STATE_2 = App.State<string>("MyState2", {
9+
key: "my-state2",
10+
}).persist();
1011
MY_STATE_2.onLoad(() => {
1112
console.log("On Load");
1213
});
@@ -18,7 +19,7 @@ MY_STATE.watch("test", (value: any) => {
1819

1920
export const MY_COMPUTED = App.Computed<string>(() => {
2021
return "test" + MY_STATE.value + "_computed_" + MY_STATE_2.value;
21-
});
22+
}, []);
2223

2324
interface collectionValueInterface {
2425
id: string;
@@ -39,12 +40,15 @@ export const MY_COLLECTION = App.Collection<collectionValueInterface>(
3940
MY_COLLECTION.collect({ id: "id1", name: "test" });
4041
MY_COLLECTION.collect({ id: "id2", name: "test2" }, "myGroup");
4142
MY_COLLECTION.update("id1", { id: "id1Updated", name: "testUpdated" });
42-
MY_COLLECTION.getGroup("myGroup")?.persist({ followCollectionPattern: true });
43+
MY_COLLECTION.getGroup("myGroup")?.persist({
44+
followCollectionPersistKeyPattern: true,
45+
});
4346

44-
console.log("Initial: myCollection ", MY_COLLECTION);
47+
console.log("Initial: myCollection ", clone(MY_COLLECTION));
4548

4649
export const MY_EVENT = App.Event<{ name: string }>({
4750
delay: 3000,
51+
key: "myEvent",
4852
});
4953

5054
MY_EVENT.on(() => {
@@ -55,51 +59,6 @@ MY_EVENT.on("Test", () => {
5559
console.log("Triggered Event (Test)");
5660
});
5761

58-
// MULTIEDITOR TEST
59-
60-
const emailValidator = new Validator().string().email().required();
61-
62-
export const multiEditor = new MultiEditor<string | undefined, boolean>(
63-
(editor) => ({
64-
data: {
65-
id: "myId",
66-
email: undefined,
67-
name: undefined,
68-
},
69-
onSubmit: async (data) => {
70-
console.log("Submitted MultiEditor", data);
71-
return Promise.resolve(true);
72-
},
73-
fixedProperties: ["id"],
74-
validateMethods: {
75-
email: emailValidator,
76-
name: editor
77-
.Validator()
78-
.required()
79-
.string()
80-
.max(10)
81-
.min(2)
82-
.addValidationMethod("testFuck", (key, value, editor) => {
83-
const isValid = value !== "Fuck";
84-
85-
if (!isValid) {
86-
editor.setStatus(key, "error", "Fuck is no valid Name!");
87-
}
88-
89-
return Promise.resolve(isValid);
90-
}),
91-
},
92-
computeMethods: {
93-
name: (value) => {
94-
return value ? value?.charAt(0).toUpperCase() + value?.slice(1) : value;
95-
},
96-
},
97-
editableProperties: ["email", "name"],
98-
reValidateMode: "onChange",
99-
validate: "all",
100-
})
101-
);
102-
10362
// LOGGER tests
10463

10564
/*

jest.config.base.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
testEnvironment: "node",
3+
coveragePathIgnorePatterns: ["(tests/.*.mock).(jsx?|tsx?)$"],
4+
modulePathIgnorePatterns: ["dist"],
5+
testMatch: ["<rootDir>/packages/**/tests/**/*.test.ts"],
6+
transform: {
7+
"^.+\\.ts?$": "ts-jest",
8+
},
9+
};

jest.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const baseConfig = require("./jest.config.base.js");
2+
3+
module.exports = {
4+
...baseConfig,
5+
projects: ["<rootDir>/packages/*/jest.config.js"],
6+
};

0 commit comments

Comments
 (0)