From 2f3aeb84a137a4826a3379c06083be38651a94cc Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Thu, 23 Mar 2017 09:56:10 +0000 Subject: [PATCH] disable add button when no valid ID is provided #1591 (#1747) * disable add button when no valid ID is provided #1591 * fix test --- .../src/components/tag-actions.component.html | 4 +- .../components/tag-actions.component.spec.ts | 84 +++++++++++++++++-- .../src/components/tag-actions.component.ts | 7 ++ 3 files changed, 87 insertions(+), 8 deletions(-) diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html index ba07f74574..3a00de8794 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.html @@ -13,7 +13,7 @@ {{errorMsg}} - @@ -33,7 +33,7 @@ {{errorMsg}} - diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts index 5c203504d7..f0354f17b6 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.spec.ts @@ -146,12 +146,25 @@ describe('Test ng2-alfresco-tag Tag actions list', () => { done(); }); - let addButton: any = element.querySelector('#add-tag'); - addButton.click(); + component.resultsEmitter.subscribe(() => { + fixture.detectChanges(); + + let addButton: any = element.querySelector('#add-tag'); + addButton.click(); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200 + }); + }); + + component.ngOnChanges(); jasmine.Ajax.requests.mostRecent().respondWith({ - status: 200 + status: 200, + contentType: 'json', + responseText: dataTag }); + }); it('The input box should be cleared after add tag', (done) => { @@ -165,11 +178,70 @@ describe('Test ng2-alfresco-tag Tag actions list', () => { done(); }); - let addButton: any = element.querySelector('#add-tag'); - addButton.click(); + component.resultsEmitter.subscribe(() => { + fixture.detectChanges(); + + let addButton: any = element.querySelector('#add-tag'); + addButton.click(); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200 + }); + }); + + component.ngOnChanges(); jasmine.Ajax.requests.mostRecent().respondWith({ - status: 200 + status: 200, + contentType: 'json', + responseText: dataTag + }); + }); + + it('Add tag should be disabled by default', (done) => { + component.nodeId = 'fake-node-id'; + component.newTagName = 'fake-tag-name'; + + let addButton: any = element.querySelector('#add-tag'); + expect(addButton.disabled).toEqual(true); + done(); + }); + + it('Add tag should be disabled if the node id is not a correct node', (done) => { + component.nodeId = 'fake-node-id'; + component.newTagName = 'fake-tag-name'; + + component.resultsEmitter.subscribe(() => { + let addButton: any = element.querySelector('#add-tag'); + expect(addButton.disabled).toEqual(true); + done(); + }); + + component.ngOnChanges(); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 404 + }); + }); + + it('Add tag should be enable if the node id is a correct node', (done) => { + component.nodeId = 'fake-node-id'; + component.newTagName = 'fake-tag-name'; + + component.resultsEmitter.subscribe(() => { + fixture.detectChanges(); + + let addButton: any = element.querySelector('#add-tag'); + expect(addButton.disabled).toEqual(false); + done(); + }); + + component.ngOnChanges(); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: dataTag }); }); }); diff --git a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts index 65880a2f33..a3ccbfbbb4 100644 --- a/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts +++ b/ng2-components/ng2-alfresco-tag/src/components/tag-actions.component.ts @@ -52,6 +52,8 @@ export class TagActionsComponent { errorMsg: string; + disableAddTag: boolean = true; + constructor(private tagService: TagService, private translateService: AlfrescoTranslationService) { if (translateService) { translateService.addTranslationFolder('ng2-alfresco-tag', 'node_modules/ng2-alfresco-tag/src'); @@ -65,6 +67,11 @@ export class TagActionsComponent { refreshTag() { this.tagService.getTagsByNodeId(this.nodeId).subscribe((data) => { this.tagsEntries = data.list.entries; + this.disableAddTag = false; + this.resultsEmitter.emit(this.tagsEntries); + }, () => { + this.tagsEntries = null; + this.disableAddTag = true; this.resultsEmitter.emit(this.tagsEntries); }); }