Skip to content

Commit d41e2b1

Browse files
committed
fix #3267, CORRECTLY, add testcase, add testcase for #3279
1 parent 0f6efac commit d41e2b1

File tree

7 files changed

+324
-10
lines changed

7 files changed

+324
-10
lines changed

js/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function Server (config) {
7272
app.use(helmet(config.httpHeaders));
7373
app.use("/js", express.static(__dirname));
7474

75-
let directories = ["/config", "/css", "/fonts", "/modules", "/vendor", "/translations", "/tests/configs", "/tests/mocks"];
75+
let directories = ["/config", "/css", "/fonts", "/modules", "/vendor", "/translations", "/tests/configs", "/tests/mocks", "/tests"];
7676
for (const directory of directories) {
7777
app.use(directory, express.static(path.resolve(global.root_path + directory)));
7878
}

modules/default/calendar/calendar.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,11 @@ Module.register("calendar", {
689689
by_url_calevents.push(event);
690690
}
691691
}
692-
by_url_calevents.sort(function (a, b) {
693-
return a.startDate - b.startDate;
694-
});
695-
if (limitNumberOfEntries) {
692+
if (true, limitNumberOfEntries) {
693+
// sort entries before clipping
694+
by_url_calevents.sort(function (a, b) {
695+
return a.startDate - b.startDate;
696+
});
696697
Log.debug(`pushing ${by_url_calevents.length} events to total with room for ${remainingEntries}`);
697698
events = events.concat(by_url_calevents.slice(0, remainingEntries));
698699
Log.debug(`events for calendar=${events.length}`);
@@ -911,7 +912,11 @@ Module.register("calendar", {
911912
let p = this.getCalendarProperty(url, property, defaultValue);
912913
if (property === "symbol" || property === "recurringSymbol" || property === "fullDaySymbol") {
913914
const className = this.getCalendarProperty(url, "symbolClassName", this.config.defaultSymbolClassName);
914-
if (p instanceof Array) p.push(className);
915+
if (p instanceof Array) {
916+
let t = [];
917+
p.forEach((n) => { t.push(className + n); });
918+
p = t;
919+
}
915920
else p = className + p;
916921
}
917922
if (!(p instanceof Array)) p = [p];
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
let config = {
2+
address: "0.0.0.0",
3+
ipWhitelist: [],
4+
timeFormat: 12,
5+
foreignModulesDir: "tests",
6+
modules: [
7+
{
8+
module: "calendar",
9+
position: "bottom_bar",
10+
11+
config: {
12+
maximumEntries: 1,
13+
calendars: [
14+
{
15+
fetchInterval: 10000, //7 * 24 * 60 * 60 * 1000,
16+
symbol: ["calendar-check", "google"],
17+
url: "http://localhost:8080/tests/mocks/12_events.ics"
18+
}
19+
]
20+
}
21+
},
22+
{
23+
module: "testNotification",
24+
position: "bottom_bar",
25+
config: {
26+
debug: true,
27+
match: {
28+
matchtype: "count",
29+
notificationID: "CALENDAR_EVENTS"
30+
}
31+
}
32+
}
33+
]
34+
};
35+
36+
/*************** DO NOT EDIT THE LINE BELOW ***************/
37+
if (typeof module !== "undefined") {
38+
module.exports = config;
39+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
let config = {
3+
address: "0.0.0.0",
4+
ipWhitelist: [],
5+
timeFormat: 12,
6+
7+
modules: [
8+
{
9+
module: "calendar",
10+
position: "bottom_bar",
11+
config: {
12+
maximumEntries: 1,
13+
calendars: [
14+
{
15+
fetchInterval: 7 * 24 * 60 * 60 * 1000,
16+
symbol: ["calendar-check", "google"],
17+
url: "https://ics.calendarlabs.com/76/mm3137/US_Holidays.ics"
18+
}
19+
]
20+
}
21+
}
22+
]
23+
};
24+
25+
/*************** DO NOT EDIT THE LINE BELOW ***************/
26+
if (typeof module !== "undefined") {
27+
module.exports = config;
28+
}

tests/electron/modules/calendar_spec.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ describe("Calendar module", () => {
1212
await expect(elem.isVisible()).resolves.toBe(true);
1313
return true;
1414
};
15+
//doTestTableContent(".testNotification tr", "td.elementCount", "12", first)).resolves.toBe(true);
1516

16-
const doTestCount = async () => {
17+
const doTestCount = async (locator = ".calendar .event") => {
1718
expect(global.page).not.toBeNull();
18-
const loc = await global.page.locator(".calendar .event");
19+
const loc = await global.page.locator(locator);
1920
const elem = loc.first();
2021
await elem.waitFor();
2122
expect(elem).not.toBeNull();
@@ -32,8 +33,8 @@ describe("Calendar module", () => {
3233
// uses playwright nth locator syntax
3334
const doTestTableContent = async (table_row, table_column, content, row = first) => {
3435
const elem = await global.page.locator(table_row);
35-
const date = await global.page.locator(table_column).locator(`nth=${row}`);
36-
await expect(date.textContent()).resolves.toContain(content);
36+
const column = await elem.locator(table_column).locator(`nth=${row}`);
37+
await expect(column.textContent()).resolves.toContain(content);
3738
return true;
3839
};
3940

@@ -279,4 +280,22 @@ describe("Calendar module", () => {
279280
});
280281
});
281282

283+
describe("count and check symbols", () => {
284+
it("in array", async () => {
285+
await helpers.startApplication("tests/configs/modules/calendar/symboltest.js", "08 Oct 2024 12:30:00 GMT-07:00", ["js/electron.js"], "America/Chicago");
286+
// just
287+
await expect(doTestCount(".calendar .event .symbol .fa-fw")).resolves.toBe(2);
288+
await expect(doTestCount(".calendar .event .symbol .fa-calendar-check")).resolves.toBe(1);
289+
await expect(doTestCount(".calendar .event .symbol .fa-google")).resolves.toBe(1);
290+
291+
});
292+
});
293+
294+
describe("count events broadcast", () => {
295+
it("with maxentries set to 12", async () => {
296+
await helpers.startApplication("tests/configs/modules/calendar/countCalendarEvents.js", "01 Jan 2024 12:30:00 GMT-076:00", ["js/electron.js"], "America/Chicago");
297+
await new Promise((r) => setTimeout(r, 60000));
298+
await expect(doTestTableContent(".testNotification", ".elementCount", "12", first)).resolves.toBe(true);
299+
});
300+
});
282301
});

tests/mocks/12_events.ics

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
BEGIN:VCALENDAR
2+
VERSION:2.0
3+
PRODID:-//Calendar Labs//Calendar 1.0//EN
4+
CALSCALE:GREGORIAN
5+
METHOD:PUBLISH
6+
X-WR-CALNAME:US Holidays
7+
X-WR-TIMEZONE:Etc/GMT
8+
BEGIN:VEVENT
9+
SUMMARY:Start of Month 1
10+
DTSTART:20190101
11+
DTEND:20190101
12+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
13+
LOCATION:United States
14+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
15+
16+
DTSTAMP:20200223T150458Z
17+
STATUS:CONFIRMED
18+
TRANSP:TRANSPARENT
19+
SEQUENCE:0
20+
END:VEVENT
21+
BEGIN:VEVENT
22+
SUMMARY:Start of Month 2
23+
DTSTART:20190201
24+
DTEND:20190201
25+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
26+
LOCATION:United States
27+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
28+
29+
DTSTAMP:20200223T150458Z
30+
STATUS:CONFIRMED
31+
TRANSP:TRANSPARENT
32+
SEQUENCE:0
33+
END:VEVENT
34+
BEGIN:VEVENT
35+
SUMMARY:Start of Month 3
36+
DTSTART:20190301
37+
DTEND:20190301
38+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
39+
LOCATION:United States
40+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
41+
42+
DTSTAMP:20200223T150458Z
43+
STATUS:CONFIRMED
44+
TRANSP:TRANSPARENT
45+
SEQUENCE:0
46+
END:VEVENT
47+
BEGIN:VEVENT
48+
SUMMARY:Start of Month 4
49+
DTSTART:20190401
50+
DTEND:20190401
51+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
52+
LOCATION:United States
53+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
54+
55+
DTSTAMP:20200223T150458Z
56+
STATUS:CONFIRMED
57+
TRANSP:TRANSPARENT
58+
SEQUENCE:0
59+
END:VEVENT
60+
BEGIN:VEVENT
61+
SUMMARY:Start of Month 5
62+
DTSTART:20190501
63+
DTEND:20190501
64+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
65+
LOCATION:United States
66+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
67+
68+
DTSTAMP:20200223T150458Z
69+
STATUS:CONFIRMED
70+
TRANSP:TRANSPARENT
71+
SEQUENCE:0
72+
END:VEVENT
73+
BEGIN:VEVENT
74+
SUMMARY:Start of Month 6
75+
DTSTART:20190601
76+
DTEND:20190601
77+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
78+
LOCATION:United States
79+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
80+
81+
DTSTAMP:20200223T150458Z
82+
STATUS:CONFIRMED
83+
TRANSP:TRANSPARENT
84+
SEQUENCE:0
85+
END:VEVENT
86+
BEGIN:VEVENT
87+
SUMMARY:Start of Month 7
88+
DTSTART:20190701
89+
DTEND:20190701
90+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
91+
LOCATION:United States
92+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
93+
94+
DTSTAMP:20200223T150458Z
95+
STATUS:CONFIRMED
96+
TRANSP:TRANSPARENT
97+
SEQUENCE:0
98+
END:VEVENT
99+
BEGIN:VEVENT
100+
SUMMARY:Start of Month 8
101+
DTSTART:20190801
102+
DTEND:20190801
103+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
104+
LOCATION:United States
105+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
106+
107+
DTSTAMP:20200223T150458Z
108+
STATUS:CONFIRMED
109+
TRANSP:TRANSPARENT
110+
SEQUENCE:0
111+
END:VEVENT
112+
BEGIN:VEVENT
113+
SUMMARY:Start of Month 9
114+
DTSTART:20190901
115+
DTEND:20190901
116+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
117+
LOCATION:United States
118+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
119+
120+
DTSTAMP:20200223T150458Z
121+
STATUS:CONFIRMED
122+
TRANSP:TRANSPARENT
123+
SEQUENCE:0
124+
END:VEVENT
125+
BEGIN:VEVENT
126+
SUMMARY:Start of Month 10
127+
DTSTART:20191001
128+
DTEND:20191001
129+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
130+
LOCATION:United States
131+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
132+
133+
DTSTAMP:20200223T150458Z
134+
STATUS:CONFIRMED
135+
TRANSP:TRANSPARENT
136+
SEQUENCE:0
137+
END:VEVENT
138+
BEGIN:VEVENT
139+
SUMMARY:Start of Month 11
140+
DTSTART:20191101
141+
DTEND:20191101
142+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
143+
LOCATION:United States
144+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
145+
146+
DTSTAMP:20200223T150458Z
147+
STATUS:CONFIRMED
148+
TRANSP:TRANSPARENT
149+
SEQUENCE:0
150+
END:VEVENT
151+
BEGIN:VEVENT
152+
SUMMARY:Start of Month 12
153+
DTSTART:20191201
154+
DTEND:20191201
155+
RRULE:FREQ=YEARLY;WKST=SU;INTERVAL=1
156+
LOCATION:United States
157+
DESCRIPTION:Visit https://calendarlabs.com/holidays/us/new-years-day.php to know more about New Year's Day. \n\n Like us on Facebook: http://fb.com/calendarlabs to get updates
158+
159+
DTSTAMP:20200223T150458Z
160+
STATUS:CONFIRMED
161+
TRANSP:TRANSPARENT
162+
SEQUENCE:0
163+
END:VEVENT
164+
END:VCALENDAR
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Module.register("testNotification", {
2+
defaults: {
3+
debug: false,
4+
match: {
5+
notificationID: "",
6+
matchtype: "count"
7+
//or
8+
// type: 'contents' // look for item in field of content
9+
}
10+
},
11+
count: 0,
12+
table: null,
13+
notificationReceived (notification, payload) {
14+
if (notification === this.config.match.notificationID) {
15+
if (this.config.match.matchtype === "count") {
16+
this.count = payload.length;
17+
if (this.count) {
18+
this.table = document.createElement("table");
19+
this.addTableRow(this.table, null, `${this.count}:elementCount`);
20+
if (this.config.debug) {
21+
payload.forEach((e, i) => {
22+
this.addTableRow(this.table, i, e.title);
23+
});
24+
}
25+
}
26+
27+
this.updateDom();
28+
}
29+
}
30+
},
31+
maketd (row, info) {
32+
let td = document.createElement("td");
33+
row.appendChild(td);
34+
if (info !== null) {
35+
let colinfo = info.toString().split(":");
36+
if (colinfo.length === 2) td.className = colinfo[1];
37+
td.innerText = colinfo[0];
38+
}
39+
return td;
40+
},
41+
addTableRow (table, col1 = null, col2 = null, col3 = null) {
42+
let tableRow = document.createElement("tr");
43+
table.appendChild(tableRow);
44+
45+
let tablecol1 = this.maketd(tableRow, col1);
46+
let tablecol2 = this.maketd(tableRow, col2);
47+
let tablecol3 = this.maketd(tableRow, col3);
48+
49+
return tableRow;
50+
},
51+
getDom () {
52+
let wrapper = document.createElement("div");
53+
if (this.table) {
54+
wrapper.appendChild(this.table);
55+
}
56+
return wrapper;
57+
}
58+
59+
});

0 commit comments

Comments
 (0)