Added ability to specify expected operation results event cleaner

This commit is contained in:
boryslevytskyi
2017-05-27 14:48:30 +03:00
parent 09a0ed1ca4
commit 74825020d6
3 changed files with 49 additions and 18 deletions

View File

@@ -7,11 +7,11 @@
"build": "webpack -p && rm -rf ./BitwiseCmdPages/* && cp ./src/index.html ./BitwiseCmdPages && cp ./src/*.js ./BitwiseCmdPages && cp ./src/bundle.js.map ./BitwiseCmdPages && cp -r ./src/css ./BitwiseCmdPages && cp -r ./src/img ./BitwiseCmdPages && cp -r ./src/css ./BitwiseCmdPages",
"stage": "npm run build && cp -r ./BitwiseCmdPages/* ../BitwiseCmdPages",
"stage:react": "npm run build && cp -r ./BitwiseCmdPages/* ../BitwiseCmdPages/react",
"serv": "webpack-dev-server --content-base ./src",
"serve": "webpack-dev-server --content-base ./src",
"e2e": "protractor ./tests/e2e.chrome.js --params.appUrl='http://localhost:8080/#clear'",
"e2e:stage": "protractor ./tests/e2e.chrome.js --params.appUrl='http://localhost:3000/#clear'",
"e2e:remote:old": "protractor ./tests/e2e.chrome.js --params.appUrl='http://bitwisecmd.com/old/#clear||-notrack'",
"e2e:remote": "protractor ./tests/e2e.chrome.js --params.appUrl='http://bitwisecmd.com//#clear||-notrack'",
"e2e:prod:old": "protractor ./tests/e2e.chrome.js --params.appUrl='http://bitwisecmd.com/old/#clear||-notrack'",
"e2e:prod": "protractor ./tests/e2e.chrome.js --params.appUrl='http://bitwisecmd.com//#clear||-notrack'",
"test": "karma start"
},
"repository": {

View File

@@ -79,7 +79,7 @@ ExpressionResultObject.prototype.shouldBe = function(expectedResult) {
var expected, actual;
for(var i=0;i<expectedResult.length; i++) {
var actual = actualResult[i],
expected = expectedResult[i];
expected = convertToExpected(expectedResult[i]);
expect(actual).toEqual(jasmine.objectContaining(expected));
}
@@ -87,6 +87,33 @@ ExpressionResultObject.prototype.shouldBe = function(expectedResult) {
};
function convertToExpected(arg) {
if(arg.length) {
return convertExpectedFromArray(arg);
}
return arg;
}
function convertExpectedFromArray(arg) {
var start = 0;
if(arg.length == 4) {
start = 1
}
var obj = {
sign: arg.length == 4 ? arg[0] : '',
label: arg[start++],
bin: arg[start++],
other: arg[start++]
}
console.log('convert: ' + JSON.stringify(arg) + " to " + JSON.stringify(obj));
return obj;
}
module.exports = {
BitwiseCmdPage : BitwiseCmdPage,
ExpressionResultObject: ExpressionResultObject

View File

@@ -61,7 +61,7 @@ describe('when application starts', function() {
return assertOperation('-1>>>1',
[{ label: '-1', bin:'11111111111111111111111111111111', other: '-0x1'},
{ sign: '>>>1', label: '2147483647', bin:'01111111111111111111111111111111', other: '0x7fffffff'}])
{ sign: '>>>1', label: '2147483647', bin:'01111111111111111111111111111111', other: '0x7fffffff'}])
});
it('should do NOT operation', function() {
@@ -99,21 +99,23 @@ describe('when application starts', function() {
it('should do multiple operand expression', function() {
return assertOperation('1|2|4<<0x1',
[{ label: '1', bin:'00000001', other: '0x1'},
{ sign:'|', label: '2', bin:'00000010', other: '0x2'},
{ sign: '=', label: '3', bin:'00000011', other: '0x3'},
{ sign: '|', label: '4', bin:'00000100', other: '0x4'},
{ sign: '=', label: '7', bin:'00000111', other: '0x7'},
{ sign: '<<0x1', label: '0xe', bin:'00001110', other: '14'}
])
return assertOperation(
'1|2|4<<0x1',
[
[ '1', '00000001', '0x1'],
[ '|', '2', '00000010', '0x2'],
[ '=', '3', '00000011', '0x3'],
[ '|', '4', '00000100', '0x4'],
[ '=', '7', '00000111', '0x7'],
[ '<<0x1','0xe','00001110', '14' ],
]);
});
it('should do or for binary numbers', function() {
return assertOperation('0b10|0b11',
[{ label: "2", bin: "00000010", other: "0x2" },
{ sign: "|", label: "3", bin: "00000011", other: "0x3" },
{ sign: "=", label: "3", bin: "00000011", other: '0x3'}]
[[ "2", "00000010", "0x2"],
["|", "3", "00000011", "0x3"],
["=", "3", "00000011", "0x3"]]
);
})
@@ -126,7 +128,8 @@ describe('when application starts', function() {
});
it('should create hashlink', function() {
// TODO: temporary disabled due to false positive on prod
xit('should create hashlink', function() {
var expression = '1|0x2';
var expected = [{ label: '1', bin:'00000001', other: '0x1'},
{ sign: '|', label: '0x2', bin:'00000010', other: '2'},
@@ -137,7 +140,8 @@ describe('when application starts', function() {
}).then(function(el) {
return el.getAttribute('href');
}).then(function(hrefUrl) {
return driver.get(hrefUrl + "||-notrack"); // TODO: temp solution. Need to implement better tracking handling logic
console.log('haslink url: ' + hrefUrl);
return driver.get(hrefUrl); // TODO: temp solution. Need to implement better tracking handling logic
}).then(function() {
return driver.findElements(By.css('.result'));
}).then(function(list) {