-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjest.setup.ts
115 lines (96 loc) · 2.8 KB
/
jest.setup.ts
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import clownface, { AnyPointer } from "clownface";
import rdf from "rdf-ext";
import DatasetExt from "rdf-ext/lib/Dataset";
import DefaultGraphExt from "rdf-ext/lib/DefaultGraph";
import { NamedNode, Term } from "rdf-js";
import { createClient, defaultExchanges } from "urql";
import { GRAPHQL_ENDPOINT } from "@/domain/env";
import * as ns from "@/rdf/namespace";
jest.mock("nanoid", () => {
return {
nanoid: () => "nanoid",
};
});
// @ts-ignore Ignoring cannot be compiled as isolated module warning. It's working.
jest.mock("@lingui/macro", () => {
return {
// Since it's a macro, it's not defined at runtime, maybe in the future
// we should add a transformer so that jest files are transformed the same
// way as app files so that the macro is defined inside files that are ran by Jest.
defineMessage: (x: string) => x,
};
});
jest.mock("@/graphql/client", () => {
return {
client: createClient({
url: GRAPHQL_ENDPOINT,
exchanges: [...defaultExchanges],
}),
};
});
jest.mock("rdf-cube-view-query", () => ({
Node: class {
constructor() {}
},
Source: class {
constructor() {}
},
Cube: class {
constructor() {}
},
CubeDimension: class {
ptr: AnyPointer;
constructor({
term = rdf.blankNode(),
dataset = rdf.dataset(),
graph = rdf.defaultGraph(),
}: {
term?: Term;
dataset?: DatasetExt;
graph?: DefaultGraphExt;
} = {}) {
this.ptr = clownface({ term, dataset, graph });
}
get path() {
return this.ptr.out(ns.sh.path).term;
}
get optional() {
const optionalDatatype = this.ptr
.out(ns.sh.or)
.out(ns.sh.datatype)
.filter((d) => ns.cube.Undefined.equals(d.term)).term;
const optionalValue = this.in.some((v) => ns.cube.Undefined.equals(v));
return Boolean(optionalDatatype || optionalValue);
}
get datatype() {
const nonOptional = this.ptr.out(ns.sh.datatype).term;
const withOptional = this.ptr
.out(ns.sh.or)
.out(ns.sh.datatype)
.filter((d) => !ns.cube.Undefined.equals(d.term)).term;
return nonOptional || withOptional;
}
get minExclusive() {
return this.ptr.out(ns.sh.minExclusive).term;
}
get minInclusive() {
return this.ptr.out(ns.sh.minInclusive).term;
}
get maxExclusive() {
return this.ptr.out(ns.sh.maxExclusive).term;
}
get maxInclusive() {
return this.ptr.out(ns.sh.maxInclusive).term;
}
get in() {
return [...(this.ptr.out(ns.sh.in).list() ?? [])].map(
(item) => item.term
);
}
out(...args: NamedNode[]) {
return this.ptr.out(...args);
}
},
}));
jest.mock("@zazuko/cube-hierarchy-query/index", () => ({}));
jest.mock("@interactivethings/swiss-federal-ci/dist/components", () => {});