From b694d95b5143e63afa03b64287f3046a2951e64a Mon Sep 17 00:00:00 2001 From: sj108s Date: Wed, 21 Mar 2018 21:25:39 +0530 Subject: Fixed couple more defects related to test screen Fixed poll status button alignment and fixed minore defect in test screen and updated test cases as per code change Issue-ID: APPC-713 Change-Id: I530739fda78d6ca05fba4cbfaacef8ead3b7c23d Signed-off-by: sj108s --- src/app/test/test.component.html | 30 +++--- src/app/test/test.component.spec.ts | 193 +++++++++++++++++++----------------- src/app/test/test.component.ts | 27 +++-- 3 files changed, 136 insertions(+), 114 deletions(-) diff --git a/src/app/test/test.component.html b/src/app/test/test.component.html index 3519007..c2eb22e 100644 --- a/src/app/test/test.component.html +++ b/src/app/test/test.component.html @@ -17,7 +17,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -ECOMP is a trademark and service mark of AT&T Intellectual Property. ============LICENSE_END============================================ --> @@ -26,7 +25,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
-
+
@@ -43,7 +42,8 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
- +
+
@@ -98,9 +98,11 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
-                    - +
@@ -110,7 +112,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
- @@ -121,22 +123,22 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
-
+
-
-

+ - +

POLL TEST STATUS RESPONSE
-
-
Poll test no {{pollCounter}}
+
+
Poll test no {{pollCounter}}
@@ -168,9 +170,9 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
-
Poll test no {{pollCounter}}
+
Poll test no {{pollCounter}}
{{statusResponse}} -
+

diff --git a/src/app/test/test.component.spec.ts b/src/app/test/test.component.spec.ts index 830effd..15dde6c 100644 --- a/src/app/test/test.component.spec.ts +++ b/src/app/test/test.component.spec.ts @@ -17,7 +17,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -ECOMP is a trademark and service mark of AT&T Intellectual Property. ============LICENSE_END============================================ */ @@ -91,7 +90,7 @@ describe('TestComponent', () => { component.pollTestStatus(); expect(service).toBeTruthy(); - + })); // Test download Method @@ -178,9 +177,9 @@ describe('TestComponent', () => { it('should execute if file extension is XLS, XLSX', () => { let reader = new FileReader(); - let file = new File(["testing"], "foo.XLS", {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}) + let file = new File(["testing"], "foo.XLS", { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }) let fileExtension = 'XLS'; - let event = { isTrusted: true, type: "change", target: {files: [file]} } + let event = { isTrusted: true, type: "change", target: { files: [file] } } component.upload(event); @@ -190,10 +189,10 @@ describe('TestComponent', () => { it('should return an error if file extension is not XLS, XLSX', () => { let reader = new FileReader(); - let file = new File(["testing"], "foo.doc", {type: ""}) + let file = new File(["testing"], "foo.doc", { type: "" }) let fileExtension = 'doc'; - let event = { isTrusted: true, type: "change", target: {files: [file]} } - + let event = { isTrusted: true, type: "change", target: { files: [file] } } + component.upload(event); expect(reader instanceof FileReader).toBeTruthy(); @@ -201,7 +200,7 @@ describe('TestComponent', () => { }); it('Should return an error is files length is not equal to 1', () => { - + }); }); @@ -287,35 +286,35 @@ describe('TestComponent', () => { }); it('should return response on success', inject([MockBackend], (mockBackend: MockBackend) => { - let mockData = 'testing'; - let response = new ResponseOptions({ - body: JSON.stringify(mockData) - }); - const baseResponse = new Response(response); - mockBackend.connections.subscribe( - (c: MockConnection) => { - c.mockRespond(baseResponse) - } - ); - - component.action = 'ConfigModify'; - - component.testVnf(); + let mockData = 'testing'; + let response = new ResponseOptions({ + body: JSON.stringify(mockData) + }); + const baseResponse = new Response(response); + mockBackend.connections.subscribe( + (c: MockConnection) => { + c.mockRespond(baseResponse) + } + ); + + component.action = 'ConfigModify'; + + component.testVnf(); })); - it('should return an error if fails', inject([HttpUtilService],( httpUtilService: HttpUtilService) => { - let error = 'Error in connecting to APPC Server'; - let spy = spyOn(httpUtilService, 'post').and.returnValue(Observable.throw(error)); - component.action = 'ConfigModify'; - - component.testVnf(); + it('should return an error if fails', inject([HttpUtilService], (httpUtilService: HttpUtilService) => { + let error = 'Error in connecting to APPC Server'; + let spy = spyOn(httpUtilService, 'post').and.returnValue(Observable.throw(error)); + component.action = 'ConfigModify'; - expect(spy).toHaveBeenCalled(); - expect(component.enableBrowse).toBeTruthy(); - expect(component.enableTestButton).toBeTruthy(); - expect(component.enablePollButton).toBeTruthy(); - expect(component.enableCounterDiv).toBeFalsy(); - })); + component.testVnf(); + + expect(spy).toHaveBeenCalled(); + expect(component.enableBrowse).toBeTruthy(); + expect(component.enableTestButton).toBeTruthy(); + expect(component.enablePollButton).toBeTruthy(); + expect(component.enableCounterDiv).toBeFalsy(); + })); it('test setTimeout', inject([NgProgress], (ngProgress: NgProgress) => { let spy = spyOn(ngProgress, 'done'); @@ -334,64 +333,80 @@ describe('TestComponent', () => { it('should call fake server', inject([MockBackend], (mockBackend: MockBackend) => { component.requestId = new Date().getTime().toString(); - component.actionIdentifiers['vnf-id'] = 123456; - let mockData = { "output": { "common-header": { "originator-id": "CDT", "sub-request-id": "653018029941", "timestamp": "2018-02-12T07:27:21.448Z", "api-ver": "2.00", "request-id": "653018029941", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 } }, "payload": "{\"status-reason\":\"FAILED\",\"status\":\"FAILED\"}", "status": { "message": "SUCCESS - request has been processed successfully", "code": 400 } } } ; - let response = new ResponseOptions({ - body: JSON.stringify(mockData) - }); - const baseResponse = new Response(response); - mockBackend.connections.subscribe( - (c: MockConnection) => c.mockRespond(baseResponse) - ); - - component.pollTestStatus(); + component.actionIdentifiers['vnf-id'] = 123456; + let mockData = { "output": { "common-header": { "originator-id": "CDT", "sub-request-id": "653018029941", "timestamp": "2018-02-12T07:27:21.448Z", "api-ver": "2.00", "request-id": "653018029941", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 } }, "payload": "{\"status-reason\":\"FAILED\",\"status\":\"FAILED\"}", "status": { "message": "SUCCESS - request has been processed successfully", "code": 400 } } }; + let response = new ResponseOptions({ + body: JSON.stringify(mockData) + }); + const baseResponse = new Response(response); + mockBackend.connections.subscribe( + (c: MockConnection) => c.mockRespond(baseResponse) + ); + + component.pollTestStatus(); })); it('should call fake server if status is success', inject([MockBackend], (mockBackend: MockBackend) => { - component.requestId = new Date().getTime().toString(); - component.actionIdentifiers['vnf-id'] = 123456; - let mockData = { "output": { "common-header": { "originator-id": "CDT", "sub-request-id": "653018029941", "timestamp": "2018-02-12T07:27:21.448Z", "api-ver": "2.00", "request-id": "653018029941", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 } }, "payload": "{\"status-reason\":\"SUCCESS\",\"status\":\"SUCCESS\"}", "status": { "message": "SUCCESS - request has been processed successfully", "code": 400 } } } ; - let response = new ResponseOptions({ - body: JSON.stringify(mockData) - }); - const baseResponse = new Response(response); - mockBackend.connections.subscribe( - (c: MockConnection) => c.mockRespond(baseResponse) - ); - - component.pollTestStatus(); - })); - - it('should execute else part if timeStamp && status && statusReason are false', inject([MockBackend], (mockBackend: MockBackend) => { - component.requestId = new Date().getTime().toString(); - component.actionIdentifiers['vnf-id'] = 123456; - let mockData = { "output": { "common-header": { "originator-id": "CDT", "sub-request-id": "653018029941", "timestamp": "2018-02-12T07:27:21.448Z", "api-ver": "2.00", "request-id": "653018029941", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 } }, "payload": "{\"status-reason\":\"FAILED\",\"status\":\"\"}", "status": { "message": "SUCCESS - request has been processed successfully", "code": 400 } } } ; - let response = new ResponseOptions({ - body: JSON.stringify(mockData) - }); - const baseResponse = new Response(response); - mockBackend.connections.subscribe( - (c: MockConnection) => c.mockRespond(baseResponse) - ); - - component.pollTestStatus(); - })); - - it('should return an error if fails', inject([MockBackend], (mockBackend: MockBackend) => { - let error = 'Error Connecting to APPC server'; - component.requestId = new Date().getTime().toString(); - component.actionIdentifiers['vnf-id'] = 123456; - let mockData = ''; - let response = new ResponseOptions({ - body: JSON.stringify(mockData) - }); - const baseResponse = new Response(response); - mockBackend.connections.subscribe( - (c: MockConnection) => c.mockError(new Error(error)) - ); - - component.pollTestStatus(); - })); + component.requestId = new Date().getTime().toString(); + component.actionIdentifiers['vnf-id'] = 123456; + let mockData = { "output": { "common-header": { "originator-id": "CDT", "sub-request-id": "653018029941", "timestamp": "2018-02-12T07:27:21.448Z", "api-ver": "2.00", "request-id": "653018029941", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 } }, "payload": "{\"status-reason\":\"SUCCESS\",\"status\":\"SUCCESS\"}", "status": { "message": "SUCCESS - request has been processed successfully", "code": 400 } } }; + let response = new ResponseOptions({ + body: JSON.stringify(mockData) + }); + const baseResponse = new Response(response); + mockBackend.connections.subscribe( + (c: MockConnection) => c.mockRespond(baseResponse) + ); + + component.pollTestStatus(); + })); + + it('should check error condition on polling where timestamp and test status are not available', inject([MockBackend], (mockBackend: MockBackend) => { + component.requestId = new Date().getTime().toString(); + component.actionIdentifiers['vnf-id'] = 123456; + //let mockData = { "output": { "common-header": { "originator-id": "CDT", "sub-request-id": "653018029941", "timestamp": "2018-02-12T07:27:21.448Z", "api-ver": "2.00", "request-id": "653018029941", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 } }, "payload": "{\"status-reason\":\"FAILED\",\"status\":\"\"}", "status": { "message": "SUCCESS - request has been processed successfully", "code": 400 } } } ; + let mockData = { "output": { "common-header": { "timestamp": "2018-03-21T14:20:30.910Z", "api-ver": "2.00", "request-id": "1521642030910", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 }, "originator-id": "CDT", "sub-request-id": "1521642030910" }, "status": { "message": "INVALID INPUT PARAMETER - vserver-id", "code": 301 } } }; + let response = new ResponseOptions({ + body: JSON.stringify(mockData) + }); + const baseResponse = new Response(response); + mockBackend.connections.subscribe( + (c: MockConnection) => c.mockRespond(baseResponse) + ); + + component.pollTestStatus(); + })); + + it('should execute else part if timeStamp && status && statusReason are false', inject([MockBackend], (mockBackend: MockBackend) => { + component.requestId = new Date().getTime().toString(); + component.actionIdentifiers['vnf-id'] = 123456; + let mockData = { "output": { "common-header": { "originator-id": "CDT", "sub-request-id": "653018029941", "timestamp": "2018-02-12T07:27:21.448Z", "api-ver": "2.00", "request-id": "653018029941", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 } }, "payload": "{\"status-reason\":\"FAILED\",\"status\":\"\"}", "status": { "message": "SUCCESS - request has been processed successfully", "code": 400 } } }; + let response = new ResponseOptions({ + body: JSON.stringify(mockData) + }); + const baseResponse = new Response(response); + mockBackend.connections.subscribe( + (c: MockConnection) => c.mockRespond(baseResponse) + ); + + component.pollTestStatus(); + })); + + it('should return an error if fails', inject([MockBackend], (mockBackend: MockBackend) => { + let error = 'Error Connecting to APPC server'; + component.requestId = new Date().getTime().toString(); + component.actionIdentifiers['vnf-id'] = 123456; + let mockData = ''; + let response = new ResponseOptions({ + body: JSON.stringify(mockData) + }); + const baseResponse = new Response(response); + mockBackend.connections.subscribe( + (c: MockConnection) => c.mockError(new Error(error)) + ); + + component.pollTestStatus(); + })); }); // Test getUrlEndPoint Method diff --git a/src/app/test/test.component.ts b/src/app/test/test.component.ts index a7516ec..2fd8525 100644 --- a/src/app/test/test.component.ts +++ b/src/app/test/test.component.ts @@ -17,7 +17,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -ECOMP is a trademark and service mark of AT&T Intellectual Property. ============LICENSE_END============================================ */ @@ -194,7 +193,7 @@ export class TestComponent implements OnInit { this.showStatusResponseDiv = false; this.errorResponse = ''; this.statusResponse = ''; - this.enableDownload=true; + this.enableDownload = true; let arrData = ((XLSX.utils.sheet_to_json(ws, { blankrows: false }))); @@ -210,10 +209,10 @@ export class TestComponent implements OnInit { // Refactor this.payload = this.processUploadedFile(arrData); this.uploadedFileResult(); - }; + }; reader.readAsBinaryString(target.files[0]); - + } else { @@ -236,7 +235,7 @@ export class TestComponent implements OnInit { } } -processUploadedFile(arrData) { + processUploadedFile(arrData) { let tempPayload = {}; for (var i = 0; i < arrData.length; i++) { var element = arrData[i]; @@ -252,7 +251,7 @@ processUploadedFile(arrData) { } } - + if (element['List Name'] === 'payload') { var listName1 = element['List Name_1']; var listName2 = element['List Name_2']; @@ -280,7 +279,7 @@ processUploadedFile(arrData) { return tempPayload; } - uploadedFileResult() { + uploadedFileResult() { if (this.action && this.actionIdentifiers['vnf-id']) { this.nService.success('Success', 'SpreadSheet uploaded successfully'); } @@ -459,23 +458,29 @@ processUploadedFile(arrData) { } else { this.showStatusResponseDiv = false; + if (this.subscribe && this.subscribe != undefined) { + this.subscribe.unsubscribe(); + this.enablePollButton = true; + } + } - }, error => { this.statusResponse = null; this.showStatusResponseDiv = false; this.errorResponse = 'Error Connecting to APPC server'; this.enableCounterDiv = false; - if (this.subscribe && this.subscribe != undefined) this.subscribe.unsubscribe(); + if (this.subscribe && this.subscribe != undefined) { + this.subscribe.unsubscribe(); + this.enablePollButton = true; + } }); - } else { this.nService.error("Error", "Please enter vnf Id & request Id"); } - + } getUrlEndPoint(action) { -- cgit 1.2.3-korg