2015-04-13 23:15:15 +02:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2015-04-13 23:15:15 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
var should = require("should");
|
|
|
|
var express = require('express');
|
|
|
|
var sinon = require('sinon');
|
|
|
|
var when = require('when');
|
|
|
|
var fs = require("fs");
|
|
|
|
|
|
|
|
var app = express();
|
|
|
|
|
2018-08-20 17:17:24 +02:00
|
|
|
var NR_TEST_UTILS = require("nr-test-utils");
|
|
|
|
|
|
|
|
var theme = NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/theme");
|
2015-04-13 23:15:15 +02:00
|
|
|
|
2018-10-03 06:39:11 +02:00
|
|
|
describe("api/editor/theme", function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
sinon.stub(fs, "statSync", function () { return true; });
|
2015-04-13 23:15:15 +02:00
|
|
|
});
|
2018-10-03 06:39:11 +02:00
|
|
|
afterEach(function () {
|
|
|
|
theme.init({settings: {}});
|
2015-04-13 23:15:15 +02:00
|
|
|
fs.statSync.restore();
|
|
|
|
});
|
2018-10-03 06:39:11 +02:00
|
|
|
it("applies the default theme", function () {
|
2018-04-24 16:01:49 +02:00
|
|
|
var result = theme.init({});
|
2015-04-13 23:15:15 +02:00
|
|
|
should.not.exist(result);
|
2015-11-11 23:11:02 +01:00
|
|
|
|
2015-04-13 23:15:15 +02:00
|
|
|
var context = theme.context();
|
|
|
|
context.should.have.a.property("page");
|
2018-10-03 06:39:11 +02:00
|
|
|
context.page.should.have.a.property("title", "Node-RED");
|
|
|
|
context.page.should.have.a.property("favicon", "favicon.ico");
|
|
|
|
context.page.should.have.a.property("tabicon", "red/images/node-red-icon-black.svg");
|
2015-04-13 23:15:15 +02:00
|
|
|
context.should.have.a.property("header");
|
2018-10-03 06:39:11 +02:00
|
|
|
context.header.should.have.a.property("title", "Node-RED");
|
|
|
|
context.header.should.have.a.property("image", "red/images/node-red.png");
|
|
|
|
context.should.have.a.property("asset");
|
|
|
|
context.asset.should.have.a.property("red", "red/red.min.js");
|
|
|
|
context.asset.should.have.a.property("main", "red/main.min.js");
|
2015-11-11 23:11:02 +01:00
|
|
|
|
2015-04-13 23:15:15 +02:00
|
|
|
should.not.exist(theme.settings());
|
|
|
|
});
|
2015-11-11 23:11:02 +01:00
|
|
|
|
2018-10-03 06:39:11 +02:00
|
|
|
it("picks up custom theme", function () {
|
2018-04-24 16:01:49 +02:00
|
|
|
theme.init({
|
2015-04-13 23:15:15 +02:00
|
|
|
editorTheme: {
|
|
|
|
page: {
|
|
|
|
title: "Test Page Title",
|
2018-10-03 06:39:11 +02:00
|
|
|
favicon: "/absolute/path/to/theme/favicon",
|
|
|
|
tabicon: "/absolute/path/to/theme/tabicon",
|
2017-07-04 10:33:00 +02:00
|
|
|
css: "/absolute/path/to/custom/css/file.css",
|
2017-04-10 16:46:44 +02:00
|
|
|
scripts: "/absolute/path/to/script.js"
|
2015-04-13 23:15:15 +02:00
|
|
|
},
|
|
|
|
header: {
|
|
|
|
title: "Test Header Title",
|
2018-10-03 06:39:11 +02:00
|
|
|
url: "http://nodered.org",
|
2015-04-13 23:15:15 +02:00
|
|
|
image: "/absolute/path/to/header/image" // or null to remove image
|
|
|
|
},
|
2015-11-11 23:11:02 +01:00
|
|
|
|
2015-04-13 23:15:15 +02:00
|
|
|
deployButton: {
|
2018-10-03 06:39:11 +02:00
|
|
|
type: "simple",
|
|
|
|
label: "Save",
|
2015-04-13 23:15:15 +02:00
|
|
|
icon: "/absolute/path/to/deploy/button/image" // or null to remove image
|
|
|
|
},
|
2015-11-11 23:11:02 +01:00
|
|
|
|
2015-04-13 23:15:15 +02:00
|
|
|
menu: { // Hide unwanted menu items by id. see editor/js/main.js:loadEditor for complete list
|
|
|
|
"menu-item-import-library": false,
|
|
|
|
"menu-item-export-library": false,
|
|
|
|
"menu-item-keyboard-shortcuts": false,
|
|
|
|
"menu-item-help": {
|
|
|
|
label: "Alternative Help Link Text",
|
|
|
|
url: "http://example.com"
|
|
|
|
}
|
|
|
|
},
|
2015-11-11 23:11:02 +01:00
|
|
|
|
2015-04-13 23:15:15 +02:00
|
|
|
userMenu: false, // Hide the user-menu even if adminAuth is enabled
|
2015-11-11 23:11:02 +01:00
|
|
|
|
2015-04-13 23:15:15 +02:00
|
|
|
login: {
|
|
|
|
image: "/absolute/path/to/login/page/big/image" // a 256x256 image
|
2018-10-03 06:39:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
palette: {
|
|
|
|
editable: true,
|
|
|
|
catalogues: ['https://catalogue.nodered.org/catalogue.json'],
|
|
|
|
theme: [{ category: ".*", type: ".*", color: "#f0f" }]
|
|
|
|
},
|
|
|
|
|
|
|
|
projects: {
|
|
|
|
enabled: false
|
2015-11-11 23:11:02 +01:00
|
|
|
}
|
2015-04-13 23:15:15 +02:00
|
|
|
}
|
2018-04-24 16:01:49 +02:00
|
|
|
});
|
2015-11-11 23:11:02 +01:00
|
|
|
|
2016-01-08 14:36:49 +01:00
|
|
|
theme.app();
|
2017-07-04 10:33:00 +02:00
|
|
|
|
2015-04-13 23:15:15 +02:00
|
|
|
var context = theme.context();
|
|
|
|
context.should.have.a.property("page");
|
2018-10-03 06:39:11 +02:00
|
|
|
context.page.should.have.a.property("title", "Test Page Title");
|
|
|
|
context.page.should.have.a.property("favicon", "theme/favicon/favicon");
|
|
|
|
context.page.should.have.a.property("tabicon", "theme/tabicon/tabicon");
|
2015-04-13 23:15:15 +02:00
|
|
|
context.should.have.a.property("header");
|
2018-10-03 06:39:11 +02:00
|
|
|
context.header.should.have.a.property("title", "Test Header Title");
|
|
|
|
context.header.should.have.a.property("url", "http://nodered.org");
|
|
|
|
context.header.should.have.a.property("image", "theme/header/image");
|
2017-04-10 16:46:44 +02:00
|
|
|
context.page.should.have.a.property("css");
|
2017-07-04 10:33:00 +02:00
|
|
|
context.page.css.should.have.lengthOf(1);
|
|
|
|
context.page.css[0].should.eql('theme/css/file.css');
|
2017-04-10 16:46:44 +02:00
|
|
|
context.page.should.have.a.property("scripts");
|
2017-07-04 10:33:00 +02:00
|
|
|
context.page.scripts.should.have.lengthOf(1);
|
|
|
|
context.page.scripts[0].should.eql('theme/scripts/script.js');
|
2018-10-03 06:39:11 +02:00
|
|
|
context.should.have.a.property("login");
|
|
|
|
context.login.should.have.a.property("image", "theme/login/image");
|
2015-11-11 23:11:02 +01:00
|
|
|
|
2015-04-13 23:15:15 +02:00
|
|
|
var settings = theme.settings();
|
|
|
|
settings.should.have.a.property("deployButton");
|
2018-10-03 06:39:11 +02:00
|
|
|
settings.deployButton.should.have.a.property("type", "simple");
|
|
|
|
settings.deployButton.should.have.a.property("label", "Save");
|
|
|
|
settings.deployButton.should.have.a.property("icon", "theme/deploy/image");
|
2015-04-13 23:15:15 +02:00
|
|
|
settings.should.have.a.property("userMenu");
|
2018-10-03 06:39:11 +02:00
|
|
|
settings.userMenu.should.be.eql(false);
|
2015-04-13 23:15:15 +02:00
|
|
|
settings.should.have.a.property("menu");
|
2018-10-03 06:39:11 +02:00
|
|
|
settings.menu.should.have.a.property("menu-item-import-library", false);
|
|
|
|
settings.menu.should.have.a.property("menu-item-export-library", false);
|
|
|
|
settings.menu.should.have.a.property("menu-item-keyboard-shortcuts", false);
|
|
|
|
settings.menu.should.have.a.property("menu-item-help", { label: "Alternative Help Link Text", url: "http://example.com" });
|
|
|
|
settings.should.have.a.property("palette");
|
|
|
|
settings.palette.should.have.a.property("editable", true);
|
|
|
|
settings.palette.should.have.a.property("catalogues", ['https://catalogue.nodered.org/catalogue.json']);
|
|
|
|
settings.palette.should.have.a.property("theme", [{ category: ".*", type: ".*", color: "#f0f" }]);
|
|
|
|
settings.should.have.a.property("projects");
|
|
|
|
settings.projects.should.have.a.property("enabled", false);
|
2015-04-13 23:15:15 +02:00
|
|
|
});
|
|
|
|
|
2015-11-11 23:11:02 +01:00
|
|
|
});
|