Skip to content

Commit

Permalink
Merge branch 'develop-toloka' into delayed_acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
AlNedorezov committed Jul 9, 2017
2 parents a89cb30 + f0a4548 commit 2fcf0b9
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 10 deletions.
14 changes: 9 additions & 5 deletions front/js/app/data_collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Created by Alexey Merzlikin on 08.04.2017.
*/

var outputJson = "";

function DataCollector() {
this.dataEntities = {};

Expand Down Expand Up @@ -36,7 +38,9 @@ DataCollector.prototype.getEntitiesParameters = function (id) {
DataCollector.prototype.deleteEntity = function (id) {
if (id in this.dataEntities) {
delete this.dataEntities[id];
this.activeEntity = null;
if(id === this.getActiveEntity().polygonId) {
this.activeEntity = null;
}
}
};

Expand Down Expand Up @@ -83,12 +87,12 @@ DataCollector.prototype.getJSON = function () {
dataEntities.push(new DataEntityToBeExported(this.dataEntities[i]));
}
}
let json = JSON.stringify(dataEntities);
outputJson = JSON.stringify(dataEntities);
if (window.thisTask !== undefined && window.thisTask !== null) {
window.thisTask.setSolutionOutputValue("result", json);
window.thisTask.setSolutionOutputValue("result", outputJson);
} else {
console.log(json); // To check output values on localhost
console.log(outputJson); // To check output values on localhost
}

return json;
return outputJson;
};
2 changes: 2 additions & 0 deletions front/js/app/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ function undoObjectsDeletion(polygon, parameters) {
// polygon with id=polygon.polygonId is now selected
dc.getActiveEntity().setParams(parameters);
setClassesAndParametersValues(dc.getActiveEntity());

onSave();
}

function redoObjectsDeletion(polygon) {
Expand Down
8 changes: 4 additions & 4 deletions front/js/app/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ function svgImgOnClick(event) {
return;
}

if (currentPolygon !== null && currentPolygon.shouldConsumeEvent.apply(currentPolygon, [event])) {
let point = getPoint(event);

if (currentPolygon !== null && !currentPolygon.shouldClose(point.x, point.y) &&
currentPolygon.shouldConsumeEvent.apply(currentPolygon, [event])) {
return;
}

let point = getPoint(event);

if (redoPoints.length > 0) {
redoPoints = [];
}
Expand Down Expand Up @@ -158,7 +159,6 @@ function onPolygonClick(polygon) {
polygon.setDragEnabled(true);



onPolygonSelected(selectedPolygon);

showPolygonSelectedMessage();
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"grunt": "^1.0.1",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-cssmin": "^2.1.0",
"grunt-contrib-uglify": "^2.3.0"
"grunt-contrib-uglify": "^2.3.0",
"wdio-dot-reporter": "0.0.8",
"wdio-mocha-framework": "^0.5.10"
}
}
46 changes: 46 additions & 0 deletions test/specs/BrightnessTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
let assert = require('assert');
let projectFolderName = "git";
describe('webdriver.io page', function () {
it("Should change image brightness from 100 to 90", function () {
browser.url('http://localhost:63342/' + projectFolderName + '/front/main_local.html');
browser.click("#btn_brightness_low");

let result = browser.execute("return defaultBrightness;");
console.log("Brightness: " + result.value);

assert.equal(result.value, 90);
});

it("Should change image brightness from 100 to 110", function () {
browser.url('http://localhost:63342/' + projectFolderName + '/front/main_local.html');
browser.click("#btn_brightness_high");

let result = browser.execute("return defaultBrightness;");
console.log("Brightness: " + result.value);

assert.equal(result.value, 110);
});

it("Should check that brightness cannot be less than 10", function () {
browser.url('http://localhost:63342/' + projectFolderName + '/front/main_local.html');
for (let i = 0; i < 11; i++) {
browser.click("#btn_brightness_low");
}

let result = browser.execute("return defaultBrightness;");
console.log("Brightness: " + result.value);

assert.equal(result.value, 10);
});

it("Should check that brightness cannot be more than 500", function () {
browser.url('http://localhost:63342/' + projectFolderName + '/front/main_local.html');
for (let i = 0; i < 41; i++) {
browser.click("#btn_brightness_high");
}

let result = browser.execute("return defaultBrightness;");
console.log("Brightness: " + result.value);
assert.equal(result.value, 500);
});
});
88 changes: 88 additions & 0 deletions test/specs/CompleteLabelingProcessTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
let assert = require('assert');
let projectFolderName = "git";
describe('webdriver.io page', function () {
it("Should label image", function () {
browser.url('http://localhost:63342/' + projectFolderName + '/front/main_local.html');
browser.windowHandleSize({width: 1920, height: 1080});

let error = 2;
let points = [[100, 100], [100, 200], [200, 100]];

//Click on canvas
browser.leftClick("#canvas-parent", points[0][0], points[0][1]);
browser.leftClick("#canvas-parent", points[1][0], points[1][1]);
browser.leftClick("#canvas-parent", points[2][0], points[2][1]);
browser.leftClick("#canvas-parent", points[0][0], points[0][1]);

//Select object class
let selectBox = $(".class-param");
selectBox.selectByValue("class 0");

//Set bool param to true
let checkBox = $(".bool-param");
checkBox.click();

//Save the result
browser.leftClick(".btn-save");

//Get outputJson
let result = browser.execute("return outputJson;");

let json = result.value.substring(0, result.value.length - 1);
json = json.substring(1, result.value.length);
let jsonResponse = JSON.parse(json);
let results = [];

for (let i = 0; i < jsonResponse.points.length; i++) {
for (let j = 0; j < 2; j++) {
let difference = Math.abs(jsonResponse.points[i][j] - points[i][j]);
results.push(difference <= error);
}
}

results.forEach(function (obj) {
assert.equal(obj, true);
});
});

it("Should label image without saving", function () {
browser.url('http://localhost:63342/' + projectFolderName + '/front/main_local.html');
browser.windowHandleSize({width: 1920, height: 1080});

let error = 2;
let points = [[100, 100], [100, 200], [200, 100]];

//Click on canvas
browser.leftClick("#canvas-parent", points[0][0], points[0][1]);
browser.leftClick("#canvas-parent", points[1][0], points[1][1]);
browser.leftClick("#canvas-parent", points[2][0], points[2][1]);
browser.leftClick("#canvas-parent", points[0][0], points[0][1]);

//Select object class
let selectBox = $(".class-param");
selectBox.selectByValue("class 0");

//Set bool param to true
let checkBox = $(".bool-param");
checkBox.click();

//Get outputJson
let result = browser.execute("return outputJson;");

let json = result.value.substring(0, result.value.length - 1);
json = json.substring(1, result.value.length);
let jsonResponse = JSON.parse(json);
let results = [];

for (let i = 0; i < jsonResponse.points.length; i++) {
for (let j = 0; j < 2; j++) {
let difference = Math.abs(jsonResponse.points[i][j] - points[i][j]);
results.push(difference <= error);
}
}

results.forEach(function (obj) {
assert.equal(obj, true);
});
});
});
174 changes: 174 additions & 0 deletions test/specs/switchingBetweenLanguages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/**
* Created by alnedorezov on 7/9/17.
*/
let assert = require('assert');
let projectFolderName = "git";
describe("webdriver.io page", function () {
it("should switch between languages (case 12)", function () {
browser.url('http://localhost:63342/' + projectFolderName + '/front/main_local.html');
browser.windowHandleSize({width: 1920, height: 1080});

let error = 2;
let points = [[100, 100], [100, 200], [200, 100]];
let activeLanguageName;
let activeLanguageNameEnglish = "english";
let activeLanguageNameRussian = "russian";
let markupImageWithToolsNotificationString;
let notTheFullImageWillBeShownNotificationString;
let messageSpaceInnerContents;
let labelParametersBlockTitleGolden;
let labelParametersBlockTitle;
let historyBlockTitleGolden;
let historyBlockTitle;
let polygonWasAddedAndAssignedAnId;
let checkedDOMElement;
let checkedDOMElementInnerText;

// Step 0: Polygon tool is selected by default

// Step 1: Check that activeLanguage.getLanguageName() returns “english”
activeLanguageName = browser.execute("return activeLanguage.getLanguageName();").value;
assert.equal(activeLanguageName, activeLanguageNameEnglish);

// Step 2: Check that #messagespace DOM element contains either a string returned by
// language.english().markupImageWithToolsNotificationString, or a string returned by
// language.english().notTheFullImageWillBeShownNotificationString
markupImageWithToolsNotificationString =
browser.execute("return language.english().markupImageWithToolsNotificationString;").value;
notTheFullImageWillBeShownNotificationString =
browser.execute("return language.english().notTheFullImageWillBeShownNotificationString;").value;
messageSpaceInnerContents =
browser.execute("return document.getElementById(\"message_space\").innerText;").value;
assert.ok(messageSpaceInnerContents.includes(markupImageWithToolsNotificationString) ||
messageSpaceInnerContents.includes(notTheFullImageWillBeShownNotificationString));

// Step 3: Check that #label-parameters-block-title DOM element contains a string
// returned by language.english().labelParameters
labelParametersBlockTitleGolden =
browser.execute("return language.english().labelParameters;").value;
labelParametersBlockTitle =
browser.execute("return document.getElementById(\"label-parameters-block-title\").innerHTML;").value;
assert.ok(labelParametersBlockTitle.includes(labelParametersBlockTitleGolden));

// Step 4: Check that #history-block-title DOM element contains a string
// returned by language.english().history
historyBlockTitleGolden =
browser.execute("return language.english().history;").value;
historyBlockTitle =
browser.execute("return document.getElementById(\"history-block-title\").innerHTML;").value;
assert.ok(historyBlockTitle.includes(historyBlockTitleGolden));

// Step 5: Label {(100, 100), (100, 200), (200, 100)} polygon.
// 5.1. left click on the 100, 100 pixel of the image
browser.leftClick("#canvas-parent", points[0][0], points[0][1]);
// 5.2. left click on the 100, 200 pixel of the image
browser.leftClick("#canvas-parent", points[1][0], points[1][1]);
// 5.3. left click on the 200, 100 pixel of the image
browser.leftClick("#canvas-parent", points[2][0], points[2][1]);
// 5.4. left click on the 100, 100 pixel of the image
browser.leftClick("#canvas-parent", points[0][0], points[0][1]);

// Step 6: Check that historyRow0 DOM element exists and contains a string
// returned by language.english().polygonWasAddedAndAssignedAnId
checkedDOMElement = browser.execute("return document.getElementById(\"historyRow0\");").value;
assert.notEqual(checkedDOMElement, null);

polygonWasAddedAndAssignedAnId =
browser.execute("return language.english().polygonWasAddedAndAssignedAnId;").value;
checkedDOMElementInnerText =
browser.execute("return document.getElementById(\"historyRow0\").innerText;").value;
assert.ok(checkedDOMElementInnerText.includes(polygonWasAddedAndAssignedAnId));

// Step 7: Select "russian" option in #language-selection-select select
browser.selectByVisibleText("#language-selection-select", activeLanguageNameRussian);

// Step 8: Check that activeLanguage.getLanguageName() returns “russian”
activeLanguageName = browser.execute("return activeLanguage.getLanguageName();").value;
assert.equal(activeLanguageName, activeLanguageNameRussian);

// Step 9: Check that #message_space DOM element contains either a string returned by
// language.russian().markupImageWithToolsNotificationString, or a string returned by
// language.russian().notTheFullImageWillBeShownNotificationString
markupImageWithToolsNotificationString =
browser.execute("return language.russian().markupImageWithToolsNotificationString;").value;
notTheFullImageWillBeShownNotificationString =
browser.execute("return language.russian().notTheFullImageWillBeShownNotificationString;").value;
messageSpaceInnerContents =
browser.execute("return document.getElementById(\"message_space\").innerText;").value;
assert.ok(messageSpaceInnerContents.includes(markupImageWithToolsNotificationString) ||
messageSpaceInnerContents.includes(notTheFullImageWillBeShownNotificationString));

// Step 10: Check that #label-parameters-block-title DOM element contains
// a string returned by language.russian().labelParameters
labelParametersBlockTitleGolden =
browser.execute("return language.russian().labelParameters;").value;
labelParametersBlockTitle =
browser.execute("return document.getElementById(\"label-parameters-block-title\").innerHTML;").value;
assert.ok(labelParametersBlockTitle.includes(labelParametersBlockTitleGolden));

// Step 11: Check that #history-block-title DOM element contains a string returned by
// language.russian().history
historyBlockTitleGolden =
browser.execute("return language.russian().history;").value;
historyBlockTitle =
browser.execute("return document.getElementById(\"history-block-title\").innerHTML;").value;
assert.ok(historyBlockTitle.includes(historyBlockTitleGolden));

// Step 12: Check that historyRow0 DOM element exists and contains a string returned by
// language.russian().polygonWasAddedAndAssignedAnId
checkedDOMElement = browser.execute("return document.getElementById(\"historyRow0\");").value;
assert.notEqual(checkedDOMElement, null);

polygonWasAddedAndAssignedAnId =
browser.execute("return language.russian().polygonWasAddedAndAssignedAnId;").value;
checkedDOMElementInnerText =
browser.execute("return document.getElementById(\"historyRow0\").innerText;").value;
assert.ok(checkedDOMElementInnerText.includes(polygonWasAddedAndAssignedAnId));

// Step 13: Select "english" option in #language-selection-select select
browser.selectByVisibleText("#language-selection-select", activeLanguageNameEnglish);

// Step 14: Check that activeLanguage.getLanguageName() returns “english”
activeLanguageName = browser.execute("return activeLanguage.getLanguageName();").value;
assert.equal(activeLanguageName, activeLanguageNameEnglish);

// Step 15: Check that #messagespace DOM element contains either a string returned by
// language.english().markupImageWithToolsNotificationString, or a string returned by
// language.english().notTheFullImageWillBeShownNotificationString
markupImageWithToolsNotificationString =
browser.execute("return language.english().markupImageWithToolsNotificationString;").value;
notTheFullImageWillBeShownNotificationString =
browser.execute("return language.english().notTheFullImageWillBeShownNotificationString;").value;
messageSpaceInnerContents =
browser.execute("return document.getElementById(\"message_space\").innerText;").value;
assert.ok(messageSpaceInnerContents.includes(markupImageWithToolsNotificationString) ||
messageSpaceInnerContents.includes(notTheFullImageWillBeShownNotificationString));

// Step 16: Check that #label-parameters-block-title DOM element contains a string
// returned by language.english().labelParameters
labelParametersBlockTitleGolden =
browser.execute("return language.english().labelParameters;").value;
labelParametersBlockTitle =
browser.execute("return document.getElementById(\"label-parameters-block-title\").innerHTML;").value;
assert.ok(labelParametersBlockTitle.includes(labelParametersBlockTitleGolden));

// Step 17: Check that #history-block-title DOM element contains a string
// returned by language.english().history
historyBlockTitleGolden =
browser.execute("return language.english().history;").value;
historyBlockTitle =
browser.execute("return document.getElementById(\"history-block-title\").innerHTML;").value;
assert.ok(historyBlockTitle.includes(historyBlockTitleGolden));

// Step 18: Check that historyRow0 DOM element exists and contains a string
// returned by language.english().polygonWasAddedAndAssignedAnId
checkedDOMElement = browser.execute("return document.getElementById(\"historyRow0\");").value;
assert.notEqual(checkedDOMElement, null);

polygonWasAddedAndAssignedAnId =
browser.execute("return language.english().polygonWasAddedAndAssignedAnId;").value;
checkedDOMElementInnerText =
browser.execute("return document.getElementById(\"historyRow0\").innerText;").value;
assert.ok(checkedDOMElementInnerText.includes(polygonWasAddedAndAssignedAnId));
});
});

0 comments on commit 2fcf0b9

Please sign in to comment.