2021-10-04 22:48:21 +02:00
const helpers = require ( "../global-setup" ) ;
const serverBasicAuth = require ( "./basic-auth.js" ) ;
2022-09-20 23:43:06 +02:00
describe ( "Calendar module" , ( ) => {
2021-10-04 22:48:21 +02:00
/ * *
2022-09-20 23:43:06 +02:00
* @ param { string } done test done
2021-10-04 22:48:21 +02:00
* @ param { string } element css selector
* @ param { string } result expected number
* @ param { string } not reverse result
* /
2022-09-20 23:43:06 +02:00
const testElementLength = ( done , element , result , not ) => {
helpers . waitForAllElements ( element ) . then ( ( elem ) => {
done ( ) ;
2022-01-13 00:13:29 +01:00
expect ( elem ) . not . toBe ( null ) ;
if ( not === "not" ) {
expect ( elem . length ) . not . toBe ( result ) ;
} else {
expect ( elem . length ) . toBe ( result ) ;
}
2022-01-13 21:12:15 +01:00
} ) ;
2022-09-20 23:43:06 +02:00
} ;
2022-01-13 00:13:29 +01:00
2022-09-20 23:43:06 +02:00
const testTextContain = ( done , element , text ) => {
helpers . waitForElement ( element , "undefinedLoading" ) . then ( ( elem ) => {
done ( ) ;
2022-01-13 21:12:15 +01:00
expect ( elem ) . not . toBe ( null ) ;
expect ( elem . textContent ) . toContain ( text ) ;
} ) ;
} ;
2021-10-04 22:48:21 +02:00
2022-09-20 23:43:06 +02:00
afterAll ( async ( ) => {
2022-05-27 19:46:28 +02:00
await helpers . stopApplication ( ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
describe ( "Default configuration" , ( ) => {
beforeAll ( ( done ) => {
2021-10-04 22:48:21 +02:00
helpers . startApplication ( "tests/configs/modules/calendar/default.js" ) ;
2022-01-13 00:13:29 +01:00
helpers . getDocument ( done ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
it ( "should show the default maximumEntries of 10" , ( done ) => {
testElementLength ( done , ".calendar .event" , 10 ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
it ( "should show the default calendar symbol in each event" , ( done ) => {
testElementLength ( done , ".calendar .event .fa-calendar-alt" , 0 , "not" ) ;
2021-10-04 22:48:21 +02:00
} ) ;
} ) ;
2022-09-20 23:43:06 +02:00
describe ( "Custom configuration" , ( ) => {
beforeAll ( ( done ) => {
2021-10-04 22:48:21 +02:00
helpers . startApplication ( "tests/configs/modules/calendar/custom.js" ) ;
2022-01-13 00:13:29 +01:00
helpers . getDocument ( done ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
it ( "should show the custom maximumEntries of 4" , ( done ) => {
testElementLength ( done , ".calendar .event" , 4 ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
it ( "should show the custom calendar symbol in each event" , ( done ) => {
testElementLength ( done , ".calendar .event .fa-birthday-cake" , 4 ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
it ( "should show two custom icons for repeating events" , ( done ) => {
testElementLength ( done , ".calendar .event .fa-undo" , 2 ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
it ( "should show two custom icons for day events" , ( done ) => {
testElementLength ( done , ".calendar .event .fa-calendar-day" , 2 ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2021-12-26 16:10:04 +01:00
} ) ;
2021-12-26 14:30:38 +01:00
2022-09-20 23:43:06 +02:00
// todo: recurring event tests not working since upgrade to node-ical v0.15.1 (versions v0.14.1 and before are o.k.)
// [19.09.2022 21:08.00.279] [ERROR] Calendar Error. Could not fetch calendar: http://localhost:8080/tests/configs/data/calendar_test_recurring.ics TypeError: curr.start.getTime is not a function
// at Object.originalEnd (/opt/magic_mirror/node_modules/node-ical/ical.js:423:44)
// at Object.END (/opt/magic_mirror/node_modules/node-ical/ical.js:602:26)
// at Object.handleObject (/opt/magic_mirror/node_modules/node-ical/ical.js:634:39)
// at Object.parseLines (/opt/magic_mirror/node_modules/node-ical/ical.js:686:18)
// at Object.parseICS (/opt/magic_mirror/node_modules/node-ical/ical.js:722:18)
// at sync.parseICS (/opt/magic_mirror/node_modules/node-ical/node-ical.js:198:15)
// at autodetect.parseICS (/opt/magic_mirror/node_modules/node-ical/node-ical.js:229:17)
// at /opt/magic_mirror/modules/default/calendar/calendarfetcher.js:72:18
// at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
// describe("Recurring event", () => {
// beforeAll((done) => {
// helpers.startApplication("tests/configs/modules/calendar/recurring.js");
// helpers.getDocument(done);
// });
// it("should show the recurring birthday event 6 times", (done) => {
// testElementLength(done, ".calendar .event", 6);
// });
// });
// process.setMaxListeners(0);
// for (let i = -12; i < 12; i++) {
// describe("Recurring event per timezone", () => {
// beforeAll((done) => {
// Date.prototype.getTimezoneOffset = () => {
// return i * 60;
// };
// helpers.startApplication("tests/configs/modules/calendar/recurring.js");
// helpers.getDocument(done);
// });
// it('should contain text "Mar 25th" in timezone UTC ' + -i, (done) => {
// testTextContain(done, ".calendar", "Mar 25th");
// });
// });
// }
describe ( "Changed port" , ( ) => {
beforeAll ( ( done ) => {
2021-10-04 22:48:21 +02:00
helpers . startApplication ( "tests/configs/modules/calendar/changed-port.js" ) ;
serverBasicAuth . listen ( 8010 ) ;
2022-01-13 00:13:29 +01:00
helpers . getDocument ( done ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
afterAll ( ( done ) => {
2021-10-04 22:48:21 +02:00
serverBasicAuth . close ( done ( ) ) ;
} ) ;
2022-09-20 23:43:06 +02:00
it ( "should return TestEvents" , ( done ) => {
testElementLength ( done , ".calendar .event" , 0 , "not" ) ;
2021-10-04 22:48:21 +02:00
} ) ;
} ) ;
2022-09-20 23:43:06 +02:00
describe ( "Basic auth" , ( ) => {
beforeAll ( ( done ) => {
2021-10-04 22:48:21 +02:00
helpers . startApplication ( "tests/configs/modules/calendar/basic-auth.js" ) ;
2022-01-13 00:13:29 +01:00
helpers . getDocument ( done ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
it ( "should return TestEvents" , ( done ) => {
testElementLength ( done , ".calendar .event" , 0 , "not" ) ;
2021-10-04 22:48:21 +02:00
} ) ;
} ) ;
2022-09-20 23:43:06 +02:00
describe ( "Basic auth by default" , ( ) => {
beforeAll ( ( done ) => {
2021-10-04 22:48:21 +02:00
helpers . startApplication ( "tests/configs/modules/calendar/auth-default.js" ) ;
2022-01-13 00:13:29 +01:00
helpers . getDocument ( done ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
it ( "should return TestEvents" , ( done ) => {
testElementLength ( done , ".calendar .event" , 0 , "not" ) ;
2021-10-04 22:48:21 +02:00
} ) ;
} ) ;
2022-09-20 23:43:06 +02:00
describe ( "Basic auth backward compatibility configuration: DEPRECATED" , ( ) => {
beforeAll ( ( done ) => {
2021-10-04 22:48:21 +02:00
helpers . startApplication ( "tests/configs/modules/calendar/old-basic-auth.js" ) ;
2022-01-13 00:13:29 +01:00
helpers . getDocument ( done ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
it ( "should return TestEvents" , ( done ) => {
testElementLength ( done , ".calendar .event" , 0 , "not" ) ;
2021-10-04 22:48:21 +02:00
} ) ;
} ) ;
2022-09-20 23:43:06 +02:00
describe ( "Fail Basic auth" , ( ) => {
beforeAll ( ( done ) => {
2021-10-04 22:48:21 +02:00
helpers . startApplication ( "tests/configs/modules/calendar/fail-basic-auth.js" ) ;
serverBasicAuth . listen ( 8020 ) ;
2022-01-13 21:12:15 +01:00
helpers . getDocument ( done ) ;
2021-10-04 22:48:21 +02:00
} ) ;
2022-09-20 23:43:06 +02:00
afterAll ( ( done ) => {
2021-10-04 22:48:21 +02:00
serverBasicAuth . close ( done ( ) ) ;
} ) ;
2022-09-20 23:43:06 +02:00
it ( "should show Unauthorized error" , ( done ) => {
testTextContain ( done , ".calendar" , "Error in the calendar module. Authorization failed" ) ;
2021-10-04 22:48:21 +02:00
} ) ;
} ) ;
} ) ;