Skip to content

Commit 5e337f8

Browse files
authored
fix #3267, CORRECTLY, add testcase, add testcase for #3279 (#3681)
fixes #3267 AGAIN, correctly, add testcase add testcase for #3679 , broadcast clipping incorrectly I added a test module (tests/testNotification) to catch the notification and check the count. (one way to configure) i put this module in the tests folder, and added /tests to the server paths. (can't have a module in a nested folder, like tests/modules/xxx) but I have a problem. i can run the test config (MM_CONFIG_FILE), and the two modules work correctly, but in the spec runner, the calendar module times out on the broadcast test.. there is only local ics file access, no outside hosts I forced my system date to 1/1/24 (same as runner) and again the manual testcase works fine I added two test config.js,(configs/calendar) one works great (symbols) , one fails (broadcast test) I added additional delay in the calendarspec runner to try to debug the module, but it still not long enough.. no messages of trouble when I get into the browser.. BUT, this may be because of the log being turned off... (just thought of this) I created a special ICS (in mocks) that has 12 events, 1 for each month.. (so I can check clipping and broadcast) the US holidays one is sensitive to the current date, and I couldn't get it to work on 1/1/2024.. also, in general, is there a mechanism to run test:just_one_runner? waiting thru the electron test to get to one testcase.. ugh..
1 parent 8fdd865 commit 5e337f8

File tree

8 files changed

+323
-10
lines changed

8 files changed

+323
-10
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ planned for 2025-04-01
2525

2626
### Fixed
2727

28-
- [calendar] Fix clipping events being broadcast (#3678)
28+
- [calendar] fix clipping events being broadcast (#3678)
2929
- [tests] Electron tests: Fixes for running under new github image ubuntu-24.04, replace xserver with labwc (#3676)
30+
- [calendar] fix arrayed symbols, #3267, again, add testcase, add testcase for #3678
3031

3132
## [2.30.0] - 2025-01-01
3233

js/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function App () {
177177
moduleFolder = defaultModuleFolder;
178178
} else {
179179
// running in Jest, allow defaultModules placed under moduleDir for testing
180-
if (env.modulesDir === "modules") {
180+
if (env.modulesDir === "modules" || env.modulesDir === "tests/mocks") {
181181
moduleFolder = defaultModuleFolder;
182182
}
183183
}

modules/default/calendar/calendar.js

+9-4
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-
});
695692
if (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];
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/mocks",
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+
}
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

+21-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ describe("Calendar module", () => {
1313
return true;
1414
};
1515

16-
const doTestCount = async () => {
16+
const doTestCount = async (locator = ".calendar .event") => {
1717
expect(global.page).not.toBeNull();
18-
const loc = await global.page.locator(".calendar .event");
18+
const loc = await global.page.locator(locator);
1919
const elem = loc.first();
2020
await elem.waitFor();
2121
expect(elem).not.toBeNull();
@@ -32,8 +32,8 @@ describe("Calendar module", () => {
3232
// uses playwright nth locator syntax
3333
const doTestTableContent = async (table_row, table_column, content, row = first) => {
3434
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);
35+
const column = await elem.locator(table_column).locator(`nth=${row}`);
36+
await expect(column.textContent()).resolves.toContain(content);
3737
return true;
3838
};
3939

@@ -279,4 +279,21 @@ describe("Calendar module", () => {
279279
});
280280
});
281281

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

tests/mocks/12_events.ics

+164
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
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)