1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00
node-red/test/red/api/editor/theme_spec.js

112 lines
4.1 KiB
JavaScript
Raw Permalink Normal View History

2015-04-13 23:15:15 +02: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();
var theme = require("../../../../red/api/editor/theme");
2015-04-13 23:15:15 +02:00
describe("api/editor/theme", function() {
2015-04-13 23:15:15 +02:00
beforeEach(function() {
sinon.stub(fs,"statSync",function() { return true; });
});
afterEach(function() {
theme.init({settings:{}});
2015-04-13 23:15:15 +02:00
fs.statSync.restore();
});
it("applies the default theme", function() {
var result = theme.init({settings:{},version:function() { return '123.456'}});
2015-04-13 23:15:15 +02:00
should.not.exist(result);
2015-04-13 23:15:15 +02:00
var context = theme.context();
context.should.have.a.property("page");
context.page.should.have.a.property("title","Node-RED");
context.page.should.have.a.property("favicon","favicon.ico");
context.should.have.a.property("header");
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("version","123.456");
2015-04-13 23:15:15 +02:00
should.not.exist(theme.settings());
});
2015-04-13 23:15:15 +02:00
it("picks up custom theme", function() {
theme.init({settings:{
2015-04-13 23:15:15 +02:00
editorTheme: {
page: {
title: "Test Page Title",
favicon: "/absolute/path/to/theme/icon",
css: "/absolute/path/to/custom/css/file.css",
scripts: "/absolute/path/to/script.js"
2015-04-13 23:15:15 +02:00
},
header: {
title: "Test Header Title",
image: "/absolute/path/to/header/image" // or null to remove image
},
2015-04-13 23:15:15 +02:00
deployButton: {
type:"simple",
label:"Save",
icon: "/absolute/path/to/deploy/button/image" // or null to remove image
},
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-04-13 23:15:15 +02:00
userMenu: false, // Hide the user-menu even if adminAuth is enabled
2015-04-13 23:15:15 +02:00
login: {
image: "/absolute/path/to/login/page/big/image" // a 256x256 image
}
2015-04-13 23:15:15 +02:00
}
}});
theme.app();
2015-04-13 23:15:15 +02:00
var context = theme.context();
context.should.have.a.property("page");
context.page.should.have.a.property("title","Test Page Title");
context.should.have.a.property("header");
context.header.should.have.a.property("title","Test Header Title");
context.page.should.have.a.property("css");
context.page.css.should.have.lengthOf(1);
context.page.css[0].should.eql('theme/css/file.css');
context.page.should.have.a.property("scripts");
context.page.scripts.should.have.lengthOf(1);
context.page.scripts[0].should.eql('theme/scripts/script.js');
2015-04-13 23:15:15 +02:00
var settings = theme.settings();
settings.should.have.a.property("deployButton");
settings.should.have.a.property("userMenu");
settings.should.have.a.property("menu");
2015-04-13 23:15:15 +02:00
});
});