diff --git a/front/js/app/data_collector.js b/front/js/app/data_collector.js index 342c014..ccdbb1d 100644 --- a/front/js/app/data_collector.js +++ b/front/js/app/data_collector.js @@ -2,6 +2,8 @@ * Created by Alexey Merzlikin on 08.04.2017. */ +var outputJson = ""; + function DataCollector() { this.dataEntities = {}; @@ -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; + } } }; @@ -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; }; diff --git a/front/js/app/history.js b/front/js/app/history.js index ea29e99..6147c0f 100644 --- a/front/js/app/history.js +++ b/front/js/app/history.js @@ -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) { diff --git a/front/js/app/svg.js b/front/js/app/svg.js index 909e56a..9849872 100644 --- a/front/js/app/svg.js +++ b/front/js/app/svg.js @@ -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 = []; } @@ -158,7 +159,6 @@ function onPolygonClick(polygon) { polygon.setDragEnabled(true); - onPolygonSelected(selectedPolygon); showPolygonSelectedMessage(); diff --git a/package.json b/package.json index 71df066..8356725 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test/specs/BrightnessTest.js b/test/specs/BrightnessTest.js new file mode 100644 index 0000000..372c233 --- /dev/null +++ b/test/specs/BrightnessTest.js @@ -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); + }); +}); \ No newline at end of file diff --git a/test/specs/CompleteLabelingProcessTest.js b/test/specs/CompleteLabelingProcessTest.js new file mode 100644 index 0000000..c360c90 --- /dev/null +++ b/test/specs/CompleteLabelingProcessTest.js @@ -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); + }); + }); +}); \ No newline at end of file diff --git a/test/specs/switchingBetweenLanguages.js b/test/specs/switchingBetweenLanguages.js new file mode 100644 index 0000000..0e3d3db --- /dev/null +++ b/test/specs/switchingBetweenLanguages.js @@ -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)); + }); +}); \ No newline at end of file