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

Merge pull request #1900 from kazuhitoyokoi/master-addtestcases4settings.js

Add test cases for red/api/editor/settings.js
This commit is contained in:
Nick O'Leary 2018-09-28 13:17:32 +01:00 committed by GitHub
commit d4d95a43b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ var request = require('supertest');
var express = require('express'); var express = require('express');
var sinon = require('sinon'); var sinon = require('sinon');
var when = require('when'); var when = require('when');
var bodyParser = require('body-parser');
var app = express(); var app = express();
var info = require("../../../../red/api/editor/settings"); var info = require("../../../../red/api/editor/settings");
@ -29,6 +30,7 @@ describe("api/editor/settings", function() {
before(function() { before(function() {
sinon.stub(theme,"settings",function() { return { test: 456 };}); sinon.stub(theme,"settings",function() { return { test: 456 };});
app = express(); app = express();
app.use(bodyParser.json());
app.get("/settings",info.runtimeSettings); app.get("/settings",info.runtimeSettings);
app.get("/settingsWithUser",function(req,res,next) { app.get("/settingsWithUser",function(req,res,next) {
req.user = { req.user = {
@ -40,12 +42,13 @@ describe("api/editor/settings", function() {
} }
next(); next();
},info.runtimeSettings); },info.runtimeSettings);
app.get("/settings/user", info.userSettings);
app.post("/settings/user", info.updateUserSettings);
}); });
after(function() { after(function() {
theme.settings.restore(); theme.settings.restore();
}); });
it('returns the filtered settings', function(done) { it('returns the filtered settings', function(done) {
info.init({ info.init({
settings: { settings: {
@ -120,6 +123,83 @@ describe("api/editor/settings", function() {
done(); done();
}); });
}); });
it('returns user settings', function (done) {
info.init({
settings: {
getUserSettings: function () {
return {
"editor": {
"view": {
"view-grid-size": "20",
"view-node-status": true,
"view-show-tips": true,
"view-snap-grid": true,
"view-show-grid": true
}
}
};
}
}
});
request(app)
.get("/settings/user")
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
res.body.should.have.property("editor");
res.body.editor.should.have.property("view");
res.body.editor.view.should.have.property("view-grid-size", "20");
res.body.editor.view.should.have.property("view-node-status", true);
res.body.editor.view.should.have.property("view-show-tips", true);
res.body.editor.view.should.have.property("view-snap-grid", true);
res.body.editor.view.should.have.property("view-show-grid", true);
done();
});
});
it('sets user settings', function (done) {
info.init({
settings: {
getUserSettings: function () {
return {};
},
setUserSettings: function (username, currentSettings) {
currentSettings.should.have.property("editor");
currentSettings.editor.should.have.property("view");
currentSettings.editor.view.should.have.property("view-grid-size", "21");
currentSettings.editor.view.should.have.property("view-node-status", false);
currentSettings.editor.view.should.have.property("view-show-tips", false);
currentSettings.editor.view.should.have.property("view-snap-grid", false);
currentSettings.editor.view.should.have.property("view-show-grid", false);
return when.resolve();
}
},
log: {
audit: function () {}
}
});
request(app)
.post("/settings/user")
.send({
"editor": {
"view": {
"view-grid-size": "21",
"view-node-status": false,
"view-show-tips": false,
"view-snap-grid": false,
"view-show-grid": false
}
}
})
.expect(204)
.end(function (err, res) {
res.should.have.property("status");
res.status.should.equal(204);
res.should.have.property("text", "");
done();
});
});
it('includes project settings if projects available', function(done) { it('includes project settings if projects available', function(done) {
info.init({ info.init({
settings: { settings: {
@ -277,7 +357,7 @@ describe("api/editor/settings", function() {
res.body.editorTheme.should.have.property("palette",{editable:false}); res.body.editorTheme.should.have.property("palette",{editable:false});
done(); done();
}); });
}) });
}); });
}); });