This is an automated email from the ASF dual-hosted git repository.
mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 3098765 Removed restangular from DivisionService (#3617)
3098765 is described below
commit 3098765665af7e632851399f529fd244953da767
Author: ocket8888 <[email protected]>
AuthorDate: Thu Sep 19 08:22:07 2019 -0600
Removed restangular from DivisionService (#3617)
* Removed restangular from ./DivisionService.js
* Fixed some service methods not throwing in error handlers
* fixed PUT method not sending a payload
* adds some UI tests for updating and deleting division
---
.../app/src/common/api/DivisionService.js | 74 +++++++++++++---------
.../table/divisions/table.divisions.tpl.html | 2 +-
.../test/end_to_end/divisions/divisions-spec.js | 25 +++++++-
3 files changed, 69 insertions(+), 32 deletions(-)
diff --git a/traffic_portal/app/src/common/api/DivisionService.js
b/traffic_portal/app/src/common/api/DivisionService.js
index a6c79c1..45c70f5 100644
--- a/traffic_portal/app/src/common/api/DivisionService.js
+++ b/traffic_portal/app/src/common/api/DivisionService.js
@@ -17,54 +17,70 @@
* under the License.
*/
-var DivisionService = function(Restangular, locationUtils, messageModel) {
+var DivisionService = function($http, ENV, locationUtils, messageModel) {
this.getDivisions = function(queryParams) {
- return Restangular.all('divisions').getList(queryParams);
+ return $http.get(ENV.api['root'] + 'divisions', {params:
queryParams}).then(
+ function(result) {
+ return result.data.response;
+ },
+ function(err) {
+ throw err;
+ }
+ );
};
this.getDivision = function(id) {
- return Restangular.one("divisions", id).get();
+ return $http.get(ENV.api['root'] + 'divisions', {params: {id:
id}}).then(
+ function(result) {
+ return result.data.response[0];
+ },
+ function(err) {
+ throw err;
+ }
+ );
};
this.createDivision = function(division) {
- return Restangular.service('divisions').post(division)
- .then(
- function() {
- messageModel.setMessages([ { level: 'success', text:
'Division created' } ], true);
- locationUtils.navigateToPath('/divisions');
- },
- function(fault) {
- messageModel.setMessages(fault.data.alerts, false);
- }
- );
+ return $http.post(ENV.api['root'] + 'divisions', division).then(
+ function(result) {
+ messageModel.setMessages(result.data.alerts, true);
+ locationUtils.navigateToPath('/divisions');
+ return result;
+ },
+ function(err) {
+ messageModel.setMessages(err.data.alerts, false);
+ throw err;
+ }
+ );
};
this.updateDivision = function(division) {
- return division.put()
- .then(
- function() {
- messageModel.setMessages([ { level: 'success', text:
'Division updated' } ], false);
- },
- function(fault) {
- messageModel.setMessages(fault.data.alerts, false);
- }
- );
+ return $http.put(ENV.api['root'] + 'divisions/' + division.id,
division).then(
+ function(result) {
+ messageModel.setMessages(result.data.alerts, false);
+ return result; },
+ function(err) {
+ messageModel.setMessages(err.data.alerts, false);
+ throw err;
+ }
+ );
};
this.deleteDivision = function(id) {
- return Restangular.one("divisions", id).remove()
- .then(
- function() {
- messageModel.setMessages([ { level: 'success', text:
'Division deleted' } ], true);
+ return $http.delete(ENV.api['root'] + 'divisions/' + id).then(
+ function(result) {
+ messageModel.setMessages(result.data.alerts, true);
+ return result;
},
- function(fault) {
- messageModel.setMessages(fault.data.alerts, true);
+ function(err) {
+ messageModel.setMessages(err.data.alerts, true);
+ throw err;
}
);
};
};
-DivisionService.$inject = ['Restangular', 'locationUtils', 'messageModel'];
+DivisionService.$inject = ['$http', 'ENV', 'locationUtils', 'messageModel'];
module.exports = DivisionService;
diff --git
a/traffic_portal/app/src/common/modules/table/divisions/table.divisions.tpl.html
b/traffic_portal/app/src/common/modules/table/divisions/table.divisions.tpl.html
index c253541..00fd384 100644
---
a/traffic_portal/app/src/common/modules/table/divisions/table.divisions.tpl.html
+++
b/traffic_portal/app/src/common/modules/table/divisions/table.divisions.tpl.html
@@ -38,7 +38,7 @@ under the License.
</thead>
<tbody>
<tr ng-click="editDivision(d.id)" ng-repeat="d in ::divisions">
- <td data-search="^{{::d.name}}$">{{::d.name}}</td>
+ <td name="name" data-search="^{{::d.name}}$">{{::d.name}}</td>
</tr>
</tbody>
</table>
diff --git a/traffic_portal/test/end_to_end/divisions/divisions-spec.js
b/traffic_portal/test/end_to_end/divisions/divisions-spec.js
index 47c8c07..f935723 100644
--- a/traffic_portal/test/end_to_end/divisions/divisions-spec.js
+++ b/traffic_portal/test/end_to_end/divisions/divisions-spec.js
@@ -39,8 +39,8 @@ describe('Traffic Portal Divisions Test Suite', function() {
expect(browser.getCurrentUrl().then(commonFunctions.urlPath)).toEqual(commonFunctions.urlPath(browser.baseUrl)+"#!/divisions/new");
});
- it('should fill out form, create button is enabled and submit',
function () {
- console.log("Filling out form, check create button is enabled
and submit");
+ it('should create a new division', function () {
+ console.log("Creating a new division");
expect(pageData.createButton.isEnabled()).toBe(false);
pageData.name.sendKeys(myNewDiv.name);
expect(pageData.createButton.isEnabled()).toBe(true);
@@ -48,4 +48,25 @@ describe('Traffic Portal Divisions Test Suite', function() {
expect(browser.getCurrentUrl().then(commonFunctions.urlPath)).toEqual(commonFunctions.urlPath(browser.baseUrl)+"#!/divisions");
});
+ it('should update a division', function() {
+ console.log('Updating the new division: ' + myNewDiv.name);
+ pageData.searchFilter.sendKeys(myNewDiv.name);
+ element.all(by.repeater('d in
::divisions')).filter(function(row){
+ return
row.element(by.name('name')).getText().then(function(val){
+ return val === myNewDiv.name;
+ });
+ }).get(0).click();
+ pageData.name.clear();
+ pageData.name.sendKeys(myNewDiv.name + ' updated');
+ pageData.updateButton.click();
+ expect(pageData.name.getText() === myNewDiv.name + ' updated');
+ });
+
+ it('should delete the new division', function() {
+ console.log('Deleting the new division: ' + myNewDiv.name + '
updated');
+ pageData.deleteButton.click();
+ pageData.confirmWithNameInput.sendKeys(myNewDiv.name + '
updated');
+ pageData.deletePermanentlyButton.click();
+ });
+
});