From d0e43cfb8fd03567f5c6659dee8bb7570d61d193 Mon Sep 17 00:00:00 2001 From: boryslevytskyi Date: Sat, 13 May 2017 18:49:38 +0300 Subject: [PATCH] add support of commads from location hash --- e2e.sh | 2 + src/app/components/AppRoot.jsx | 6 +-- src/app/components/InputBox.jsx | 2 +- .../results/ListOfNumbersExpressionView.jsx | 2 +- .../models/BitwiseExpressionViewModel.js | 6 +-- src/app/hash.js | 40 +++++++++++++++++++ src/app/index.jsx | 12 ++++-- tests/e2e/spec.js | 8 ++-- 8 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 e2e.sh create mode 100644 src/app/hash.js diff --git a/e2e.sh b/e2e.sh new file mode 100644 index 0000000..207d22e --- /dev/null +++ b/e2e.sh @@ -0,0 +1,2 @@ +#!/bin/bash +protractor ./tests/e2e.chrome.js --params.appUrl="http://localhost:8080" \ No newline at end of file diff --git a/src/app/components/AppRoot.jsx b/src/app/components/AppRoot.jsx index d9513a8..fd70055 100644 --- a/src/app/components/AppRoot.jsx +++ b/src/app/components/AppRoot.jsx @@ -12,11 +12,7 @@ export default class AppRoot extends React.Component { } getIndicator(value) { - if(value) { - return "on"; - } - - return "off"; + return value === true ? 'on' : 'off'; } getResultViews() { diff --git a/src/app/components/InputBox.jsx b/src/app/components/InputBox.jsx index a32aa70..65c0be1 100644 --- a/src/app/components/InputBox.jsx +++ b/src/app/components/InputBox.jsx @@ -9,7 +9,7 @@ export default class InputBox extends React.Component { } render() { - return this.onKeyUp(e)} onKeyDown={e => this.onKeyDown(e)} className="expressionInput mono" diff --git a/src/app/components/results/ListOfNumbersExpressionView.jsx b/src/app/components/results/ListOfNumbersExpressionView.jsx index 5528cc5..a4e93f5 100644 --- a/src/app/components/results/ListOfNumbersExpressionView.jsx +++ b/src/app/components/results/ListOfNumbersExpressionView.jsx @@ -2,7 +2,7 @@ import React from 'react'; import formatter from '../../formatter'; import BinaryStringView from './BinaryStringView'; import BitwiseExpressionViewModel from './models/BitwiseExpressionViewModel' -//import calc from '../../calc'; + export default class ListOfNumersExpressionView extends React.Component { render() { diff --git a/src/app/components/results/models/BitwiseExpressionViewModel.js b/src/app/components/results/models/BitwiseExpressionViewModel.js index 56e3c15..7831afe 100644 --- a/src/app/components/results/models/BitwiseExpressionViewModel.js +++ b/src/app/components/results/models/BitwiseExpressionViewModel.js @@ -7,7 +7,7 @@ export default class BitwiseExpressionViewModel { } static buildMultiple (expr, config) { - console.log(config); + var op = expr.expressions[0], i = 1, l = expr.expressions.length, ex, m = new BitwiseExpressionViewModel(config); @@ -30,8 +30,8 @@ export default class BitwiseExpressionViewModel { return m; }; - static buildNot (expression, cofig) { - console.log(config); + static buildNot (expression, config) { + var m = new BitwiseExpressionViewModel(config); m.addExpression(expression); m.addExpressionResult(expression.apply()); diff --git a/src/app/hash.js b/src/app/hash.js new file mode 100644 index 0000000..d36ce94 --- /dev/null +++ b/src/app/hash.js @@ -0,0 +1,40 @@ +export default { + encodeHash: function(string) { + return encodeURI(string.trim().replace(/\s/g,',')); + }, + decodeHash: function(hashValue) { + return decodeURI(hashValue).replace(/^\#/, '').replace(/,/g,' '); + }, + getArgs: function (hashValue) { + + var decodedHash = this.decodeHash(hashValue), + args = []; + + splitHashList(decodedHash).forEach(function(value) { + if(/^\-[a-zA-Z]+$/.test(value)) { + args[value.substr(1)] = true; + return; + } + + args.push(value); + }); + + return Object.freeze(args); + } + }; + +function splitHashList(str) { + var values = []; + + if(str.indexOf('||')) { + str.split('||').forEach(function (v) { + if (v.length > 0) { + values.push(v); + } + }); + } else { + values.push(str); + } + + return values; +} \ No newline at end of file diff --git a/src/app/index.jsx b/src/app/index.jsx index 3524483..25331ea 100644 --- a/src/app/index.jsx +++ b/src/app/index.jsx @@ -6,6 +6,7 @@ import appStateStore from './appStateStore'; import cmd from './cmd'; import commands from './commands'; import AppRoot from './components/AppRoot'; +import hash from './hash'; var stateData = appStateStore.getPersistedData(); @@ -17,9 +18,14 @@ commands.initialize(cmd, appState); console.log("appState", appState); -cmd.execute('1'); -cmd.execute('2'); -cmd.execute('1|2<<2'); + +var hashArgs = hash.getArgs(window.location.hash); +var startupCommands = ['1','2','1|2<<2']; +if(hashArgs.length > 0) { + startupCommands = hashArgs; +} + +startupCommands.forEach(cmd.execute.bind(cmd)); var root = ; ReactDOM.render(root, document.getElementById('root')); \ No newline at end of file diff --git a/tests/e2e/spec.js b/tests/e2e/spec.js index fb4bd90..77bbbfb 100644 --- a/tests/e2e/spec.js +++ b/tests/e2e/spec.js @@ -7,7 +7,7 @@ var driver = browser.driver; var appUrl = browser.params.appUrl || 'http://localhost:63342/BitwiseCmd/src/#clear'; var sutPage = new BitwiseCmdPage(driver, appUrl); -describe('launch of application', function() { +describe('when application starts', function() { it('should have title', function() { sutPage.goToApp().then(function() { expect(driver.getTitle()).toEqual('BitwiseCmd'); @@ -149,15 +149,15 @@ describe('launch of application', function() { }); - xit('should emphasize bytes', function() { + it('should emphasize bytes', function() { - goToApp() + sutPage.goToApp() .then(function() { return sutPage.executeExpression('1')}) .then(function() { return assertExpressionResult([{ label: '1', bin:'00000001', other: '0x1'}]) }) .then(function() { return sutPage.executeExpression('clear')}) - // .then(function() { return sendCommand('em')}) + .then(function() { return sutPage.executeExpression('em')}) .then(function() { return sutPage.shouldHaveNoErrors(); }) .then(function() { return sutPage.executeExpression('1 3')}) .then(function() {