Skip to content

Commit 081bcb1

Browse files
committed
[Bug#642] Update tests.
1 parent 6ca652c commit 081bcb1

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

src/component/term/__tests__/CreateTerm.test.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import { langString } from "../../../model/MultilingualString";
1313
import Constants from "../../../util/Constants";
1414
import { intlFunctions } from "../../../__tests__/environment/IntlUtil";
1515

16-
jest.mock("../../../util/Routing");
16+
jest.mock("../../../util/Routing", () => ({
17+
default: jest.fn(),
18+
namespaceQueryParam: jest.requireActual("../../../util/Routing")
19+
.namespaceQueryParam,
20+
}));
1721

1822
describe("CreateTerm", () => {
1923
const namespace = "http://onto.fel.cvut.cz/ontologies/termit/vocabularies/";
@@ -59,6 +63,8 @@ describe("CreateTerm", () => {
5963
isExact: true,
6064
url: "http://localhost:3000/" + location.pathname,
6165
};
66+
Routing.transitionTo = jest.fn();
67+
Routing.reload = jest.fn();
6268
});
6369

6470
it("invokes on create on create call", () => {
@@ -107,7 +113,9 @@ describe("CreateTerm", () => {
107113
"test-term"
108114
);
109115
expect((call[1].query as Map<string, string>).get("namespace")).toEqual(
110-
"http://onto.fel.cvut.cz/ontologies/termit/vocabularies/"
116+
encodeURIComponent(
117+
"http://onto.fel.cvut.cz/ontologies/termit/vocabularies/"
118+
)
111119
);
112120
});
113121
});
@@ -135,7 +143,9 @@ describe("CreateTerm", () => {
135143
"test-vocabulary"
136144
);
137145
expect((call[1].query as Map<string, string>).get("namespace")).toEqual(
138-
"http://onto.fel.cvut.cz/ontologies/termit/vocabularies/"
146+
encodeURIComponent(
147+
"http://onto.fel.cvut.cz/ontologies/termit/vocabularies/"
148+
)
139149
);
140150
});
141151
});

src/component/term/__tests__/TermLink.test.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ describe("TermLink", () => {
5454
</MemoryRouter>
5555
).find(Link);
5656
expect((link.props() as any).to).toEqual(
57-
`/vocabularies/${vocFragment}/terms/${termFragment}?namespace=${vocNamespace}`
57+
`/vocabularies/${vocFragment}/terms/${termFragment}?namespace=${encodeURIComponent(
58+
vocNamespace
59+
)}`
5860
);
5961
});
6062

@@ -93,7 +95,9 @@ describe("TermLink", () => {
9395
</MemoryRouter>
9496
).find(Link);
9597
expect((link.props() as any).to).toEqual(
96-
`/public/vocabularies/${vocFragment}/terms/${termFragment}?namespace=${vocNamespace}`
98+
`/public/vocabularies/${vocFragment}/terms/${termFragment}?namespace=${encodeURIComponent(
99+
vocNamespace
100+
)}`
97101
);
98102
});
99103

src/component/vocabulary/__tests__/VocabularyLink.test.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ describe("Vocabulary Link links to correct internal asset", () => {
3131
</MemoryRouter>
3232
).find(Link);
3333
expect((link.props() as any).to).toEqual(
34-
"/vocabularies/" + fragment + "?namespace=" + namespace
34+
"/vocabularies/" +
35+
fragment +
36+
"?namespace=" +
37+
encodeURIComponent(namespace)
3538
);
3639
});
3740

@@ -43,7 +46,10 @@ describe("Vocabulary Link links to correct internal asset", () => {
4346
</MemoryRouter>
4447
).find(Link);
4548
expect((link.props() as any).to).toEqual(
46-
"/public/vocabularies/" + fragment + "?namespace=" + namespace
49+
"/public/vocabularies/" +
50+
fragment +
51+
"?namespace=" +
52+
encodeURIComponent(namespace)
4753
);
4854
});
4955
});

src/util/__tests__/Routing.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ describe("Routing", () => {
3535
const name = "test-vocabulary";
3636
const namespace = "http://onto.fel.cvut.cz/ontologies/termit/vocabulary/";
3737
const path = Routing.getTransitionPath(Routes.vocabularies, {
38-
query: new Map([["namespace", namespace]]),
38+
query: new Map([["namespace", encodeURIComponent(namespace)]]),
3939
});
4040
const expectedPath =
4141
Routes.vocabularies.path.replace(":name", name) +
4242
"?namespace=" +
43-
namespace;
43+
encodeURIComponent(namespace);
4444
expect(path).toEqual(expectedPath);
4545
});
4646
});
@@ -58,14 +58,14 @@ describe("Routing", () => {
5858
const iri = namespace + label;
5959

6060
it("transitions to vocabulary summary for a vocabulary", () => {
61-
const vocabulary = new Vocabulary({ iri, label });
61+
const vocabulary = new Vocabulary({ iri, label: langString(label) });
6262
TermItStore.getState().user = Generator.generateUser();
6363

6464
RoutingInstance.transitionToAsset(vocabulary);
6565
expect(historyMock.push).toHaveBeenCalledWith(
6666
Routing.getTransitionPath(Routes.vocabularySummary, {
6767
params: new Map([["name", label]]),
68-
query: new Map([["namespace", namespace]]),
68+
query: new Map([["namespace", encodeURIComponent(namespace)]]),
6969
})
7070
);
7171
});
@@ -87,7 +87,7 @@ describe("Routing", () => {
8787
["name", label],
8888
["timestamp", timestamp],
8989
]),
90-
query: new Map([["namespace", namespace]]),
90+
query: new Map([["namespace", encodeURIComponent(namespace)]]),
9191
})
9292
);
9393
});
@@ -105,7 +105,7 @@ describe("Routing", () => {
105105
["name", label],
106106
["termName", termName],
107107
]),
108-
query: new Map([["namespace", namespace]]),
108+
query: new Map([["namespace", encodeURIComponent(namespace)]]),
109109
})
110110
);
111111
});
@@ -129,7 +129,7 @@ describe("Routing", () => {
129129
["termName", termName],
130130
["timestamp", timestamp],
131131
]),
132-
query: new Map([["namespace", namespace]]),
132+
query: new Map([["namespace", encodeURIComponent(namespace)]]),
133133
})
134134
);
135135
});
@@ -142,12 +142,12 @@ describe("Routing", () => {
142142

143143
it("transitions to public vocabulary summary for a vocabulary", () => {
144144
TermItStore.getState().user = EMPTY_USER;
145-
const vocabulary = new Vocabulary({ iri, label });
145+
const vocabulary = new Vocabulary({ iri, label: langString(label) });
146146
RoutingInstance.transitionToPublicAsset(vocabulary);
147147
expect(historyMock.push).toHaveBeenCalledWith(
148148
Routing.getTransitionPath(Routes.publicVocabularySummary, {
149149
params: new Map([["name", label]]),
150-
query: new Map([["namespace", namespace]]),
150+
query: new Map([["namespace", encodeURIComponent(namespace)]]),
151151
})
152152
);
153153
});
@@ -164,7 +164,7 @@ describe("Routing", () => {
164164
["name", label],
165165
["termName", term.label[Constants.DEFAULT_LANGUAGE]],
166166
]),
167-
query: new Map([["namespace", namespace]]),
167+
query: new Map([["namespace", encodeURIComponent(namespace)]]),
168168
})
169169
);
170170
});

0 commit comments

Comments
 (0)