2 * Copyright 2014 IBM Corp.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 var request = require("supertest");
17 var express = require("express");
18 var redUI = require("../../red/ui");
21 describe("red/ui icon handler", function() {
22 it('returns the default icon when getting an unknown icon', function(done) {
26 .get("/icons/youwonthaveme.png")
27 .expect('Content-Type', /image\/png/)
29 .end(function(err, res){
37 it('returns an icon from disk', function(done) {
41 .get("/icons/arduino.png")
42 .expect('Content-Type', /image\/png/)
44 .end(function(err, res){
53 describe("icon cache handler", function() {
54 var fs = require('fs-extra');
55 var path = require('path');
56 var events = require("../../red/events");
58 var tempDir = path.join(__dirname,".tmp/");
59 var cachedFakePNG = tempDir + "cacheMe.png";
62 beforeEach(function(done) {
63 fs.remove(tempDir,function(err) {
64 fs.mkdirSync(tempDir);
65 fs.writeFileSync(cachedFakePNG, "Hello PNG\n");
69 afterEach(function(done) {
70 fs.exists(cachedFakePNG, function(exists) {
72 fs.unlinkSync(cachedFakePNG);
74 fs.remove(tempDir,done);
79 * This test case test that:
80 * 1) any directory can be added to the path lookup (such as /tmp) by
81 * calling the right event
82 * 2) that a file we know exists gets cached so that the lookup/verification
83 * of actual existence doesn't occur again when a subsequent request comes in
85 * The second point verifies that the cache works. If the cache wouldn't work
86 * the default PNG would be served
88 it('returns an icon using icon cache', function(done) {
91 events.emit("node-icon-dir", tempDir);
93 .get("/icons/cacheMe.png")
94 .expect('Content-Type', /image\/png/)
96 .end(function(err, res){
100 fs.unlink(cachedFakePNG, function(err) {
105 .get("/icons/cacheMe.png")
106 .expect('Content-Type', /text\/html/)
108 .end(function(err, res){
119 describe("red/ui settings handler", function() {
120 it('returns the provided settings', function(done) {
122 httpNodeRoot: "testHttpNodeRoot",
123 version: "testVersion",
129 .expect('Content-Type', /application\/json/)
130 .expect(200, "{\n \"httpNodeRoot\": \"testHttpNodeRoot\",\n \"version\": \"testVersion\"\n}")
131 .end(function(err, res){
141 describe("red/ui root handler", function() {
142 it('server up the main page', function(done) {
148 .expect('Content-Type', /text\/html/)
150 .end(function(err, res){
159 it('redirects to path ending with /', function(done) {
160 var rapp = express();
163 var app = express().use('/root', rapp);
167 .expect('Content-Type', /text\/plain/)
169 .end(function(err, res){