mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
improve code coverage
This commit is contained in:
@@ -43,7 +43,7 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
entry: {
|
entry: {
|
||||||
id: '123',
|
id: '123',
|
||||||
name: 'MyDoc',
|
name: 'MyDoc',
|
||||||
isFile : true,
|
isFile: true,
|
||||||
content: {
|
content: {
|
||||||
mimetype: 'text/plain'
|
mimetype: 'text/plain'
|
||||||
},
|
},
|
||||||
@@ -128,8 +128,8 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
|
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
alfrescoSearchComponentFixture.detectChanges();
|
||||||
expect( element.querySelector('#result_user_0').innerHTML).toBe('John Doe');
|
expect(element.querySelector('#result_user_0').innerHTML).toBe('John Doe');
|
||||||
expect( element.querySelector('#result_name_0').innerHTML).toBe('MyDoc');
|
expect(element.querySelector('#result_name_0').innerHTML).toBe('MyDoc');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
it('should display no result if no result are returned', (done) => {
|
it('should display no result if no result are returned', (done) => {
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
alfrescoSearchComponentFixture.detectChanges();
|
||||||
expect( element.querySelector('#search_no_result')).not.toBe(null);
|
expect(element.querySelector('#search_no_result')).not.toBe(null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -31,7 +31,7 @@ import { TAGCOMPONENT, TAGSERVICES } from 'ng2-alfresco-tag';
|
|||||||
@Component({
|
@Component({
|
||||||
selector: 'alfresco-tag-demo',
|
selector: 'alfresco-tag-demo',
|
||||||
template: `
|
template: `
|
||||||
<label for="ticket"><b>Insert a valid access ticket / ticket:</b></label><br>
|
<label for="ticket"><b>Insert a valid access ticket / ticket:</b></label><br>
|
||||||
<input id="ticket" type="text" size="48" (change)="updateTicket()" [(ngModel)]="ticket"><br>
|
<input id="ticket" type="text" size="48" (change)="updateTicket()" [(ngModel)]="ticket"><br>
|
||||||
<label for="host"><b>Insert the ip of your Alfresco instance:</b></label><br>
|
<label for="host"><b>Insert the ip of your Alfresco instance:</b></label><br>
|
||||||
<input id="host" type="text" size="48" (change)="updateHost()" [(ngModel)]="ecmHost"><br><br>
|
<input id="host" type="text" size="48" (change)="updateHost()" [(ngModel)]="ecmHost"><br><br>
|
||||||
@@ -40,7 +40,7 @@ import { TAGCOMPONENT, TAGSERVICES } from 'ng2-alfresco-tag';
|
|||||||
operations.
|
operations.
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<label for="nodeId"><b>Insert Node Id</b></label><br>
|
<label for="nodeId"><b>Insert Node Id</b></label><br>
|
||||||
<input id="nodeId" type="text" size="48" [(ngModel)]="nodeId"><br>
|
<input id="nodeId" type="text" size="48" [(ngModel)]="nodeId"><br>
|
||||||
<div class="container" *ngIf="authenticated">
|
<div class="container" *ngIf="authenticated">
|
||||||
<div class="mdl-grid">
|
<div class="mdl-grid">
|
||||||
@@ -50,10 +50,6 @@ import { TAGCOMPONENT, TAGSERVICES } from 'ng2-alfresco-tag';
|
|||||||
Tag list By Node ID
|
Tag list By Node ID
|
||||||
<alfresco-tag-node-list [nodeId]="nodeId"></alfresco-tag-node-list>
|
<alfresco-tag-node-list [nodeId]="nodeId"></alfresco-tag-node-list>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-cell mdl-cell--4-col">
|
|
||||||
Tag list By Node Properties
|
|
||||||
<alfresco-tag-node-list [properties]="propertiesDemo"></alfresco-tag-node-list>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
@@ -62,10 +58,8 @@ import { TAGCOMPONENT, TAGSERVICES } from 'ng2-alfresco-tag';
|
|||||||
})
|
})
|
||||||
class TagDemo implements OnInit {
|
class TagDemo implements OnInit {
|
||||||
|
|
||||||
propertiesDemo: string = '{"cm:taggable": ["008e722c-bf2a-4426-832c-29d1a9b174a8", "0350ff75-badb-40e5-b7de-1091a855dd70"]}';
|
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
nodeId: string = '1a0b110f-1e09-4ca2-b367-fe25e4964a4e';
|
nodeId: string = '74cd8a96-8a21-47e5-9b3b-a1b3e296787d';
|
||||||
|
|
||||||
currentPath: string = '/';
|
currentPath: string = '/';
|
||||||
|
|
||||||
|
@@ -1,39 +1,36 @@
|
|||||||
<!--isContextMenu-->
|
<!--isContextMenu-->
|
||||||
<div *ngIf="isContextMenu">
|
<div *ngIf="isContextMenu">
|
||||||
<li class="mdl-menu__item" *ngFor="let currentEntry of tagsEntries">
|
<li class="mdl-menu__item" *ngFor="let currentEntry of tagsEntries; let idx = index">
|
||||||
<span class="mdl-list__item-primary-content">
|
<span id="tag_name_{{idx}}" class="mdl-list__item-primary-content">
|
||||||
{{currentEntry.entry.tag}}
|
{{currentEntry.entry.tag}}
|
||||||
</span>
|
</span>
|
||||||
<span class="mdl-list__item-secondary-action">
|
<div id="tag_delete_{{idx}}" class="mdl-list__item-secondary-action" (click)="removeTag(currentEntry.entry.id)">
|
||||||
<i class="material-icons" (click)="removeTag(currentEntry.entry.id)">delete</i>
|
<i class="material-icons">delete</i>
|
||||||
</span>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<div class="mdl-textfield mdl-js-textfield tag-container-input">
|
<div class="mdl-textfield mdl-js-textfield tag-container-input">
|
||||||
<input class="mdl-textfield__input tag-input" type="tag" id="new-tag-text" [(ngModel)]="newTagName"/>
|
<input class="mdl-textfield__input tag-input" type="tag" id="new-tag-text" [(ngModel)]="newTagName"/>
|
||||||
</div>
|
</div>
|
||||||
<button class="mdl-button mdl-js-button mdl-button--raised button" (click)="addTag()">
|
<button id="add-tag" class="mdl-button mdl-js-button mdl-button--raised button" (click)="addTag()">
|
||||||
Add tag
|
Add tag
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--not ContextMenu-->
|
<!--not ContextMenu-->
|
||||||
|
<ul *ngIf="!isContextMenu" class="tag-list-control mdl-list">
|
||||||
<ul *ngIf="!isContextMenu" class="mdl-menu--bottom-right">
|
<li class="mdl-list__item tag-element" *ngFor="let currentEntry of tagsEntries; let idx = index">
|
||||||
<li class="mdl-menu__item" *ngFor="let currentEntry of tagsEntries">
|
<span id="tag_name_{{idx}}" class="mdl-list__item-primary-content">{{currentEntry.entry.tag}}</span>
|
||||||
<span class="mdl-list__item-primary-content">
|
<div id="tag_delete_{{idx}}" class="mdl-list__item-secondary-action" (click)="removeTag(currentEntry.entry.id)">
|
||||||
{{currentEntry.entry.tag}}
|
<i class="material-icons">delete</i>
|
||||||
</span>
|
</div>
|
||||||
<span class="mdl-list__item-secondary-action">
|
|
||||||
<i class="material-icons" (click)="removeTag(currentEntry.entry.id)">delete</i>
|
|
||||||
</span>
|
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<div class="mdl-textfield mdl-js-textfield tag-container-input">
|
<div class="mdl-textfield mdl-js-textfield tag-container-input">
|
||||||
<input class="mdl-textfield__input tag-input" type="tag" id="new-tag-text" [(ngModel)]="newTagName"/>
|
<input class="mdl-textfield__input tag-input" type="tag" id="new-tag-text" [(ngModel)]="newTagName"/>
|
||||||
</div>
|
</div>
|
||||||
<button class="mdl-button mdl-js-button mdl-button--raised button" (click)="addTag()">
|
<button id="add-tag" class="mdl-button mdl-js-button mdl-button--raised button" (click)="addTag()">
|
||||||
Add tag
|
Add tag
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
@@ -16,18 +16,36 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import { describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing';
|
import { it, describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing';
|
||||||
|
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||||
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||||
import { TagService } from '../services/tag.service';
|
import { TagService } from '../services/tag.service';
|
||||||
|
import { TagActionsComponent } from './tag-actions.component';
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
describe('Tag actions', () => {
|
describe('Tag actions list', () => {
|
||||||
|
|
||||||
let service;
|
let tagActionsListFixture, element, component;
|
||||||
|
|
||||||
|
let dataTag = {
|
||||||
|
'list': {
|
||||||
|
'pagination': {
|
||||||
|
'count': 3,
|
||||||
|
'hasMoreItems': false,
|
||||||
|
'totalItems': 3,
|
||||||
|
'skipCount': 0,
|
||||||
|
'maxItems': 100
|
||||||
|
},
|
||||||
|
'entries': [{
|
||||||
|
'entry': {'tag': 'test1', 'id': '0ee933fa-57fc-4587-8a77-b787e814f1d2'}
|
||||||
|
}, {'entry': {'tag': 'test2', 'id': 'fcb92659-1f10-41b4-9b17-851b72a3b597'}}, {
|
||||||
|
'entry': {'tag': 'test3', 'id': 'fb4213c0-729d-466c-9a6c-ee2e937273bf'}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
beforeEachProviders(() => {
|
beforeEachProviders(() => {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
@@ -35,11 +53,17 @@ describe('Tag actions', () => {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(inject([TagService], (tagService: TagService) => {
|
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||||
service = tagService;
|
return tcb
|
||||||
|
.createAsync(TagActionsComponent)
|
||||||
|
.then(fixture => {
|
||||||
|
tagActionsListFixture = fixture;
|
||||||
|
element = tagActionsListFixture.nativeElement;
|
||||||
|
component = tagActionsListFixture.componentInstance;
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('Content tests', () => {
|
describe('Rendering tests', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jasmine.Ajax.install();
|
jasmine.Ajax.install();
|
||||||
@@ -49,5 +73,70 @@ describe('Tag actions', () => {
|
|||||||
jasmine.Ajax.uninstall();
|
jasmine.Ajax.uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Tag list relative a single node should be rendered', (done) => {
|
||||||
|
component.nodeId = 'fake-node-id';
|
||||||
|
|
||||||
|
component.resultsEmitter.subscribe(() => {
|
||||||
|
tagActionsListFixture.detectChanges();
|
||||||
|
|
||||||
|
expect(element.querySelector('#tag_name_0').innerHTML).toBe('test1');
|
||||||
|
expect(element.querySelector('#tag_name_1').innerHTML).toBe('test2');
|
||||||
|
expect(element.querySelector('#tag_name_2').innerHTML).toBe('test3');
|
||||||
|
|
||||||
|
expect(element.querySelector('#tag_delete_0')).not.toBe(null);
|
||||||
|
expect(element.querySelector('#tag_delete_1')).not.toBe(null);
|
||||||
|
expect(element.querySelector('#tag_delete_2')).not.toBe(null);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges();
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: dataTag
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Tag list click on delete button should delete the tag', (done) => {
|
||||||
|
component.nodeId = 'fake-node-id';
|
||||||
|
|
||||||
|
component.resultsEmitter.subscribe(() => {
|
||||||
|
tagActionsListFixture.detectChanges();
|
||||||
|
element.querySelector('#tag_delete_0').click();
|
||||||
|
tagActionsListFixture.detectChanges();
|
||||||
|
|
||||||
|
expect(jasmine.Ajax.requests.at(1).url).
|
||||||
|
toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/tags/0ee933fa-57fc-4587-8a77-b787e814f1d2');
|
||||||
|
expect(jasmine.Ajax.requests.at(1).method).toBe('DELETE');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges();
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: dataTag
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Add tag', (done) => {
|
||||||
|
component.nodeId = 'fake-node-id';
|
||||||
|
component.newTagName = 'fake-tag-name';
|
||||||
|
|
||||||
|
tagActionsListFixture.detectChanges();
|
||||||
|
|
||||||
|
component.addEmitter.subscribe(() => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
element.querySelector('#add-tag').click();
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -15,9 +15,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
||||||
import {AlfrescoAuthenticationService} from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||||
import {TagService} from '../services/tag.service';
|
import { TagService } from '../services/tag.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -42,7 +42,10 @@ export class TagActionsComponent {
|
|||||||
isContextMenu: boolean = false;
|
isContextMenu: boolean = false;
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
onSuccess: EventEmitter<any> = new EventEmitter();
|
addEmitter: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
|
@Output()
|
||||||
|
resultsEmitter = new EventEmitter();
|
||||||
|
|
||||||
newTagName: string;
|
newTagName: string;
|
||||||
|
|
||||||
@@ -61,20 +64,21 @@ export class TagActionsComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refreshTag() {
|
refreshTag() {
|
||||||
this.tagService.getTagsByNodeId(this.nodeId).then((data) => {
|
this.tagService.getTagsByNodeId(this.nodeId).subscribe((data) => {
|
||||||
this.tagsEntries = data;
|
this.tagsEntries = data.list.entries;
|
||||||
|
this.resultsEmitter.emit(this.tagsEntries);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addTag() {
|
addTag() {
|
||||||
this.tagService.addTag(this.nodeId, this.newTagName).then((res) => {
|
this.tagService.addTag(this.nodeId, this.newTagName).subscribe((res) => {
|
||||||
this.refreshTag();
|
this.refreshTag();
|
||||||
this.onSuccess.emit(res.entry.id);
|
this.addEmitter.emit(this.nodeId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTag(tag: string) {
|
removeTag(tag: string) {
|
||||||
this.tagService.removeTag(this.nodeId, tag).then(() => {
|
this.tagService.removeTag(this.nodeId, tag).subscribe(() => {
|
||||||
this.refreshTag();
|
this.refreshTag();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,8 @@
|
|||||||
<div class="tag-container">
|
<div class="tag-container">
|
||||||
<div id="table-cards-container">
|
<div id="table-cards-container">
|
||||||
<ul class="tag-list-control mdl-list">
|
<ul class="tag-list-control mdl-list">
|
||||||
<li class="mdl-list__item tag-element" *ngFor="let currentEntry of tagsEntries">
|
<li class="mdl-list__item tag-element" *ngFor="let currentEntry of tagsEntries; let idx = index">
|
||||||
<span class="mdl-list__item-primary-content">
|
<span id="tag_name_{{idx}}" class="mdl-list__item-primary-content">{{currentEntry.entry.tag}}</span>
|
||||||
{{currentEntry.entry.tag}}
|
|
||||||
</span>
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -16,18 +16,35 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import { describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing';
|
import { it, describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing';
|
||||||
|
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||||
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||||
import { TagService } from '../services/tag.service';
|
import { TagService } from '../services/tag.service';
|
||||||
|
import { TagList } from './tag-list.component';
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
describe('Tag list', () => {
|
describe('Tag list All ECM', () => {
|
||||||
|
|
||||||
let service;
|
let tagListFixture, element, component;
|
||||||
|
|
||||||
|
let dataTag = {
|
||||||
|
'list': {
|
||||||
|
'pagination': {
|
||||||
|
'count': 3,
|
||||||
|
'hasMoreItems': false,
|
||||||
|
'totalItems': 3,
|
||||||
|
'skipCount': 0,
|
||||||
|
'maxItems': 100
|
||||||
|
},
|
||||||
|
'entries': [{
|
||||||
|
'entry': {'tag': 'test1', 'id': '0ee933fa-57fc-4587-8a77-b787e814f1d2'}
|
||||||
|
}, {'entry': {'tag': 'test2', 'id': 'fcb92659-1f10-41b4-9b17-851b72a3b597'}}, {
|
||||||
|
'entry': {'tag': 'test3', 'id': 'fb4213c0-729d-466c-9a6c-ee2e937273bf'}}]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
beforeEachProviders(() => {
|
beforeEachProviders(() => {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
@@ -35,11 +52,17 @@ describe('Tag list', () => {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(inject([TagService], (tagService: TagService) => {
|
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||||
service = tagService;
|
return tcb
|
||||||
|
.createAsync(TagList)
|
||||||
|
.then(fixture => {
|
||||||
|
tagListFixture = fixture;
|
||||||
|
element = tagListFixture.nativeElement;
|
||||||
|
component = tagListFixture.componentInstance;
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('Content tests', () => {
|
describe('Rendering tests', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jasmine.Ajax.install();
|
jasmine.Ajax.install();
|
||||||
@@ -49,5 +72,26 @@ describe('Tag list', () => {
|
|||||||
jasmine.Ajax.uninstall();
|
jasmine.Ajax.uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Tag list relative a single node should be rendered', (done) => {
|
||||||
|
component.nodeId = 'fake-node-id';
|
||||||
|
|
||||||
|
component.resultsEmitter.subscribe(() => {
|
||||||
|
tagListFixture.detectChanges();
|
||||||
|
|
||||||
|
expect(element.querySelector('#tag_name_0').innerHTML).toBe('test1');
|
||||||
|
expect(element.querySelector('#tag_name_1').innerHTML).toBe('test2');
|
||||||
|
expect(element.querySelector('#tag_name_2').innerHTML).toBe('test3');
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnInit();
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: dataTag
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -15,9 +15,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Component, Input} from '@angular/core';
|
import { Component, Output, EventEmitter } from '@angular/core';
|
||||||
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||||
import { TagService} from '../services/tag.service';
|
import { TagService } from '../services/tag.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -30,16 +30,14 @@ declare let __moduleName: string;
|
|||||||
@Component({
|
@Component({
|
||||||
moduleId: __moduleName,
|
moduleId: __moduleName,
|
||||||
selector: 'alfresco-tag-list',
|
selector: 'alfresco-tag-list',
|
||||||
templateUrl: './tag-list.component.html',
|
templateUrl: './tag-list.component.html'
|
||||||
styleUrls: ['./tag.component.css']
|
|
||||||
|
|
||||||
})
|
})
|
||||||
export class TagList {
|
export class TagList {
|
||||||
|
|
||||||
tagsEntries: any;
|
tagsEntries: any;
|
||||||
|
|
||||||
@Input()
|
@Output()
|
||||||
tagUlId: string = 'tg-id';
|
resultsEmitter = new EventEmitter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@@ -55,7 +53,8 @@ export class TagList {
|
|||||||
|
|
||||||
refreshTagEcm() {
|
refreshTagEcm() {
|
||||||
this.tagService.getAllTheTags().subscribe((data) => {
|
this.tagService.getAllTheTags().subscribe((data) => {
|
||||||
this.tagsEntries = data;
|
this.tagsEntries = data.list.entries;
|
||||||
|
this.resultsEmitter.emit(this.tagsEntries);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
<div class="tag-list-container">
|
<div class="tag-list-container">
|
||||||
<ul class="tags">
|
<ul class="tags">
|
||||||
<li *ngFor="let currentEntry of tagsEntries">
|
<li *ngFor="let currentEntry of tagsEntries; let idx = index">
|
||||||
<a href="#" class="tag-name">{{currentEntry.entry.tag}}</a>
|
<div id="tag_name_{{idx}}" class="tag-name">{{currentEntry.entry.tag}}</div>
|
||||||
<div class="tag-delete" (click)="removeTag(currentEntry.entry.id)" ><i class="material-icons delete-icon">close</i></div>
|
<div id="tag_delete_{{idx}}" class="tag-delete" (click)="removeTag(currentEntry.entry.id)" ><i class="material-icons delete-icon">close</i></div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -16,18 +16,35 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import { describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing';
|
import { it, describe, inject, beforeEachProviders, beforeEach, afterEach } from '@angular/core/testing';
|
||||||
|
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||||
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||||
import { TagService } from '../services/tag.service';
|
import { TagService } from '../services/tag.service';
|
||||||
|
import { TagNodeList } from './tag-node-list.component';
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
describe('Tag relative node list', () => {
|
describe('Tag relative node list', () => {
|
||||||
|
|
||||||
let service;
|
let tagNodeListFixture, element, component;
|
||||||
|
|
||||||
|
let dataTag = {
|
||||||
|
'list': {
|
||||||
|
'pagination': {
|
||||||
|
'count': 3,
|
||||||
|
'hasMoreItems': false,
|
||||||
|
'totalItems': 3,
|
||||||
|
'skipCount': 0,
|
||||||
|
'maxItems': 100
|
||||||
|
},
|
||||||
|
'entries': [{
|
||||||
|
'entry': {'tag': 'test1', 'id': '0ee933fa-57fc-4587-8a77-b787e814f1d2'}
|
||||||
|
}, {'entry': {'tag': 'test2', 'id': 'fcb92659-1f10-41b4-9b17-851b72a3b597'}}, {
|
||||||
|
'entry': {'tag': 'test3', 'id': 'fb4213c0-729d-466c-9a6c-ee2e937273bf'}}]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
beforeEachProviders(() => {
|
beforeEachProviders(() => {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
@@ -35,7 +52,17 @@ describe('Tag relative node list', () => {
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Content tests', () => {
|
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||||
|
return tcb
|
||||||
|
.createAsync(TagNodeList)
|
||||||
|
.then(fixture => {
|
||||||
|
tagNodeListFixture = fixture;
|
||||||
|
element = tagNodeListFixture.nativeElement;
|
||||||
|
component = tagNodeListFixture.componentInstance;
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('Rendering tests', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jasmine.Ajax.install();
|
jasmine.Ajax.install();
|
||||||
@@ -45,16 +72,52 @@ describe('Tag relative node list', () => {
|
|||||||
jasmine.Ajax.uninstall();
|
jasmine.Ajax.uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getTagsByNodeId catch errors call', (done) => {
|
it('Tag list relative a single node should be rendered', (done) => {
|
||||||
service.getTagsByNodeId('fake-node-id', 'fake-tag').subscribe(() => {
|
component.nodeId = 'fake-node-id';
|
||||||
}, () => {
|
|
||||||
|
component.resultsEmitter.subscribe(() => {
|
||||||
|
tagNodeListFixture.detectChanges();
|
||||||
|
|
||||||
|
expect(element.querySelector('#tag_name_0').innerHTML).toBe('test1');
|
||||||
|
expect(element.querySelector('#tag_name_1').innerHTML).toBe('test2');
|
||||||
|
expect(element.querySelector('#tag_name_2').innerHTML).toBe('test3');
|
||||||
|
|
||||||
|
expect(element.querySelector('#tag_delete_0')).not.toBe(null);
|
||||||
|
expect(element.querySelector('#tag_delete_1')).not.toBe(null);
|
||||||
|
expect(element.querySelector('#tag_delete_2')).not.toBe(null);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges();
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
status: 403
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: dataTag
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Tag list click on delete button should delete the tag', (done) => {
|
||||||
|
component.nodeId = 'fake-node-id';
|
||||||
|
|
||||||
|
component.resultsEmitter.subscribe(() => {
|
||||||
|
tagNodeListFixture.detectChanges();
|
||||||
|
element.querySelector('#tag_delete_0').click();
|
||||||
|
|
||||||
|
expect(jasmine.Ajax.requests.mostRecent().url).
|
||||||
|
toBe('http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/tags/0ee933fa-57fc-4587-8a77-b787e814f1d2');
|
||||||
|
expect(jasmine.Ajax.requests.mostRecent().method).toBe('DELETE');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges();
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: dataTag
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
||||||
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||||
import { TagService } from '../services/tag.service';
|
import { TagService } from '../services/tag.service';
|
||||||
|
|
||||||
@@ -40,6 +40,9 @@ export class TagNodeList {
|
|||||||
|
|
||||||
tagsEntries: any;
|
tagsEntries: any;
|
||||||
|
|
||||||
|
@Output()
|
||||||
|
resultsEmitter = new EventEmitter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param authService
|
* @param authService
|
||||||
@@ -52,13 +55,14 @@ export class TagNodeList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refreshTag() {
|
refreshTag() {
|
||||||
this.tagService.getTagsByNodeId(this.nodeId).then((data) => {
|
this.tagService.getTagsByNodeId(this.nodeId).subscribe((data) => {
|
||||||
this.tagsEntries = data;
|
this.tagsEntries = data.list.entries;
|
||||||
|
this.resultsEmitter.emit(this.tagsEntries);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTag(tag: string) {
|
removeTag(tag: string) {
|
||||||
this.tagService.removeTag(this.nodeId, tag).then(() => {
|
this.tagService.removeTag(this.nodeId, tag).subscribe(() => {
|
||||||
this.refreshTag();
|
this.refreshTag();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -18,8 +18,7 @@
|
|||||||
import { describe, expect, it, inject, beforeEachProviders, beforeEach, afterEach, xit } from '@angular/core/testing';
|
import { describe, expect, it, inject, beforeEachProviders, beforeEach, afterEach, xit } from '@angular/core/testing';
|
||||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||||
import { WebscriptComponent } from '../src/webscript.component';
|
import { WebscriptComponent } from '../src/webscript.component';
|
||||||
|
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||||
import { AlfrescoAuthenticationService, AlfrescoSettingsService, AlfrescoApiService } from 'ng2-alfresco-core';
|
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user