Skip to content

Commit

Permalink
* Fixed unit tests and added some * Updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
sivakumar414ram committed Nov 3, 2020
1 parent 10d268e commit 1e7b6aa
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Opens a [Content Node Selector](content-node-selector.component.md) in its own
| select | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<`[`Node`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/Node.md)`[]>` | Emitted when the user has chosen an item. |
| showingSearch | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<boolean>` | Emitted when search is running. |
| siteChange | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<string>` | Emitted when the select site changes. |
| currentFolder | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<`[`Node`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/Node.md)`[]>` | Emitted when current folder loaded. |

## Details

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy {
@Output()
showingSearch: EventEmitter<boolean> = new EventEmitter<boolean>();

/** Emitted when search is running. */
/** Emitted when current folder loaded. */
@Output()
currentFolder: EventEmitter<Node> = new EventEmitter<Node>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h2>{{title}}</h2>
<mat-icon>warning</mat-icon>
<span>{{ 'NODE_SELECTOR.UPLOAD_BUTTON_SEARCH_WARNING_MESSAGE' | translate }}</span>
</div>
<div class="adf-content-node-upload-button-warning-message" *ngIf="hasPermission">
<div class="adf-content-node-upload-button-warning-message" *ngIf="!hasAllowableOperations && !showingSearch">
<mat-icon>warning</mat-icon>
<span>{{ 'NODE_SELECTOR.UPLOAD_BUTTON_PERMISSION_WARNING_MESSAGE' | translate }}</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ describe('ContentNodeSelectorComponent', () => {
fixture = TestBed.createComponent(ContentNodeSelectorComponent);
component = fixture.componentInstance;
const contentService = TestBed.inject(ContentService);
spyOn(contentService, 'hasAllowableOperations').and.returnValue(false);
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
spyOn(contentService, 'getNode').and.returnValue(of(fakeFolderNodeWithPermission));

component.data.showLocalUploadButton = true;
component.hasAllowableOperations = true;
component.showingSearch = false;
fixture.detectChanges();
});

Expand Down Expand Up @@ -223,6 +226,8 @@ describe('ContentNodeSelectorComponent', () => {

it('should be able to disable UploadButton if showingSearch set to true', () => {
component.showingSearch = true;
component.hasAllowableOperations = true;

fixture.detectChanges();
const adfUploadButton = fixture.debugElement.query(By.css('adf-upload-button button'));

Expand All @@ -232,45 +237,78 @@ describe('ContentNodeSelectorComponent', () => {

it('should be able to enable UploadButton if showingSearch set to false', () => {
component.showingSearch = false;
component.hasAllowableOperations = true;

fixture.detectChanges();
const adfUploadButton = fixture.debugElement.query(By.css('adf-upload-button button'));

expect(adfUploadButton).not.toBeNull();
expect(adfUploadButton.nativeElement.disabled).toBe(false);
});

it('should be able to show warning message if showLocalUploadButton and showingSearch set to true', () => {
component.showingSearch = true;
it('should be able to show warning message while searching', () => {
component.data.showLocalUploadButton = true;
component.showingSearch = true;
component.hasAllowableOperations = false;

fixture.detectChanges();
const warnningMessage = fixture.debugElement.query(By.css('.adf-content-node-upload-button-warning-message span'));

expect(warnningMessage).not.toBeNull();
expect(warnningMessage.nativeElement.innerText).toEqual('NODE_SELECTOR.UPLOAD_BUTTON_SEARCH_WARNING_MESSAGE');
});

it('should not be able to show warning message if showLocalUploadButton set to false', () => {
component.data.showLocalUploadButton = false;
it('should not be able to show warning message if it is not in search mode', () => {
component.data.showLocalUploadButton = true;
component.showingSearch = false;
const warnningMessage = fixture.debugElement.query(By.css('.adf-content-node-upload-button-warning-message'));

fixture.detectChanges();
const warnningMessage = fixture.debugElement.query(By.css('.adf-content-node-upload-button-warning-message span'));

expect(warnningMessage).toBeNull();
});

it('should not be able to show warning message if disableUploadButton set to false', () => {
it('should be able to disable UploadButton if user does not have allowable operations', () => {
component.hasAllowableOperations = false;

fixture.detectChanges();
const adfUploadButton = fixture.debugElement.query(By.css('adf-upload-button button'));

expect(adfUploadButton).not.toBeNull();
expect(adfUploadButton.nativeElement.disabled).toBe(true);
});

it('should be able to enable UploadButton if user has allowable operations', () => {
component.hasAllowableOperations = true;

fixture.detectChanges();
const adfUploadButton = fixture.debugElement.query(By.css('adf-upload-button button'));

expect(adfUploadButton).not.toBeNull();
expect(adfUploadButton.nativeElement.disabled).toBe(false);
});

it('should not be able to show warning message if user has allowable operations', () => {
component.data.showLocalUploadButton = true;
component.hasAllowableOperations = true;
component.showingSearch = false;
const warnningMessage = fixture.debugElement.query(By.css('.adf-content-node-upload-button-warning-message'));

fixture.detectChanges();
const warnningMessage = fixture.debugElement.query(By.css('.adf-content-node-upload-button-warning-message span'));

expect(warnningMessage).toBeNull();
});

it('should not be able to show upload button if showLocalUploadButton set to false', () => {
component.data.showLocalUploadButton = false;
it('should be able to show warning message if user does not have allowable operations', () => {
component.data.showLocalUploadButton = true;
component.hasAllowableOperations = false;
component.showingSearch = false;

fixture.detectChanges();
const adfUploadButton = fixture.debugElement.query(By.css('adf-upload-button span'));
const warnningMessage = fixture.debugElement.query(By.css('.adf-content-node-upload-button-warning-message span'));

expect(adfUploadButton).toBeNull();
expect(warnningMessage).not.toBeNull();
expect(warnningMessage.nativeElement.innerText).toEqual('NODE_SELECTOR.UPLOAD_BUTTON_PERMISSION_WARNING_MESSAGE');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ContentNodeSelectorComponent {
chosenNode: Node[];
currentDirectoryId: string;
showingSearch = false;
hasPermission = false;
hasAllowableOperations = false;

constructor(private translation: TranslationService,
private contentService: ContentService,
Expand Down Expand Up @@ -92,14 +92,13 @@ export class ContentNodeSelectorComponent {

onShowingSearch(value: boolean) {
this.showingSearch = value;
this.hasPermission = false;
}

onCurrentFolder(currentFolder: Node) {
this.hasPermission = !this.contentService.hasAllowableOperations(currentFolder, AllowableOperationsEnum.CREATE);
this.hasAllowableOperations = this.contentService.hasAllowableOperations(currentFolder, AllowableOperationsEnum.CREATE);
}

isAllowedToUpload() {
return this.showingSearch || this.hasPermission;
return this.showingSearch || !this.hasAllowableOperations;
}
}

0 comments on commit 1e7b6aa

Please sign in to comment.