Skip to content

Commit

Permalink
* Refactored names
Browse files Browse the repository at this point in the history
  • Loading branch information
sivakumar414ram committed Nov 3, 2020
1 parent 4645f1a commit 10d268e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ <h2>{{title}}</h2>
[staticTitle]="'FORM.FIELD.UPLOAD' | translate "
[multipleFiles]="isMultipleSelection()"
[rootFolderId]="currentDirectoryId"
[disabled]="disableUploadButton || isAllowedToUploadFiles"
[disabled]="isAllowedToUpload()"
(error)="onError($event)">
</adf-upload-button>
<ng-container>
<div class="adf-content-node-upload-button-warning-message" *ngIf="disableUploadButton">
<div class="adf-content-node-upload-button-warning-message" *ngIf="showingSearch">
<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="isAllowedToUploadFiles">
<div class="adf-content-node-upload-button-warning-message" *ngIf="hasPermission">
<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 @@ -34,6 +34,7 @@

.mat-dialog-actions {
padding: 8px;
height: 61px;
background-color: mat-color($background, background);
display: flex;
flex-direction: row;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { CUSTOM_ELEMENTS_SCHEMA, EventEmitter } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ContentNodeSelectorComponent } from './content-node-selector.component';
import { Node } from '@alfresco/js-api';
import { ContentNodeSelectorPanelComponent } from '@alfresco/adf-content-services';
import { Node, NodeEntry } from '@alfresco/js-api';
import { ContentNodeSelectorPanelComponent, UploadModule } from '@alfresco/adf-content-services';
import { By } from '@angular/platform-browser';
import { setupTestBed, SitesService } from '@alfresco/adf-core';
import { setupTestBed, SitesService, ContentService } from '@alfresco/adf-core';
import { of } from 'rxjs';
import { ContentTestingModule } from '../testing/content.testing.module';
import { DocumentListService } from '../document-list/services/document-list.service';
Expand All @@ -41,13 +41,27 @@ describe('ContentNodeSelectorComponent', () => {
rowFilter: (shareDataRow: ShareDataRow) => shareDataRow.node.entry.name === 'impossible-name',
imageResolver: () => 'piccolo',
currentFolderId: 'cat-girl-nuku-nuku',
selectionMode: 'multiple',
showLocalUploadButton: true
};

const fakeFolderNodeWithPermission = new NodeEntry({
entry: {
allowableOperations: [
'create',
'update'
],
isFolder: true,
name: 'Folder Fake Name',
nodeType: 'cm:folder'
}
});

setupTestBed({
imports: [
TranslateModule.forRoot(),
ContentTestingModule
ContentTestingModule,
UploadModule
],
providers: [
{ provide: MAT_DIALOG_DATA, useValue: data }
Expand All @@ -58,18 +72,23 @@ describe('ContentNodeSelectorComponent', () => {
beforeEach(() => {
const documentListService: DocumentListService = TestBed.inject(DocumentListService);
const sitesService: SitesService = TestBed.inject(SitesService);

spyOn(documentListService, 'getFolder').and.returnValue(of({ list: [] }));
spyOn(documentListService, 'getFolderNode').and.returnValue(of({ entry: {} }));
spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } }));

fixture = TestBed.createComponent(ContentNodeSelectorComponent);
component = fixture.componentInstance;
const contentService = TestBed.inject(ContentService);
spyOn(contentService, 'hasAllowableOperations').and.returnValue(false);
spyOn(contentService, 'getNode').and.returnValue(of(fakeFolderNodeWithPermission));

fixture.detectChanges();
});

afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});

describe('Data injecting with the "Material dialog way"', () => {
Expand Down Expand Up @@ -202,26 +221,26 @@ describe('ContentNodeSelectorComponent', () => {
expect(adfUploadButton.nativeElement.innerText).toEqual('file_uploadFORM.FIELD.UPLOAD');
});

it('should be able to disable UploadButton if disableUploadButton set to true', () => {
component.disableUploadButton = true;
it('should be able to disable UploadButton if showingSearch set to true', () => {
component.showingSearch = true;
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 disableUploadButton set to false', () => {
component.disableUploadButton = false;
it('should be able to enable UploadButton if showingSearch set to false', () => {
component.showingSearch = false;
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 disableUploadButton set to true', () => {
component.disableUploadButton = true;
it('should be able to show warning message if showLocalUploadButton and showingSearch set to true', () => {
component.showingSearch = true;
component.data.showLocalUploadButton = true;
fixture.detectChanges();
const warnningMessage = fixture.debugElement.query(By.css('.adf-content-node-upload-button-warning-message span'));
Expand All @@ -232,15 +251,15 @@ describe('ContentNodeSelectorComponent', () => {

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

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

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

expect(warnningMessage).toBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ export class ContentNodeSelectorComponent {
buttonActionName: string;
chosenNode: Node[];
currentDirectoryId: string;
disableUploadButton = false;
isAllowedToUploadFiles = false;
currentFolder: any;
showingSearch = false;
hasPermission = false;

constructor(private translation: TranslationService,
private contentService: ContentService,
Expand Down Expand Up @@ -92,12 +91,15 @@ export class ContentNodeSelectorComponent {
}

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

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

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

0 comments on commit 10d268e

Please sign in to comment.