[ACS-5540]fixed unit test cases and added unit test cases

This commit is contained in:
Yasa-Nataliya
2023-09-01 15:09:42 +05:30
parent 6a7f8b5b65
commit 3e435be1d0
2 changed files with 18 additions and 4 deletions

View File

@@ -31,10 +31,10 @@ 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';
import { STORE_INITIAL_APP_DATA, SetSelectedNodesAction } from '@alfresco/aca-shared/store'; import { STORE_INITIAL_APP_DATA, SetSelectedNodesAction } from '@alfresco/aca-shared/store';
import { NodeEntry } from '@alfresco/js-api'; import { MinimalNodeEntryEntity, NodeEntry } from '@alfresco/js-api';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { AuthenticationService, PageTitleService } from '@alfresco/adf-core'; import { AuthenticationService, PageTitleService } from '@alfresco/adf-core';
import { SearchQueryBuilderService } from '@alfresco/adf-content-services'; import { NodeAspectService, SearchQueryBuilderService } from '@alfresco/adf-content-services';
describe('DetailsComponent', () => { describe('DetailsComponent', () => {
let component: DetailsComponent; let component: DetailsComponent;
@@ -42,6 +42,7 @@ describe('DetailsComponent', () => {
let contentApiService: ContentApiService; let contentApiService: ContentApiService;
let store: Store; let store: Store;
let node: NodeEntry; let node: NodeEntry;
let mockNodeAspectService: jasmine.SpyObj<NodeAspectService>;
const mockStream = new Subject(); const mockStream = new Subject();
const storeMock = { const storeMock = {
@@ -50,6 +51,7 @@ describe('DetailsComponent', () => {
}; };
beforeEach(() => { beforeEach(() => {
const nodeAspectServiceSpy = jasmine.createSpyObj('NodeAspectService', ['updateNodeAspects']);
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [AppTestingModule, DetailsComponent], imports: [AppTestingModule, DetailsComponent],
providers: [ providers: [
@@ -78,6 +80,10 @@ describe('DetailsComponent', () => {
onLogout: new Subject<any>(), onLogout: new Subject<any>(),
isLoggedIn: () => true isLoggedIn: () => true
} }
},
{
provide: NodeAspectService,
useValue: nodeAspectServiceSpy
} }
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
@@ -86,6 +92,8 @@ describe('DetailsComponent', () => {
fixture = TestBed.createComponent(DetailsComponent); fixture = TestBed.createComponent(DetailsComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
contentApiService = TestBed.inject(ContentApiService); contentApiService = TestBed.inject(ContentApiService);
mockNodeAspectService = TestBed.inject(NodeAspectService) as jasmine.SpyObj<NodeAspectService>;
component.node = { id: 'test-id' } as MinimalNodeEntryEntity;
store = TestBed.inject(Store); store = TestBed.inject(Store);
node = { node = {
@@ -128,4 +136,10 @@ describe('DetailsComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([node])); expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([node]));
}); });
it('should call openAspectDialog and updateNodeAspects when the button is clicked', () => {
component.openAspectDialog();
fixture.detectChanges();
expect(mockNodeAspectService.updateNodeAspects).toHaveBeenCalledWith('test-id');
});
}); });

View File

@@ -256,7 +256,7 @@ describe('MetadataTabComponent', () => {
}); });
it('show pass empty when store is in initial state', () => { it('show pass empty when store is in initial state', () => {
const initialState = fixture.debugElement.query(By.css('adf-content-metadata-card')); const initialState = fixture.debugElement.query(By.css('adf-content-metadata'));
expect(initialState.componentInstance.displayAspect).toBeFalsy(); expect(initialState.componentInstance.displayAspect).toBeFalsy();
}); });
@@ -266,7 +266,7 @@ describe('MetadataTabComponent', () => {
expect(aspect).toBe('EXIF'); expect(aspect).toBe('EXIF');
}); });
fixture.detectChanges(); fixture.detectChanges();
const initialState = fixture.debugElement.query(By.css('adf-content-metadata-card')); const initialState = fixture.debugElement.query(By.css('adf-content-metadata'));
expect(initialState.componentInstance.displayAspect).toBe('EXIF'); expect(initialState.componentInstance.displayAspect).toBe('EXIF');
}); });
}); });