mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-29 20:49:54 +00:00
Show invalid url error on UI, add test case
This commit is contained in:
parent
2ec275957f
commit
a269b5cd93
@ -66,6 +66,7 @@ Module.register("newsfeed", {
|
|||||||
|
|
||||||
this.newsItems = [];
|
this.newsItems = [];
|
||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
|
this.error = null;
|
||||||
this.activeItem = 0;
|
this.activeItem = 0;
|
||||||
this.scrollPosition = 0;
|
this.scrollPosition = 0;
|
||||||
|
|
||||||
@ -87,8 +88,10 @@ Module.register("newsfeed", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
|
this.error = null;
|
||||||
} else if (notification === "INCORRECT_URL") {
|
} else if (notification === "INCORRECT_URL") {
|
||||||
Log.error("Newsfeed Error. Incorrect url: " + payload.url);
|
this.error = "Newsfeed Error. Incorrect url: " + payload.url;
|
||||||
|
this.scheduleUpdateInterval();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -110,15 +113,20 @@ Module.register("newsfeed", {
|
|||||||
url: this.getActiveItemURL()
|
url: this.getActiveItemURL()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (this.error) {
|
||||||
|
return {
|
||||||
|
error: this.error
|
||||||
|
};
|
||||||
|
}
|
||||||
if (this.newsItems.length === 0) {
|
if (this.newsItems.length === 0) {
|
||||||
return {
|
return {
|
||||||
loaded: false
|
loaded: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.activeItem >= this.newsItems.length) {
|
if (this.activeItem >= this.newsItems.length) {
|
||||||
this.activeItem = 0;
|
this.activeItem = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const item = this.newsItems[this.activeItem];
|
const item = this.newsItems[this.activeItem];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
{{ sourceTitle }}{% if config.showPublishDate %}, {% else %}: {% endif %}
|
{{ sourceTitle }}{% if config.showPublishDate %}, {% else %}: {% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if config.showPublishDate %}
|
{% if config.showPublishDate %}
|
||||||
{{ publishDate }}:
|
{{ publishDate }}:
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -21,8 +21,12 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% elseif error %}
|
||||||
|
<div class="small dimmed">
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="small dimmed">
|
<div class="small dimmed">
|
||||||
{{ "LOADING" | translate | safe }}
|
{{ "LOADING" | translate | safe }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -38,7 +38,7 @@ module.exports = NodeHelper.create({
|
|||||||
try {
|
try {
|
||||||
new URL(url);
|
new URL(url);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.sendSocketNotification("INCORRECT_URL", { url: url });
|
this.sendSocketNotification("INCORRECT_URL", { url });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
|
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
|
||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
let config = {
|
||||||
var config = {
|
|
||||||
port: 8080,
|
port: 8080,
|
||||||
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],
|
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],
|
||||||
|
|
||||||
|
38
tests/configs/modules/newsfeed/incorrect_url.js
Normal file
38
tests/configs/modules/newsfeed/incorrect_url.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/* Magic Mirror Test config newsfeed module
|
||||||
|
*
|
||||||
|
* MIT Licensed.
|
||||||
|
*/
|
||||||
|
let config = {
|
||||||
|
port: 8080,
|
||||||
|
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],
|
||||||
|
|
||||||
|
language: "en",
|
||||||
|
timeFormat: 12,
|
||||||
|
units: "metric",
|
||||||
|
electronOptions: {
|
||||||
|
webPreferences: {
|
||||||
|
nodeIntegration: true,
|
||||||
|
enableRemoteModule: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
modules: [
|
||||||
|
{
|
||||||
|
module: "newsfeed",
|
||||||
|
position: "bottom_bar",
|
||||||
|
config: {
|
||||||
|
feeds: [
|
||||||
|
{
|
||||||
|
title: "Incorrect Url",
|
||||||
|
url: "this is not a valid url"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||||
|
if (typeof module !== "undefined") {
|
||||||
|
module.exports = config;
|
||||||
|
}
|
@ -8,7 +8,7 @@ const afterEach = global.afterEach;
|
|||||||
describe("Newsfeed module", function () {
|
describe("Newsfeed module", function () {
|
||||||
helpers.setupTimeout(this);
|
helpers.setupTimeout(this);
|
||||||
|
|
||||||
var app = null;
|
let app = null;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
return helpers
|
return helpers
|
||||||
@ -29,8 +29,18 @@ describe("Newsfeed module", function () {
|
|||||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/newsfeed/default.js";
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/newsfeed/default.js";
|
||||||
});
|
});
|
||||||
|
|
||||||
it("show title newsfeed", function () {
|
it("should show the newsfeed title", function () {
|
||||||
return app.client.waitUntilTextExists(".newsfeed .small", "Rodrigo Ramirez Blog", 10000).should.be.fulfilled;
|
return app.client.waitUntilTextExists(".newsfeed .small", "Rodrigo Ramirez Blog", 10000).should.be.fulfilled;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Invalid configuration", function () {
|
||||||
|
before(function () {
|
||||||
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/newsfeed/incorrect_url.js";
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should show invalid url warning", function () {
|
||||||
|
return app.client.waitUntilTextExists(".newsfeed .small", "Newsfeed Error. Incorrect url:", 10000).should.be.fulfilled;
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user