-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathAngularGenerator.test.js
97 lines (89 loc) · 3.73 KB
/
AngularGenerator.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { Api, Resource, Field } from "@api-platform/api-doc-parser";
import path from "path";
import { fileURLToPath } from "url";
import fs from "fs";
import tmp from "tmp";
import AngularGenerator from "./AngularGenerator.js";
const dirname = path.dirname(fileURLToPath(import.meta.url));
const generator = new AngularGenerator({
hydraPrefix: "hydra:",
templateDirectory: `${dirname}/../../templates`,
});
afterEach(() => {
jest.resetAllMocks();
});
describe("generate", () => {
test("Generate an Angular app", () => {
const tmpobj = tmp.dirSync({ unsafeCleanup: true });
const fields = [
new Field("bar", {
id: "http://schema.org/url",
range: "http://www.w3.org/2001/XMLSchema#string",
reference: null,
required: true,
description: "An URL",
}),
];
const resource = new Resource("abc", "http://example.com/foos", {
id: "abc",
title: "abc",
readableFields: fields,
writableFields: fields,
});
const api = new Api("http://example.com", {
entrypoint: "http://example.com:8080",
title: "My API",
resources: [resource],
});
generator.generate(api, resource, tmpobj.name);
[
"app/components/common/delete/delete.component.html",
"app/components/common/delete/delete.component.ts",
"app/components/common/header/header.component.css",
"app/components/common/header/header.component.html",
"app/components/common/header/header.component.ts",
"app/components/common/layout/layout.component.html",
"app/components/common/layout/layout.component.ts",
"app/components/common/pagination/pagination.component.html",
"app/components/common/pagination/pagination.component.ts",
"app/components/common/sidebar/sidebar.component.css",
"app/components/common/sidebar/sidebar.component.html",
"app/components/common/sidebar/sidebar.component.ts",
"app/components/common/svg/list-svg/list-svg.component.svg",
"app/components/common/svg/list-svg/list-svg.component.ts",
"app/components/common/svg/show-svg/show-svg.component.svg",
"app/components/common/svg/show-svg/show-svg.component.ts",
"app/components/common/svg/edit-svg/edit-svg.component.svg",
"app/components/common/svg/edit-svg/edit-svg.component.ts",
"app/components/common/svg/menu/menu.component.svg",
"app/components/common/svg/menu/menu.component.ts",
"app/components/common/back-to-list/back-to-list.component.html",
"app/components/common/back-to-list/back-to-list.component.ts",
"app/components/common/alert/alert.component.html",
"app/components/common/alert/alert.component.ts",
"app/interface/api.ts",
"app/router/foo.ts",
"app/service/api.service.ts",
].forEach((file) => expect(fs.existsSync(tmpobj.name + file)).toBe(true));
[
"app/router/abc.ts",
"app/components/abc/list/list.component.html",
"app/components/abc/list/list.component.ts",
"app/components/abc/create/create.component.html",
"app/components/abc/create/create.component.ts",
"app/components/abc/edit/edit.component.html",
"app/components/abc/edit/edit.component.ts",
"app/components/abc/form/form.component.html",
"app/components/abc/form/form.component.ts",
"app/components/abc/show/show.component.html",
"app/components/abc/show/show.component.ts",
"app/components/abc/show/show.component.html",
"app/components/abc/table/table.component.html",
"app/components/abc/table/table.component.ts",
].forEach((file) => {
expect(fs.existsSync(tmpobj.name + file)).toBe(true);
expect(fs.readFileSync(tmpobj.name + file, "utf8")).toMatch(/bar/);
});
tmpobj.removeCallback();
});
});