Skip to content

Commit

Permalink
Fixed broken turtle integration and added user config test.
Browse files Browse the repository at this point in the history
Added coverage banner to the README.md file.
  • Loading branch information
MarkusBordihn committed May 13, 2018
1 parent 5b6c147 commit 1f72b27
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 26 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -3,7 +3,8 @@ src="static_files/resources/external/chrome_webstore.png" align="right"
alt="Available in the Chrome Web Store">](https://chrome.google.com/webstore/detail/coding-with-chrome/becloognjehhioodmnimnehjcibkloed)
==================

[![Code Climate](https://codeclimate.com/github/google/coding-with-chrome/badges/gpa.svg)](https://codeclimate.com/github/google/coding-with-chrome)
[![Maintainability](https://api.codeclimate.com/v1/badges/c523df13ccc1f326dc65/maintainability)](https://codeclimate.com/github/google/coding-with-chrome/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/c523df13ccc1f326dc65/test_coverage)](https://codeclimate.com/github/google/coding-with-chrome/test_coverage)
[![Build Status](https://travis-ci.org/google/coding-with-chrome.svg?branch=master)](https://travis-ci.org/google/coding-with-chrome)
<img src="/static_files/images/cwc_logo.png" align="right" alt="Coding with Chrome">

Expand Down
11 changes: 2 additions & 9 deletions src/config/user_config.js
Expand Up @@ -60,21 +60,14 @@ cwc.userConfigName = {


/**
* @param {!cwc.utils.Helper} helper
* @constructor
* @struct
* @final
*/
cwc.UserConfig = function(helper) {
cwc.UserConfig = function() {
/** @type {string} */
this.name = 'User Config';

/** @type {!cwc.utils.Helper} */
this.helper = helper;

/** @private {!cwc.utils.Storage} */
this.storage_ = this.helper.getInstance('storage');

/** @private {Object} */
this.cache_ = new Map();

Expand Down Expand Up @@ -116,7 +109,7 @@ cwc.UserConfig.prototype.getAll = function(type) {
let result = new Map();
for (let [key, value] of this.cache_) {
if (key && String(key).startsWith(type)) {
result.set(key, value);
result.set(key.replace(type + '_', ''), value);
}
}
return result;
Expand Down
6 changes: 4 additions & 2 deletions src/frameworks/internal/runner/runner.js
Expand Up @@ -40,7 +40,7 @@ cwc.framework.Runner = function() {
this.appWindow = null;

/** @type {Object} */
this.commands = {};
this.commands = {'Runner Framework': null};

/** @private {?Function} */
this.callback_ = null;
Expand Down Expand Up @@ -155,7 +155,9 @@ cwc.framework.Runner.prototype.setScope = function(scope) {
if (this.callback_ || this.monitor_) {
throw new Error('Scope should be set before callback/monitor!');
}
if (scope && typeof scope === 'function') {
if (scope && typeof scope !== 'function' && typeof scope !== 'object') {
throw new Error('Invalid runner scope!', scope);
} else if (scope) {
this.scope_ = scope;
}
return this;
Expand Down
19 changes: 14 additions & 5 deletions src/frameworks/internal/turtle/turtle.js
Expand Up @@ -23,22 +23,22 @@ goog.require('cwc.framework.Runner');


/**
* @param {string=} opt_target
* @param {Object=} opt_options
* @param {string=} target
* @param {Object=} options
* @constructor
* @struct
* @final
* @export
*/
cwc.framework.Turtle = function(opt_target, opt_options) {
cwc.framework.Turtle = function(target, options) {
/** @type {string} */
this.name = 'Turtle Framework';

/** @type {string|undefined} */
this.target = opt_target;
this.target = target;

/** @type {Object} */
this.options = opt_options || {
this.options = options || {
'panel': false,
};

Expand All @@ -55,6 +55,15 @@ cwc.framework.Turtle = function(opt_target, opt_options) {
/** @type {Object} */
this.turtleTarget = this.turtle(this.target, this.options);

if (!this.turtle || !this.turtleTarget) {
console.error('Turtle library is not ready!');
} else {
this.addCommands();
}
};


cwc.framework.Turtle.prototype.addCommands = function() {
// Mapping available commands.
this.runner.addCommand('__reset__', this.reset);
this.runner.addCommand('fd', this.handleFd_);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/builder.js
Expand Up @@ -228,7 +228,7 @@ cwc.ui.Builder.prototype.decorate = function(node = null, callback = null) {
this.raiseError('Runtime Error\n' + browserEvent.message, true);
}, false, this);

// Prepare and load Storage
// Prepare and UserConfig
this.loadUserConfig_();
};

Expand Down
20 changes: 13 additions & 7 deletions src/ui/select_screen/select_screen.js
Expand Up @@ -50,6 +50,9 @@ cwc.ui.SelectScreen = function(helper) {
/** @type {Element} */
this.nodeContent = null;

/** @type {Object} */
this.modules = {};

/** @private {!goog.events.EventTarget} */
this.eventHandler_ = new goog.events.EventTarget();

Expand Down Expand Up @@ -88,8 +91,16 @@ cwc.ui.SelectScreen.prototype.decorate = function(node) {
goog.soy.renderElement(this.node, cwc.soy.SelectScreen.template, {
'prefix': this.prefix,
});

this.nodeContent = goog.dom.getElement(this.prefix + 'content');

let userConfigInstance = this.helper.getInstance('userConfig');
if (userConfigInstance) {
let moduleConfig = userConfigInstance.getAll(cwc.userConfigType.MODULE);
this.modules = {};
moduleConfig.forEach((value, key) => {
this.modules[key] = value;
});
}
};


Expand Down Expand Up @@ -246,16 +257,11 @@ cwc.ui.SelectScreen.prototype.addFileHandler_ = function() {
* @param {!Function} template
*/
cwc.ui.SelectScreen.prototype.showTemplate_ = function(template) {
let modules = {};
let userConfigInstance = this.helper.getInstance('userConfig');
if (userConfigInstance) {
modules = userConfigInstance.getAll(cwc.userConfigType.MODULE);
}
if (this.nodeContent && template) {
goog.soy.renderElement(this.nodeContent, template, {
debug: this.helper.debugEnabled(),
experimental: this.helper.experimentalEnabled(),
modules: modules,
modules: this.modules,
online: this.helper.checkFeature('online'),
prefix: this.prefix,
version: this.helper.getAppVersion(),
Expand Down
2 changes: 2 additions & 0 deletions test/core_tests.conf
Expand Up @@ -46,6 +46,7 @@ module.exports = function(config) {
{pattern: 'genfiles/core/js/locales/*.js', included: false},
{pattern: 'genfiles/third_party/external/blockly/media/**/*', included: false},
{pattern: 'genfiles/third_party/frameworks/external/**/*', included: false},
{pattern: 'static_files/images/**/*', included: false},
{pattern: 'static_files/resources/**/*', included: false},

{pattern: 'test/core_tests/**/*_test.js'},
Expand All @@ -55,6 +56,7 @@ module.exports = function(config) {
"/external/blockly/media/": "/base/genfiles/third_party/external/blockly/media/",
"/frameworks/external/": "/base/genfiles/third_party/frameworks/external/",
"/frameworks/internal/": "/base/genfiles/core/frameworks/internal/",
"/images/": "/base/static_files/images/",
"/js/locales/": "/base/genfiles/core/js/locales/",
"/resources/": "/base/static_files/resources/",
};
Expand Down
74 changes: 74 additions & 0 deletions test/unit_tests/config/user_config_test.js
@@ -0,0 +1,74 @@
/**
* @fileoverview User config tests.
*
* @license Copyright 2015 The Coding with Chrome Authors.
*
* 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.
*
* @author mbordihn@google.com (Markus Bordihn)
*/
goog.require('cwc.UserConfig');


describe('UserConfig', function() {
it('constructor', function() {
expect(typeof new cwc.UserConfig()).toEqual('object');
});

it('prepare', function(done) {
let userConfig = new cwc.UserConfig();
userConfig.prepare().then(() => {
expect(true).toEqual(true);
done();
}, (error) => {
expect(error).toEqual(null);
done();
});
});

it('set / get', function(done) {
let userConfig = new cwc.UserConfig();
userConfig.prepare().then(() => {
userConfig.set('a', 'b', 'c');
expect(userConfig.get('a', 'b')).toEqual('c');
expect(userConfig.get('a', 'c')).toEqual(undefined);
done();
}, (error) => {
expect(error).toEqual(null);
done();
});
expect(typeof new cwc.UserConfig()).toEqual('object');
});

it('getAll', function(done) {
let userConfig = new cwc.UserConfig();
userConfig.prepare().then(() => {
userConfig.set('a', '1', 'a1');
userConfig.set('a', '2', 'a2');
userConfig.set('a', '3', 'a3');
userConfig.set('b', '1', 'b1');
userConfig.set('b', '2', 'b2');
userConfig.set('b', '3', 'b3');
let result = userConfig.getAll('a');
expect(result.get('1')).toEqual('a1');
expect(result.get('2')).toEqual('a2');
expect(result.get('3')).toEqual('a3');
expect(result.get('4')).toEqual(undefined);
done();
}, (error) => {
expect(error).toEqual(null);
done();
});
expect(typeof new cwc.UserConfig()).toEqual('object');
});
});
1 change: 0 additions & 1 deletion test/unit_tests/utils/stack_queue_test.js
Expand Up @@ -27,7 +27,6 @@ describe('StackType', function() {
expect(typeof cwc.utils.StackType).toEqual('object');
});


it('CMD', function() {
expect(cwc.utils.StackType.CMD).toEqual('cmd');
});
Expand Down

0 comments on commit 1f72b27

Please sign in to comment.