Skip to content

Commit 758433f

Browse files
committed
add unit tests
1 parent 8267a5f commit 758433f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/utils/constructChangesetUrl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const constructChangesetUrl = (task) => {
22
if (
33
process.env.REACT_APP_CHANGESET_URL === "enabled" &&
4+
task?.parent?.id &&
45
task.parent.changesetUrl
56
) {
67
return ` ${window.location.origin}/browse/challenges/${task.parent.id}`;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { constructChangesetUrl } from "./constructChangesetUrl";
2+
3+
describe("constructChangesetUrl", () => {
4+
const cachedEnv = process.env;
5+
6+
beforeEach(() => {
7+
jest.resetModules();
8+
process.env = { ...cachedEnv, REACT_APP_CHANGESET_URL: "enabled" };
9+
});
10+
11+
afterAll(() => {
12+
process.env = cachedEnv;
13+
});
14+
15+
it("returns empty string if no task is provided", () => {
16+
expect(constructChangesetUrl()).toBe("");
17+
});
18+
19+
it("returns empty string if env variabled is disabled", () => {
20+
process.env.REACT_APP_CHANGESET_URL = "disabled";
21+
const task = { parent: { changesetUrl: true, id: 1 } };
22+
expect(constructChangesetUrl(task)).toBe("");
23+
});
24+
25+
it("returns empty string changesetUrl is false", () => {
26+
const task = { parent: { changesetUrl: false, id: 1 } };
27+
expect(constructChangesetUrl(task)).toBe("");
28+
});
29+
30+
it("returns correct url if changesetUrl is true", () => {
31+
const task = { parent: { changesetUrl: true, id: 1 } };
32+
expect(constructChangesetUrl(task)).toBe(
33+
" http://localhost/browse/challenges/1"
34+
);
35+
});
36+
});

0 commit comments

Comments
 (0)