|
3 | 3 | */ |
4 | 4 | const { JSDOM } = require("jsdom"); |
5 | 5 | const $ = require("jquery"); |
6 | | -const { |
7 | | - updateNavigationPanel, |
8 | | - updateContents, |
9 | | - load_data, |
10 | | - getCurrentFolder, |
11 | | -} = require("../notebooker/index.js"); |
| 6 | +const { updateNavigationPanel, updateContents, load_data, getCurrentFolder } = require("../notebooker/index.js"); |
12 | 7 |
|
13 | 8 | const dom = new JSDOM(); |
14 | 9 | global.window = dom.window; |
15 | 10 | global.document = window.document; |
16 | 11 | global.fetch = jest.fn(); |
17 | 12 |
|
18 | 13 | describe("index.js", () => { |
19 | | - beforeEach(() => { |
20 | | - delete window.location; |
21 | | - window.location = { pathname: "/folder/test/my%20fake%20folder/hello" }; |
22 | | - $("body").html( |
23 | | - '<div id="folderNavigationPanel"></div><div id="cardContainer"></div>' |
24 | | - ); |
25 | | - fetch.mockClear(); |
26 | | - }); |
| 14 | + beforeEach(() => { |
| 15 | + delete window.location; |
| 16 | + window.location = { pathname: "/folder/test/my%20fake%20folder/hello" }; |
| 17 | + $("body").html('<div id="folderNavigationPanel"></div><div id="cardContainer"></div>'); |
| 18 | + fetch.mockClear(); |
| 19 | + }); |
27 | 20 |
|
28 | | - test("getCurrentFolder", () => { |
29 | | - expect(getCurrentFolder()).toBe("test/my fake folder/hello/"); |
30 | | - }); |
| 21 | + test("getCurrentFolder", () => { |
| 22 | + expect(getCurrentFolder()).toBe("test/my fake folder/hello/"); |
| 23 | + }); |
31 | 24 |
|
32 | | - test("updateNavigationPanel", () => { |
33 | | - console.log(updateNavigationPanel); |
34 | | - updateNavigationPanel("test/"); |
35 | | - expect($("#folderNavigationPanel").html()).toContain("test"); |
36 | | - }); |
| 25 | + test("updateNavigationPanel", () => { |
| 26 | + updateNavigationPanel("test/"); |
| 27 | + expect($("#folderNavigationPanel").html()).toContain("test"); |
| 28 | + }); |
37 | 29 |
|
38 | | - test("updateContents", () => { |
39 | | - const entries = {}; |
40 | | - entries["report"] = { |
41 | | - report_name: "report", |
42 | | - time_diff: "1 hour", |
43 | | - count: 1, |
44 | | - scheduler_runs: 1, |
45 | | - }; |
46 | | - entries["hello/world"] = { |
47 | | - report_name: "hello/world", |
48 | | - time_diff: "1 second", |
49 | | - count: 2, |
50 | | - scheduler_runs: 1, |
51 | | - }; |
52 | | - entries["folder with spaces/ and again/ and one more /test"] = { |
53 | | - report_name: "folder with spaces/ and again/ and one more /test", |
54 | | - time_diff: "1 second", |
55 | | - count: 2, |
56 | | - scheduler_runs: 1, |
57 | | - }; |
58 | | - updateContents("", entries); |
59 | | - const cardContainer = $("#cardContainer").html(); |
60 | | - expect(cardContainer).toContain('href="/result_listing/report"'); |
61 | | - expect(cardContainer).toContain('href="/folder/hello"'); |
62 | | - expect(cardContainer).toContain('href="/folder/folder with spaces"'); |
63 | | - }); |
| 30 | + test("updateContents", () => { |
| 31 | + const entries = {}; |
| 32 | + entries["report"] = { |
| 33 | + report_name: "report", |
| 34 | + time_diff: "1 hour", |
| 35 | + count: 1, |
| 36 | + scheduler_runs: 1, |
| 37 | + }; |
| 38 | + entries["hello/world"] = { |
| 39 | + report_name: "hello/world", |
| 40 | + time_diff: "1 second", |
| 41 | + count: 2, |
| 42 | + scheduler_runs: 1, |
| 43 | + }; |
| 44 | + entries["folder with spaces/ and again/ and one more /test"] = { |
| 45 | + report_name: "folder with spaces/ and again/ and one more /test", |
| 46 | + time_diff: "1 second", |
| 47 | + count: 2, |
| 48 | + scheduler_runs: 1, |
| 49 | + }; |
| 50 | + updateContents("", entries); |
| 51 | + const cardContainer = $("#cardContainer").html(); |
| 52 | + expect(cardContainer).toContain('href="/result_listing/report"'); |
| 53 | + expect(cardContainer).toContain('href="/folder/hello"'); |
| 54 | + expect(cardContainer).toContain('href="/folder/folder with spaces"'); |
| 55 | + }); |
64 | 56 |
|
65 | | - test("load_data", async () => { |
66 | | - let mockResult = {}; |
67 | | - mockResult["test/my fake folder/hello/report"] = { |
68 | | - report_name: "test/my fake folder/hello/report", |
69 | | - time_diff: "1 hour", |
70 | | - count: 1, |
71 | | - scheduler_runs: 1, |
72 | | - }; |
73 | | - fetch.mockResolvedValueOnce({ |
74 | | - json: () => Promise.resolve(mockResult), |
| 57 | + test("load_data", async () => { |
| 58 | + let mockResult = {}; |
| 59 | + mockResult["test/my fake folder/hello/report"] = { |
| 60 | + report_name: "test/my fake folder/hello/report", |
| 61 | + time_diff: "1 hour", |
| 62 | + count: 1, |
| 63 | + scheduler_runs: 1, |
| 64 | + }; |
| 65 | + fetch.mockResolvedValueOnce({ |
| 66 | + json: () => Promise.resolve(mockResult), |
| 67 | + }); |
| 68 | + await load_data(); |
| 69 | + expect(fetch).toHaveBeenCalledWith("/core/get_all_templates_with_results/folder/test/my fake folder/hello/"); |
| 70 | + expect($("#folderNavigationPanel").html()).toContain( |
| 71 | + '<a href="/folder/test/my fake folder">my fake folder </a>' |
| 72 | + ); |
| 73 | + expect($("#cardContainer").html()).toContain("report"); |
75 | 74 | }); |
76 | | - await load_data(); |
77 | | - expect(fetch).toHaveBeenCalledWith( |
78 | | - "/core/get_all_templates_with_results/folder/test/my fake folder/hello/" |
79 | | - ); |
80 | | - expect($("#folderNavigationPanel").html()).toContain( |
81 | | - '<a href="/folder/test/my fake folder">my fake folder </a>' |
82 | | - ); |
83 | | - expect($("#cardContainer").html()).toContain("report"); |
84 | | - }); |
85 | 75 | }); |
0 commit comments