Add sort in scenarios page + tests 71/53871/1
authorthuva4 <tharma.thuva@gmail.com>
Thu, 15 Mar 2018 11:12:44 +0000 (16:42 +0530)
committerthuva4 <tharma.thuva@gmail.com>
Thu, 15 Mar 2018 11:12:44 +0000 (16:42 +0530)
Change-Id: I1b1e4c9cc3739c4ed13fe4c76562b8c35fed4531
Signed-off-by: thuva4 <tharma.thuva@gmail.com>
testapi/opnfv_testapi/tests/UI/e2e/scenariosControllerSpec.js
testapi/opnfv_testapi/ui/components/scenarios/scenarios.html
testapi/opnfv_testapi/ui/components/scenarios/scenariosController.js

index bed80dd..e7c5fb0 100644 (file)
@@ -32,154 +32,6 @@ describe('testing the scenarios page for anonymous user', function () {
                                                  {
                                                     "date": "2016-12-11 01:45",
                                                     "score": "14/24"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-15 05:28",
-                                                    "score": "17/24"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-17 03:41",
-                                                    "score": "16/24"
-                                                 },
-                                                 {
-                                                    "date": "2018-01-22T18:30:00.000Z",
-                                                    "score": "10/13"
-                                                 }
-                                              ],
-                                              "trust_indicators": [
-                                                 {
-                                                    "date": "2016-12-09 11:38",
-                                                    "status": "silver"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-25 08:22",
-                                                    "status": "gold"
-                                                 },
-                                                 {
-                                                    "date": "2018-01-22T18:30:00.000Z",
-                                                    "status": "sf"
-                                                 },
-                                                 {
-                                                    "date": "2018-01-17T18:30:00.000Z",
-                                                    "status": "df"
-                                                 }
-                                              ]
-                                           },
-                                           {
-                                              "project": "functest",
-                                              "customs": [
-                                                 "vping_ssh",
-                                                 "vping_userdata",
-                                              ],
-                                              "scores": [
-                                                 {
-                                                    "date": "2016-12-09 11:28",
-                                                    "score": "6/8"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-14 15:34",
-                                                    "score": "8/8"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-19 13:22",
-                                                    "score": "8/8"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-22 18:17",
-                                                    "score": "8/8"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-25 08:22",
-                                                    "score": "8/8"
-                                                 }
-                                              ],
-                                              "trust_indicators": [
-                                                 {
-                                                    "date": "2016-12-09 11:38",
-                                                    "status": "silver"
-                                                 }
-                                              ]
-                                           },
-                                           {
-                                              "project": "sla",
-                                              "customs": [],
-                                              "scores": [
-                                                 {
-                                                    "date": "2018-01-16T18:30:00.000Z",
-                                                    "score": "sdS"
-                                                 }
-                                              ],
-                                              "trust_indicators": []
-                                           },
-                                           {
-                                              "project": "dvsd",
-                                              "customs": [],
-                                              "scores": [],
-                                              "trust_indicators": []
-                                           }
-                                        ]
-                                     },
-                                     {
-                                        "owner": "dfgvds",
-                                        "version": "df",
-                                        "projects": []
-                                     }
-                                  ]
-                               },
-                               {
-                                  "installer": "fuel2",
-                                  "versions": [
-                                     {
-                                        "owner": "testUser",
-                                        "version": "colorado",
-                                        "projects": [
-                                           {
-                                              "project": "yardstick",
-                                              "customs": [
-                                                 "tc002",
-                                                 "tc005",
-                                                 "tc010",
-                                                 "tc011"
-                                              ],
-                                              "scores": [
-                                                 {
-                                                    "date": "2016-12-11 01:45",
-                                                    "score": "14/24"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-15 05:28",
-                                                    "score": "17/24"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-17 03:41",
-                                                    "score": "16/24"
-                                                 }
-                                              ],
-                                              "trust_indicators": [
-                                                 {
-                                                    "date": "2016-12-09 11:38",
-                                                    "status": "silver"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-25 08:22",
-                                                    "status": "gold"
-                                                 }
-                                              ]
-                                           },
-                                           {
-                                              "project": "functest",
-                                              "customs": [
-                                                 "vping_ssh",
-                                                 "vping_userdata"
-                                              ],
-                                              "scores": [
-                                                 {
-                                                    "date": "2016-12-09 11:28",
-                                                    "score": "6/8"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-14 15:34",
-                                                    "score": "8/8"
                                                  }
                                               ],
                                               "trust_indicators": [
@@ -197,7 +49,43 @@ describe('testing the scenarios page for anonymous user', function () {
                             "_id": "5a50fcacsdgdsgdasgfvb861c",
                             "name": "test-scenario",
                             "creation_date": "2018-01-06 22:13:24.160407"
-                            }
+                            },
+                            {
+                                "installers": [
+                                   {
+                                      "installer": "fuel",
+                                      "versions": [
+                                         {
+                                            "owner": "testUser",
+                                            "version": "colorado",
+                                            "projects": [
+                                               {
+                                                  "project": "yardstick",
+                                                  "customs": [
+                                                     "dvs"
+                                                  ],
+                                                  "scores": [
+                                                     {
+                                                        "date": "2016-12-11 01:45",
+                                                        "score": "14/24"
+                                                     }
+                                                  ],
+                                                  "trust_indicators": [
+                                                     {
+                                                        "date": "2016-12-09 11:38",
+                                                        "status": "silver"
+                                                     }
+                                                  ]
+                                               }
+                                            ]
+                                         }
+                                      ]
+                                   }
+                                ],
+                                "_id": "5a50fcacsdgdsgdasgfvb861d",
+                                "name": "z-test-scenario",
+                                "creation_date": "2018-01-06 22:13:24.160407"
+                                }
                         ]
                     }
                 }
@@ -229,6 +117,15 @@ describe('testing the scenarios page for anonymous user', function () {
         expect(cells.get(1).getText()).toContain("test-scenario");
     });
 
+    it('Sort scenarios', function () {
+        browser.get(baseURL+"#/scenarios");
+        var sort = element(by.xpath('//*[@id="ng-app"]/body/div/div[4]/div/table/thead/tr/th[2]/a[2]/span'))
+        sort.click();
+        var row = element.all(by.repeater('(index, scenario) in ctrl.data.scenarios')).first();
+        var cells = row.all(by.tagName('td'));
+        expect(cells.get(1).getText()).toContain("z-test-scenario");
+    });
+
     it('create button is not visible for anonymous user ', function () {
         browser.get(baseURL+'#/scenarios');
         var buttonCreate = element(by.buttonText('Create'));
@@ -271,154 +168,6 @@ describe('testing the scenarios page for user', function () {
                                                  {
                                                     "date": "2016-12-11 01:45",
                                                     "score": "14/24"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-15 05:28",
-                                                    "score": "17/24"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-17 03:41",
-                                                    "score": "16/24"
-                                                 },
-                                                 {
-                                                    "date": "2018-01-22T18:30:00.000Z",
-                                                    "score": "10/13"
-                                                 }
-                                              ],
-                                              "trust_indicators": [
-                                                 {
-                                                    "date": "2016-12-09 11:38",
-                                                    "status": "silver"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-25 08:22",
-                                                    "status": "gold"
-                                                 },
-                                                 {
-                                                    "date": "2018-01-22T18:30:00.000Z",
-                                                    "status": "sf"
-                                                 },
-                                                 {
-                                                    "date": "2018-01-17T18:30:00.000Z",
-                                                    "status": "df"
-                                                 }
-                                              ]
-                                           },
-                                           {
-                                              "project": "functest",
-                                              "customs": [
-                                                 "vping_ssh",
-                                                 "vping_userdata",
-                                              ],
-                                              "scores": [
-                                                 {
-                                                    "date": "2016-12-09 11:28",
-                                                    "score": "6/8"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-14 15:34",
-                                                    "score": "8/8"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-19 13:22",
-                                                    "score": "8/8"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-22 18:17",
-                                                    "score": "8/8"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-25 08:22",
-                                                    "score": "8/8"
-                                                 }
-                                              ],
-                                              "trust_indicators": [
-                                                 {
-                                                    "date": "2016-12-09 11:38",
-                                                    "status": "silver"
-                                                 }
-                                              ]
-                                           },
-                                           {
-                                              "project": "sla",
-                                              "customs": [],
-                                              "scores": [
-                                                 {
-                                                    "date": "2018-01-16T18:30:00.000Z",
-                                                    "score": "sdS"
-                                                 }
-                                              ],
-                                              "trust_indicators": []
-                                           },
-                                           {
-                                              "project": "dvsd",
-                                              "customs": [],
-                                              "scores": [],
-                                              "trust_indicators": []
-                                           }
-                                        ]
-                                     },
-                                     {
-                                        "owner": "dfgvds",
-                                        "version": "df",
-                                        "projects": []
-                                     }
-                                  ]
-                               },
-                               {
-                                  "installer": "fuel2",
-                                  "versions": [
-                                     {
-                                        "owner": "testUser",
-                                        "version": "colorado",
-                                        "projects": [
-                                           {
-                                              "project": "yardstick",
-                                              "customs": [
-                                                 "tc002",
-                                                 "tc005",
-                                                 "tc010",
-                                                 "tc011"
-                                              ],
-                                              "scores": [
-                                                 {
-                                                    "date": "2016-12-11 01:45",
-                                                    "score": "14/24"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-15 05:28",
-                                                    "score": "17/24"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-17 03:41",
-                                                    "score": "16/24"
-                                                 }
-                                              ],
-                                              "trust_indicators": [
-                                                 {
-                                                    "date": "2016-12-09 11:38",
-                                                    "status": "silver"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-25 08:22",
-                                                    "status": "gold"
-                                                 }
-                                              ]
-                                           },
-                                           {
-                                              "project": "functest",
-                                              "customs": [
-                                                 "vping_ssh",
-                                                 "vping_userdata"
-                                              ],
-                                              "scores": [
-                                                 {
-                                                    "date": "2016-12-09 11:28",
-                                                    "score": "6/8"
-                                                 },
-                                                 {
-                                                    "date": "2016-12-14 15:34",
-                                                    "score": "8/8"
                                                  }
                                               ],
                                               "trust_indicators": [
@@ -514,13 +263,13 @@ describe('testing the scenarios page for user', function () {
         expect(cells.get(1).getText()).toContain("test-scenario");
     });
 
-    it('create button is not visible for user ', function () {
+    it('create button is visible for user ', function () {
         browser.get(baseURL+'#/scenarios');
         var buttonCreate = element(by.buttonText('Create'));
         expect(buttonCreate.isDisplayed()).toBe(true);
     });
 
-    it('delete button is not visible for user ', function () {
+    it('delete button is visible for user ', function () {
         browser.get(baseURL+'#/scenarios');
         var buttonDelete = element(by.buttonText('Delete'));
         expect(buttonDelete.isDisplayed()).toBe(true);
index 9057b0f..bde946c 100644 (file)
         <tr style="
         text-align: center;">
             <th style="width: 1%;">Bulk&nbsp;Select</th>
-            <th style="width: 80%;">Name</th>
+            <th style="width: 80%;">Name
+                    <a class="text-danger"  ng-click="ctrl.sortBy()" ng-class="{ 'hidden': ctrl.sortName }" >
+                        <span class="glyphicon glyphicon-sort-by-alphabet pull-right" aria-hidden="true"></span>
+                    </a>
+                    <a class="text-danger"  ng-click="ctrl.sortBy()" ng-class="{ 'hidden': !ctrl.sortName}" >
+                        <span class="glyphicon glyphicon-sort-by-alphabet-alt pull-right" aria-hidden="true"></span>
+                    </a>
+            </th>
             <th style="width: 19%;" ng-class="{'hidden': !auth.isAuthenticated}">Operations</th>
         </tr>
         </thead>
index 98e4089..240287c 100644 (file)
@@ -21,7 +21,7 @@
 
         ScenariosController.$inject = [
         '$scope', '$http', '$filter', '$state', '$window', '$uibModal', 'testapiApiUrl',
-        'raiseAlert', 'confirmModal'
+        'raiseAlert', 'confirmModal', 'sortService'
     ];
 
     /**
@@ -30,7 +30,7 @@
      * through projects declared in TestAPI.
      */
     function ScenariosController($scope, $http, $filter, $state, $window, $uibModal, testapiApiUrl,
-        raiseAlert, confirmModal) {
+        raiseAlert, confirmModal, sortService) {
         var ctrl = this;
         ctrl.url = testapiApiUrl + '/scenarios';
 
@@ -44,8 +44,9 @@
         ctrl.deleteScenario = deleteScenario;
         ctrl.openBatchDeleteModal = openBatchDeleteModal;
         ctrl.deleteBatchScenario = deleteBatchScenario
-
+        ctrl.sortBy = sortBy
         ctrl.checkBox = [];
+        ctrl.sortName = false
 
         function openUpdateModal(name){
             $uibModal.open({
             confirmModal("Delete", 'scenarios', ctrl.deleteScenario,name);
         }
 
+        function sortBy(){
+            ctrl.data.scenarios = sortService.sortFunction(ctrl.data.scenarios, 'name' , ctrl.sortName)
+            ctrl.sortName=!ctrl.sortName
+        }
+
         function deleteScenario(name){
             var scenarioURL = ctrl.url+"/"+name;
             ctrl.scenarioRequest =
            ctrl.resultsRequest =
                $http.get(ctrl.url).success(function (data) {
                    ctrl.data = data;
+                   ctrl.sortBy()
                }).catch(function (data)  {
                    ctrl.data = null;
                    ctrl.showError = true;