From c72bebf41dbd08facb7398fa94680d812ea38a62 Mon Sep 17 00:00:00 2001 From: thuva4 Date: Sat, 30 Dec 2017 09:29:03 +0530 Subject: Add the filter option in results page apply multiple filter in results page. Add e2e tests for results page. Change-Id: Ia55407d921136756ab5f15507c92775f95a761dc Signed-off-by: thuva4 --- .../tests/UI/e2e/resultsControllerSpec.js | 363 +++++++++++++++++++++ testapi/opnfv_testapi/ui/Gruntfile.js | 303 ++++++++--------- .../ui/components/results/results.html | 63 +++- .../ui/components/results/resultsController.js | 98 ++++-- 4 files changed, 627 insertions(+), 200 deletions(-) create mode 100644 testapi/opnfv_testapi/tests/UI/e2e/resultsControllerSpec.js diff --git a/testapi/opnfv_testapi/tests/UI/e2e/resultsControllerSpec.js b/testapi/opnfv_testapi/tests/UI/e2e/resultsControllerSpec.js new file mode 100644 index 0000000..a14f8ea --- /dev/null +++ b/testapi/opnfv_testapi/tests/UI/e2e/resultsControllerSpec.js @@ -0,0 +1,363 @@ +'use strict'; + +var mock = require('protractor-http-mock'); +var baseURL = "http://localhost:8000/" + +describe('testing the result page for anonymous user', function () { + beforeEach(function(){ + mock([ + { + request: { + path: '/api/v1/results', + method: 'GET', + queryString: { + page: '1' + } + }, + response: { + data: { + "pagination": { + "current_page": 1, + "total_pages": 1 + }, + "results": [ + { + "project_name": "testproject", + "description": "Demo results", + "stop_date": "2017-12-28 16:08:43", + "case_name": "testcase", + "build_tag": null, + "user": null, + "installer": "fuel", + "scenario": "test-scenario", + "trust_indicator": null, + "public": "true", + "version": "euphrates", + "details": "", + "criteria": "PASS", + "_id": "5a45170bbb2092000e2643f4", + "start_date": "2017-12-28 14:44:27", + "pod_name": "testPod" + } + ] + } + } + }, + { + request: { + path: '/api/v1/results', + method: 'GET', + queryString: { + page: '1', + project: 'testproject' + } + }, + response: { + data: { + "pagination": { + "current_page": 1, + "total_pages": 1 + }, + "results": [ + { + "project_name": "testproject", + "description": "Demo results", + "stop_date": "2017-12-28 16:08:43", + "case_name": "testcase", + "build_tag": null, + "user": null, + "installer": "fuel", + "scenario": "test-scenario", + "trust_indicator": null, + "public": "true", + "version": "euphrates", + "details": "", + "criteria": "PASS", + "_id": "5a45170bbb2092000e2643f5", + "start_date": "2017-12-28 14:44:27", + "pod_name": "testPod" + } + ] + } + } + }, + { + request: { + path: '/api/v1/results', + method: 'GET', + queryString: { + page: '1', + project: 'testproject', + case: 'testcase' + } + }, + response: { + data: { + "pagination": { + "current_page": 1, + "total_pages": 1 + }, + "results": [ + { + "project_name": "testproject", + "description": "Demo results", + "stop_date": "2017-12-28 16:08:43", + "case_name": "testcase", + "build_tag": null, + "user": null, + "installer": "fuel", + "scenario": "test-scenario", + "trust_indicator": null, + "public": "true", + "version": "euphrates", + "details": "", + "criteria": "PASS", + "_id": "5a45170bbb2092000e2643f6", + "start_date": "2017-12-28 14:44:27", + "pod_name": "testPod" + } + ] + } + } + } + ]); + }); + + afterEach(function(){ + mock.teardown(); + }); + + it( 'should show the results page for anonymous user', function() { + browser.get(baseURL+"#/results"); + expect(element(by.cssContainingText(".ng-binding.ng-scope","Test Results")).isDisplayed()).toBe(true); + }); + + it( 'navigate anonymous user to testCase page', function() { + browser.get(baseURL); + var resultLink = element(by.linkText('Results')).click(); + var EC = browser.ExpectedConditions; + browser.wait(EC.urlContains(baseURL+ '#/results'), 10000); + }); + + it('Should show the results in results page for anonymous user ', function () { + browser.get(baseURL+"#/results"); + var row = element.all(by.repeater('(index, result) in ctrl.data.results')).first(); + var cells = row.all(by.tagName('td')); + expect(cells.get(0).getText()).toContain("5a45170bbb2092000e2643f4"); + }); + + it('Should show the results in results page related to the filters for anonymous user ', function () { + browser.get(baseURL+"#/results"); + var filter = element(by.model('ctrl.filter')); + var filterText = element(by.model('ctrl.filterText')); + filter.sendKeys('project'); + filterText.sendKeys('testproject'); + var buttonFilter = element(by.buttonText('Filter')); + buttonFilter.click(); + var row = element.all(by.repeater('(index, result) in ctrl.data.results')).first(); + var cells = row.all(by.tagName('td')); + expect(cells.get(0).getText()).toContain("5a45170bbb2092000e2643f5"); + filter.sendKeys('case'); + filterText.sendKeys('testcase') + buttonFilter.click(); + expect(cells.get(0).getText()).toContain("5a45170bbb2092000e2643f6"); + }); + it('Should not show the results in results page related to the filters for anonymous user ', function () { + browser.get(baseURL+"#/results"); + var filter = element(by.model('ctrl.filter')); + var filterText = element(by.model('ctrl.filterText')); + filter.sendKeys('project'); + filterText.sendKeys('testproject1'); + var buttonFilter = element(by.buttonText('Filter')); + buttonFilter.click(); + expect(element(by.css('.alert.alert-danger.ng-binding.ng-scope')) + .isDisplayed()).toBe(true); + }); + +}); + +describe('testing the result page for user', function () { + beforeEach(function(){ + mock([ + { + request: { + path: '/api/v1/profile', + method: 'GET' + }, + response: { + data: { + "fullname": "Test User", "_id": "79f82eey9a00c84bfhc7aed", + "user": "testUser", "groups": ["opnfv-testapi-users"], + "email": "testuser@test.com" + } + } + }, + { + request: { + path: '/api/v1/results', + method: 'GET', + queryString: { + page: '1' + } + }, + response: { + data: { + "pagination": { + "current_page": 1, + "total_pages": 1 + }, + "results": [ + { + "project_name": "testproject", + "description": "Demo results", + "stop_date": "2017-12-28 16:08:43", + "case_name": "testcase", + "build_tag": null, + "user": null, + "installer": "fuel", + "scenario": "test-scenario", + "trust_indicator": null, + "public": "true", + "version": "euphrates", + "details": "", + "criteria": "PASS", + "_id": "5a45170bbb2092000e2643f4", + "start_date": "2017-12-28 14:44:27", + "pod_name": "testPod" + } + ] + } + } + }, + { + request: { + path: '/api/v1/results', + method: 'GET', + queryString: { + page: '1', + project: 'testproject' + } + }, + response: { + data: { + "pagination": { + "current_page": 1, + "total_pages": 1 + }, + "results": [ + { + "project_name": "testproject", + "description": "Demo results", + "stop_date": "2017-12-28 16:08:43", + "case_name": "testcase", + "build_tag": null, + "user": null, + "installer": "fuel", + "scenario": "test-scenario", + "trust_indicator": null, + "public": "true", + "version": "euphrates", + "details": "", + "criteria": "PASS", + "_id": "5a45170bbb2092000e2643f5", + "start_date": "2017-12-28 14:44:27", + "pod_name": "testPod" + } + ] + } + } + }, + { + request: { + path: '/api/v1/results', + method: 'GET', + queryString: { + page: '1', + project: 'testproject', + case: 'testcase' + } + }, + response: { + data: { + "pagination": { + "current_page": 1, + "total_pages": 1 + }, + "results": [ + { + "project_name": "testproject", + "description": "Demo results", + "stop_date": "2017-12-28 16:08:43", + "case_name": "testcase", + "build_tag": null, + "user": null, + "installer": "fuel", + "scenario": "test-scenario", + "trust_indicator": null, + "public": "true", + "version": "euphrates", + "details": "", + "criteria": "PASS", + "_id": "5a45170bbb2092000e2643f6", + "start_date": "2017-12-28 14:44:27", + "pod_name": "testPod" + } + ] + } + } + } + ]); + }); + + afterEach(function(){ + mock.teardown(); + }); + + it( 'should show the results page for user', function() { + browser.get(baseURL+"#/results"); + expect(element(by.cssContainingText(".ng-binding.ng-scope","Test Results")).isDisplayed()).toBe(true); + }); + + it( 'navigate user to testCase page', function() { + browser.get(baseURL); + var resultLink = element(by.linkText('Results')).click(); + var EC = browser.ExpectedConditions; + browser.wait(EC.urlContains(baseURL+ '#/results'), 10000); + }); + + it('Should show the results in results page for user ', function () { + browser.get(baseURL+"#/results"); + var row = element.all(by.repeater('(index, result) in ctrl.data.results')).first(); + var cells = row.all(by.tagName('td')); + expect(cells.get(0).getText()).toContain("5a45170bbb2092000e2643f4"); + }); + + it('Should show the results in results page related to the filters for user ', function () { + browser.get(baseURL+"#/results"); + var filter = element(by.model('ctrl.filter')); + var filterText = element(by.model('ctrl.filterText')); + filter.sendKeys('project'); + filterText.sendKeys('testproject'); + var buttonFilter = element(by.buttonText('Filter')); + buttonFilter.click(); + var row = element.all(by.repeater('(index, result) in ctrl.data.results')).first(); + var cells = row.all(by.tagName('td')); + expect(cells.get(0).getText()).toContain("5a45170bbb2092000e2643f5"); + filter.sendKeys('case'); + filterText.sendKeys('testcase') + buttonFilter.click(); + expect(cells.get(0).getText()).toContain("5a45170bbb2092000e2643f6"); + }); + it('Should not show the results in results page related to the filters for user ', function () { + browser.get(baseURL+"#/results"); + var filter = element(by.model('ctrl.filter')); + var filterText = element(by.model('ctrl.filterText')); + filter.sendKeys('project'); + filterText.sendKeys('testproject1'); + var buttonFilter = element(by.buttonText('Filter')); + buttonFilter.click(); + expect(element(by.css('.alert.alert-danger.ng-binding.ng-scope')) + .isDisplayed()).toBe(true); + }); + +}); \ No newline at end of file diff --git a/testapi/opnfv_testapi/ui/Gruntfile.js b/testapi/opnfv_testapi/ui/Gruntfile.js index 56aaa6e..72a47e1 100644 --- a/testapi/opnfv_testapi/ui/Gruntfile.js +++ b/testapi/opnfv_testapi/ui/Gruntfile.js @@ -1,154 +1,155 @@ module.exports = function (grunt) { - require('load-grunt-tasks')(grunt); - require('grunt-protractor-coverage')(grunt); - grunt.loadNpmTasks('grunt-shell-spawn'); - grunt.loadNpmTasks('grunt-wait'); - grunt.loadNpmTasks('grunt-contrib-copy'); - grunt.loadNpmTasks('grunt-contrib-connect'); - grunt.initConfig({ - connect: { - server: { - options: { - port: 8000, - base: './', - middleware: function(connect, options, middlewares) { - middlewares.unshift(function(req, res, next) { - if (req.method.toUpperCase() == 'POST' || req.method.toUpperCase() == "PUT" || - req.method.toUpperCase() == "DELETE") - { - req.method='GET'; - } - return next(); - }); - return middlewares; - } - } - } - }, - copy: { - assets: { - expand: true, - cwd: '../../3rd_party/static/testapi-ui/assets', - src: '**', - dest: 'testapi-ui/assets', - }, - components: { - expand: true, - cwd: 'components', - src: '**', - dest: 'testapi-ui/components', - }, - shared: { - expand: true, - cwd: 'shared', - src: '**', - dest: 'testapi-ui/shared', - }, - filesPng: { - expand: true, - src: '*.png', - dest: 'testapi-ui/', - }, - filesIco: { - expand: true, - src: '*.ico', - dest: 'testapi-ui/', - }, - filesJs: { - expand: true, - src: 'app.js', - dest: 'testapi-ui/', - }, - filesJson: { - expand: true, - src: 'config.json', - dest: 'testapi-ui/', - } - }, - wait: { - default: { - options: { - delay: 3000 - } - } - }, - shell: { - updateSelenium: { - command: 'node_modules/protractor/bin/webdriver-manager update', - options: { - async: false - } - }, - startSelenium: { - command: 'node_modules/protractor/bin/webdriver-manager start', - options: { - async: true - } - }, - deleteFiles: { - command: 'rm -r testapi-ui', - options: { - async: false - } - }, - options: { - stdout: false, - stderr: false - } - }, - instrument: { - files: ['components/**/*.js'], - options: { - lazy: false, - basePath: "./testapi-ui/" - } - }, - karma: { - unit: { - configFile: 'karma.conf.js' - } - }, - protractor_coverage: { - options: { - keepAlive: true, - noColor: false, - coverageDir: '../tests/UI/coverage', - args: { - specs: ['../tests/UI/e2e/testCasesControllerSpec.js'] - } - }, - local: { - options: { - configFile: '../tests/UI/protractor-conf.js' - } - } - }, - makeReport: { - src: '../tests/UI/coverage/*.json', - options: { - print: 'detail' - } - } - }); - grunt.registerTask('test', [ - 'karma:unit' - ]); - grunt.registerTask('e2e', [ - 'copy:assets', - 'copy:components', - 'copy:shared', - 'copy:filesPng', - 'copy:filesIco', - 'copy:filesJs', - 'copy:filesJson', - 'instrument', - 'connect', - 'shell:updateSelenium', - 'shell:startSelenium', - 'wait:default', - 'protractor_coverage', - 'makeReport', - 'shell:deleteFiles' - ]); + require('load-grunt-tasks')(grunt); + require('grunt-protractor-coverage')(grunt); + grunt.loadNpmTasks('grunt-shell-spawn'); + grunt.loadNpmTasks('grunt-wait'); + grunt.loadNpmTasks('grunt-contrib-copy'); + grunt.loadNpmTasks('grunt-contrib-connect'); + grunt.initConfig({ + connect: { + server: { + options: { + port: 8000, + base: './', + middleware: function(connect, options, middlewares) { + middlewares.unshift(function(req, res, next) { + if (req.method.toUpperCase() == 'POST' || req.method.toUpperCase() == "PUT" || + req.method.toUpperCase() == "DELETE") + { + req.method='GET'; + } + return next(); + }); + return middlewares; + } + } + } + }, + copy: { + assets: { + expand: true, + cwd: '../../3rd_party/static/testapi-ui/assets', + src: '**', + dest: 'testapi-ui/assets', + }, + components: { + expand: true, + cwd: 'components', + src: '**', + dest: 'testapi-ui/components', + }, + shared: { + expand: true, + cwd: 'shared', + src: '**', + dest: 'testapi-ui/shared', + }, + filesPng: { + expand: true, + src: '*.png', + dest: 'testapi-ui/', + }, + filesIco: { + expand: true, + src: '*.ico', + dest: 'testapi-ui/', + }, + filesJs: { + expand: true, + src: 'app.js', + dest: 'testapi-ui/', + }, + filesJson: { + expand: true, + src: 'config.json', + dest: 'testapi-ui/', + } + }, + wait: { + default: { + options: { + delay: 3000 + } + } + }, + shell: { + updateSelenium: { + command: 'node_modules/protractor/bin/webdriver-manager update', + options: { + async: false + } + }, + startSelenium: { + command: 'node_modules/protractor/bin/webdriver-manager start', + options: { + async: true + } + }, + deleteFiles: { + command: 'rm -r testapi-ui', + options: { + async: false + } + }, + options: { + stdout: false, + stderr: false + } + }, + instrument: { + files: ['components/**/*.js'], + options: { + lazy: false, + basePath: "./testapi-ui/" + } + }, + karma: { + unit: { + configFile: 'karma.conf.js' + } + }, + protractor_coverage: { + options: { + keepAlive: true, + noColor: false, + coverageDir: '../tests/UI/coverage', + args: { + specs: ['../tests/UI/e2e/testCasesControllerSpec.js', + '../tests/UI/e2e/resultsControllerSpec.js'] + } + }, + local: { + options: { + configFile: '../tests/UI/protractor-conf.js' + } + } + }, + makeReport: { + src: '../tests/UI/coverage/*.json', + options: { + print: 'detail' + } + } + }); + grunt.registerTask('test', [ + 'karma:unit' + ]); + grunt.registerTask('e2e', [ + 'copy:assets', + 'copy:components', + 'copy:shared', + 'copy:filesPng', + 'copy:filesIco', + 'copy:filesJs', + 'copy:filesJson', + 'instrument', + 'connect', + 'shell:updateSelenium', + 'shell:startSelenium', + 'wait:default', + 'protractor_coverage', + 'makeReport', + 'shell:deleteFiles' + ]); } diff --git a/testapi/opnfv_testapi/ui/components/results/results.html b/testapi/opnfv_testapi/ui/components/results/results.html index 2ae5339..0e7b8d5 100644 --- a/testapi/opnfv_testapi/ui/components/results/results.html +++ b/testapi/opnfv_testapi/ui/components/results/results.html @@ -18,15 +18,28 @@
-
-

Filters

-
-
- -

+

+
+
+ +
+
+ +
+
+ Search:   + +
+
+ Start Date:   +

-
- -

+

+ End Date:   +

-
- - +
+ Filter:   + +
+ +
+
+ {{key}} : {{tag}} +
+ × +
+
@@ -103,7 +136,7 @@ boundary-links="true" rotate="false" num-pages="ctrl.numPages" - ng-change="ctrl.update()"> + ng-change="ctrl.filterList()">
diff --git a/testapi/opnfv_testapi/ui/components/results/resultsController.js b/testapi/opnfv_testapi/ui/components/results/resultsController.js index cc6cc0b..e9b4443 100644 --- a/testapi/opnfv_testapi/ui/components/results/resultsController.js +++ b/testapi/opnfv_testapi/ui/components/results/resultsController.js @@ -51,7 +51,6 @@ var ctrl = this; ctrl.uploadFile=uploadFile; - ctrl.update = update; ctrl.open = open; ctrl.clearFilters = clearFilters; ctrl.associateMeta = associateMeta; @@ -60,6 +59,11 @@ ctrl.associateProductVersion = associateProductVersion; ctrl.getProductVersions = getProductVersions; ctrl.prepVersionEdit = prepVersionEdit; + ctrl.deleteTag = deleteTag; + ctrl.filterList= filterList; + ctrl.testFilter = testFilter + + ctrl.tagArray = {} /** Mappings of Interop WG components to marketing program names. */ ctrl.targetMappings = { @@ -104,8 +108,7 @@ $state.go('home'); } - ctrl.pageHeader = ctrl.isUserResults ? - 'Private test results' : 'Community test results'; + ctrl.pageHeader = "Test Results" ctrl.pageParagraph = ctrl.isUserResults ? 'Your most recently uploaded test results are listed here.' : @@ -118,10 +121,24 @@ if (ctrl.isUserResults) { ctrl.authRequest = $scope.auth.doSignCheck() - .then(ctrl.update); + .then(ctrl.filterList); // ctrl.getUserProducts(); } else { - ctrl.update(); + ctrl.filterList(); + } + + function deleteTag(index){ + delete ctrl.tagArray[index]; + ctrl.filterList(); + } + + function testFilter(text){ + for (var filter in ctrl.tagArray){ + if(text==filter){ + return true; + } + } + return false; } @@ -138,7 +155,7 @@ .success(function(data){ var id = data.href.substr(data.href.lastIndexOf('/')+1); ctrl.uploadState = "Upload succeed. Result id is " + id; - ctrl.update(); + ctrl.filterList(); }) .error(function(data, status){ @@ -159,37 +176,50 @@ * This will contact the TestAPI API to get a listing of test run * results. */ - function update() { + function filterList(){ + if(ctrl.filter && ctrl.filterText!=""){ + ctrl.tagArray[ctrl.filter] = ctrl.filterText; + } ctrl.showError = false; - // Construct the API URL based on user-specified filters. var content_url = testapiApiUrl + '/results' + '?page=' + ctrl.currentPage; - var start = $filter('date')(ctrl.startDate, 'yyyy-MM-dd'); - if (start) { - content_url = - content_url + '&from=' + start + ' 00:00:00'; - } - var end = $filter('date')(ctrl.endDate, 'yyyy-MM-dd'); - if (end) { - content_url = content_url + '&to=' + end + ' 23:59:59'; - } - if (ctrl.isUserResults) { - content_url = content_url + '&signed'; + for(var key in ctrl.tagArray){ + if(key=="start_date"){ + var start = $filter('date')(ctrl.tagArray[key], 'yyyy-MM-dd'); + if (start) { + content_url = + content_url + '&from=' + start + ' 00:00:00'; + } + } + else if(key=="end_date"){ + var end = $filter('date')(ctrl.tagArray[key], 'yyyy-MM-dd'); + if (end) { + content_url = content_url + '&to=' + end + ' 23:59:59'; + } + } + else{ + content_url = content_url + "&" + key + "=" + ctrl.tagArray[key] + } + if (ctrl.isUserResults) { + content_url = content_url + '&signed'; + } } ctrl.resultsRequest = - $http.get(content_url).success(function (data) { - ctrl.data = data; - ctrl.totalItems = ctrl.data.pagination.total_pages * ctrl.itemsPerPage; - ctrl.currentPage = ctrl.data.pagination.current_page; - }).error(function (error) { - ctrl.data = null; - ctrl.totalItems = 0; - ctrl.showError = true; - ctrl.error = - 'Error retrieving results listing from server: ' + - angular.toJson(error); - }); + $http.get(content_url).success(function (data) { + ctrl.data = data; + ctrl.totalItems = ctrl.data.pagination.total_pages * ctrl.itemsPerPage; + ctrl.currentPage = ctrl.data.pagination.current_page; + }).error(function (error) { + ctrl.data = null; + ctrl.totalItems = 0; + ctrl.showError = true; + ctrl.error = + 'Error retrieving results listing from server: ' + + angular.toJson(error); + }); + ctrl.filterText = '' } + ctrl.filterList(); /** * This is called when the date filter calendar is opened. It @@ -209,9 +239,9 @@ * listing. */ function clearFilters() { - ctrl.startDate = null; - ctrl.endDate = null; - ctrl.update(); + ctrl.tagArray = {} + ctrl.filter = undefined + ctrl.filterList(); } /** -- cgit 1.2.3-korg