Skip to content

Commit 98ed468

Browse files
committed
add compliments_file tests to e2e, fix module for interval timer still running
1 parent 9be5535 commit 98ed468

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

modules/default/compliments/compliments.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ Module.register("compliments", {
4949
if ((this.config.remoteFileRefreshInterval >= this.refreshMinimumDelay) || window.mmTestMode === "true") {
5050
setInterval(async () => {
5151
const response = await this.loadComplimentFile();
52-
this.compliments_new = JSON.parse(response);
52+
if (response) {
53+
this.compliments_new = JSON.parse(response);
54+
}
55+
else {
56+
Log.error(`${this.name} remoteFile refresh failed`);
57+
}
5358
},
5459
this.config.remoteFileRefreshInterval);
5560
} else {
@@ -204,10 +209,14 @@ Module.register("compliments", {
204209
// we need to force the server to not give us the cached result
205210
// create an extra property (ignored by the server handler) just so the url string is different
206211
// that will never be the same, using the ms value of date
207-
if (this.config.remoteFileRefreshInterval !== 0) this.urlSuffix = `?dummy=${Date.now()}`;
212+
if (isRemote && this.config.remoteFileRefreshInterval !== 0) this.urlSuffix = `?dummy=${Date.now()}`;
208213
//
209-
const response = await fetch(url + this.urlSuffix);
210-
return await response.text();
214+
try {
215+
const response = await fetch(url + this.urlSuffix);
216+
return await response.text();
217+
} catch (error) {
218+
Log.info(`${this.name} fetch failed error=`, error);
219+
}
211220
},
212221

213222
/**

tests/e2e/modules/compliments_spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,37 @@ describe("Compliments module", () => {
8989
});
9090
});
9191
});
92+
93+
describe("Feature remote compliments file", () => {
94+
describe("get list from remote file", () => {
95+
beforeAll(async () => {
96+
await helpers.startApplication("tests/configs/modules/compliments/compliments_file.js");
97+
await helpers.getDocument();
98+
});
99+
it("shows 'Remote compliment file works!' as only anytime list set", async () => {
100+
//await helpers.startApplication("tests/configs/modules/compliments/compliments_file.js", "01 Jan 2022 10:00:00 GMT");
101+
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
102+
});
103+
// afterAll(async () =>{
104+
// await helpers.stopApplication()
105+
// });
106+
});
107+
108+
describe("get list from remote file w update", () => {
109+
beforeAll(async () => {
110+
await helpers.startApplication("tests/configs/modules/compliments/compliments_file_change.js");
111+
await helpers.getDocument();
112+
});
113+
it("shows 'test in morning' as test time set to 10am", async () => {
114+
//await helpers.startApplication("tests/configs/modules/compliments/compliments_file_change.js", "01 Jan 2022 10:00:00 GMT");
115+
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
116+
await new Promise((r) => setTimeout(r, 10000));
117+
await expect(doTest(["test in morning"])).resolves.toBe(true);
118+
});
119+
// afterAll(async () =>{
120+
// await helpers.stopApplication()
121+
// });
122+
});
123+
});
124+
92125
});

tests/electron/modules/compliments_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe("Compliments module", () => {
8888
});
8989
});
9090
describe("get updated list from remote file", () => {
91-
it("shows 'test in morning' as test time set to 10am", async () => {
91+
it("shows 'test in morning'", async () => {
9292
await helpers.startApplication("tests/configs/modules/compliments/compliments_file_change.js", "01 Jan 2022 10:00:00 GMT");
9393
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
9494
await new Promise((r) => setTimeout(r, 10000));

tests/mocks/compliments_file.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"morning": ["test in morning"],
3-
"afternoon": ["test in afternoon"],
4-
"evening": ["test in evening"]
2+
"anytime": ["test in morning"]
53
}

0 commit comments

Comments
 (0)