[ACS-5645] added unit test cases

This commit is contained in:
Yasa-Nataliya
2023-09-18 12:45:01 +05:30
parent 5121ad09c0
commit 341d7c41e2
7 changed files with 95 additions and 4 deletions

View File

@@ -1261,7 +1261,7 @@
"click": "EXPAND_INFO_DRAWER" "click": "EXPAND_INFO_DRAWER"
}, },
"rules": { "rules": {
"visible": "canNotShowExpand" "visible": "canShowExpand"
} }
} }
], ],

View File

@@ -192,7 +192,7 @@ export class ContentServiceExtensionModule {
canToggleFavorite: rules.canToggleFavorite, canToggleFavorite: rules.canToggleFavorite,
isLibraryManager: rules.isLibraryManager, isLibraryManager: rules.isLibraryManager,
canEditAspects: rules.canEditAspects, canEditAspects: rules.canEditAspects,
canNotShowExpand: rules.canNotShowExpand, canShowExpand: rules.canShowExpand,
canInfoPreview: rules.canInfoPreview, canInfoPreview: rules.canInfoPreview,
showInfoSelectionButton: rules.showInfoSelectionButton, showInfoSelectionButton: rules.showInfoSelectionButton,

View File

@@ -26,7 +26,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppTestingModule } from '../../testing/app-testing.module'; import { AppTestingModule } from '../../testing/app-testing.module';
import { DetailsComponent } from './details.component'; import { DetailsComponent } from './details.component';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { of, Subject } from 'rxjs'; import { BehaviorSubject, of, Subject } from 'rxjs';
import { NO_ERRORS_SCHEMA } from '@angular/core'; import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { ContentApiService } from '@alfresco/aca-shared'; import { ContentApiService } from '@alfresco/aca-shared';
@@ -49,6 +49,16 @@ describe('DetailsComponent', () => {
select: () => mockStream select: () => mockStream
}; };
const extensionsServiceMock = {
getAllowedSidebarActions: jasmine.createSpy('getAllowedSidebarActions')
};
const mockAspectActions = [];
// Mock the observable returned by getAllowedSidebarActions
const mockObservable = new BehaviorSubject(mockAspectActions);
extensionsServiceMock.getAllowedSidebarActions.and.returnValue(mockObservable);
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [AppTestingModule, DetailsComponent], imports: [AppTestingModule, DetailsComponent],
@@ -128,4 +138,12 @@ describe('DetailsComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([node])); expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([node]));
}); });
it('should set aspectActions from extensions', () => {
extensionsServiceMock.getAllowedSidebarActions.and.returnValue(of(mockAspectActions));
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.aspectActions).toEqual(mockAspectActions);
});
});
}); });

View File

@@ -29,6 +29,7 @@ import { Store } from '@ngrx/store';
import { NodeEntry } from '@alfresco/js-api'; import { NodeEntry } from '@alfresco/js-api';
import { DownloadNodesAction, EditOfflineAction, SnackbarErrorAction } from '@alfresco/aca-shared/store'; import { DownloadNodesAction, EditOfflineAction, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { AppTestingModule } from '../../../testing/app-testing.module'; import { AppTestingModule } from '../../../testing/app-testing.module';
import { AppExtensionService } from '@alfresco/aca-shared';
describe('ToggleEditOfflineComponent', () => { describe('ToggleEditOfflineComponent', () => {
let fixture: ComponentFixture<ToggleEditOfflineComponent>; let fixture: ComponentFixture<ToggleEditOfflineComponent>;
@@ -38,6 +39,10 @@ describe('ToggleEditOfflineComponent', () => {
let selectSpy: jasmine.Spy; let selectSpy: jasmine.Spy;
let selection: any; let selection: any;
const extensionsMock = {
updateSidebarActions: jasmine.createSpy('updateSidebarActions')
};
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [AppTestingModule, ToggleEditOfflineComponent], imports: [AppTestingModule, ToggleEditOfflineComponent],
@@ -48,6 +53,10 @@ describe('ToggleEditOfflineComponent', () => {
select: () => {}, select: () => {},
dispatch: () => {} dispatch: () => {}
} }
},
{
provide: AppExtensionService,
useValue: extensionsMock
} }
] ]
}); });
@@ -133,4 +142,14 @@ describe('ToggleEditOfflineComponent', () => {
}) })
]); ]);
}); });
it('should call updateSidebarActions on click', async () => {
selectSpy.and.returnValue(of(selection));
fixture.detectChanges();
await component.onClick();
fixture.detectChanges();
expect(extensionsMock.updateSidebarActions).toHaveBeenCalled();
});
}); });

View File

@@ -121,6 +121,28 @@ describe('app.evaluators', () => {
}); });
}); });
describe('canShowExpand', () => {
it('should return false when isLibraries returns true', () => {
const context: any = {
navigation: {
url: '/libraries'
}
};
expect(app.canShowExpand(context)).toBe(false);
});
it('should return false when isDetails returns true', () => {
const context: any = {
navigation: {
url: '/details'
}
};
expect(app.canShowExpand(context)).toBe(false);
});
});
describe('hasLockedFiles', () => { describe('hasLockedFiles', () => {
it('should return [false] if selection not present', () => { it('should return [false] if selection not present', () => {
const context: any = {}; const context: any = {};

View File

@@ -511,7 +511,7 @@ export const canEditAspects = (context: RuleContext): boolean =>
repository.isMajorVersionAvailable(context, '7') repository.isMajorVersionAvailable(context, '7')
].every(Boolean); ].every(Boolean);
export const canNotShowExpand = (context: RuleContext): boolean => [!navigation.isLibraries(context), !navigation.isDetails(context)].every(Boolean); export const canShowExpand = (context: RuleContext): boolean => [!navigation.isLibraries(context), !navigation.isDetails(context)].every(Boolean);
/** /**
* Checks if user can manage permissions for the selected node. * Checks if user can manage permissions for the selected node.

View File

@@ -225,6 +225,38 @@ describe('navigation.evaluators', () => {
}); });
}); });
describe('isDetails', () => {
it('should return [true] if url ends with `/details`', () => {
const context: any = {
navigation: {
url: '/path/details'
}
};
expect(app.isDetails(context)).toBe(true);
});
it('should return [true] if url starts with `/details`', () => {
const context: any = {
navigation: {
url: '/details/path'
}
};
expect(app.isDetails(context)).toBe(true);
});
it('should return [true] if url includes with `/details`', () => {
const context: any = {
navigation: {
url: '/details/path'
}
};
expect(app.isDetails(context)).toBe(true);
});
});
describe('isRecentFiles', () => { describe('isRecentFiles', () => {
it('should return [true] if url starts with `/recent-files`', () => { it('should return [true] if url starts with `/recent-files`', () => {
const context: any = { const context: any = {