Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VitoAlbano committed Nov 24, 2023
1 parent b661b88 commit 573f4be
Show file tree
Hide file tree
Showing 24 changed files with 519 additions and 437 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('UploadService', () => {
service.uploadFilesInTheQueue(emitter);

const request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true&include=allowableOperations');
expect(request.url).toContain('/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true&include=allowableOperations');
expect(request.method).toBe('POST');

jasmine.Ajax.requests.mostRecent().respondWith({
Expand All @@ -194,7 +194,7 @@ describe('UploadService', () => {
service.addToQueue(fileFake);
service.uploadFilesInTheQueue(null, emitter);
expect(jasmine.Ajax.requests.mostRecent().url)
.toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true&include=allowableOperations');
.toContain('ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true&include=allowableOperations');

jasmine.Ajax.requests.mostRecent().respondWith({
status: 404,
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('UploadService', () => {
emitterDisposable.unsubscribe();

const deleteRequest = jasmine.Ajax.requests.mostRecent();
expect(deleteRequest.url).toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/myNodeId?permanent=true');
expect(deleteRequest.url).toContain('ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/myNodeId?permanent=true');
expect(deleteRequest.method).toBe('DELETE');

jasmine.Ajax.requests.mostRecent().respondWith({
Expand All @@ -247,7 +247,7 @@ describe('UploadService', () => {
service.cancelUpload(...file);

const request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true&include=allowableOperations');
expect(request.url).toContain('ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children?autoRename=true&include=allowableOperations');
expect(request.method).toBe('POST');

jasmine.Ajax.requests.mostRecent().respondWith({
Expand All @@ -269,7 +269,7 @@ describe('UploadService', () => {
emitterDisposable.unsubscribe();

const deleteRequest = jasmine.Ajax.requests.mostRecent();
expect(deleteRequest.url).toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/myNodeId/versions/1.1');
expect(deleteRequest.url).toContain('ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/myNodeId/versions/1.1');
expect(deleteRequest.method).toBe('DELETE');

jasmine.Ajax.requests.mostRecent().respondWith({
Expand All @@ -288,7 +288,7 @@ describe('UploadService', () => {
service.cancelUpload(...file);

const request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/fakeId/content?include=allowableOperations');
expect(request.url).toContain('ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/fakeId/content?include=allowableOperations');
expect(request.method).toBe('PUT');

jasmine.Ajax.requests.mostRecent().respondWith({
Expand Down Expand Up @@ -349,7 +349,7 @@ describe('UploadService', () => {
service.uploadFilesInTheQueue(emitter);

const request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/123/children?autoRename=true&include=allowableOperations');
expect(request.url).toContain('ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/123/children?autoRename=true&include=allowableOperations');
expect(request.method).toBe('POST');

jasmine.Ajax.requests.mostRecent().respondWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ import { By } from '@angular/platform-browser';
import { Node } from '@alfresco/js-api';
import { ContentMetadataCardComponent } from './content-metadata-card.component';
import { ContentMetadataComponent } from '../content-metadata/content-metadata.component';
import { ContentTestingModule } from '../../../testing/content.testing.module';
import { SimpleChange } from '@angular/core';
import { APP_INITIALIZER, SimpleChange } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { NodeAspectService } from '../../../aspect-list/services/node-aspect.service';
import { ContentMetadataService } from '../../services/content-metadata.service';
import { AllowableOperationsEnum } from '../../../common/models/allowable-operations.enum';
import { of } from 'rxjs';
import { AlfrescoApiService, AlfrescoApiServiceMock, AuthModule, PipeModule, TranslationMock, TranslationService } from '@alfresco/adf-core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
import { versionCompatibilityFactory } from '../../../version-compatibility/version-compatibility-factory';
import { VersionCompatibilityService } from '../../../version-compatibility';
import { MatDialogModule } from '@angular/material/dialog';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { MatTooltipModule } from '@angular/material/tooltip';
import { CategoryService } from '../../../category';
import { TagService } from '../../../tag';
import { PropertyDescriptorsService } from '../../public-api';

describe('ContentMetadataCardComponent', () => {

Expand All @@ -36,18 +46,40 @@ describe('ContentMetadataCardComponent', () => {
let node: Node;
const preset = 'custom-preset';
let nodeAspectService: NodeAspectService = null;
let tagService: TagService = null;
let categoryService: CategoryService = null;
let propertyDescriptorsService: PropertyDescriptorsService = null;

const getToggleEditButton = () => fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]'));

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
ContentTestingModule
NoopAnimationsModule,
AuthModule.forRoot({ useHash: true }),
HttpClientModule,
MatDialogModule,
PipeModule,
MatSnackBarModule,
MatTooltipModule
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{ provide: TranslationService, useClass: TranslationMock },
{
provide: APP_INITIALIZER,
useFactory: versionCompatibilityFactory,
deps: [ VersionCompatibilityService ],
multi: true
}
]
});
fixture = TestBed.createComponent(ContentMetadataCardComponent);
contentMetadataService = TestBed.inject(ContentMetadataService);
tagService = TestBed.inject(TagService);
categoryService = TestBed.inject(CategoryService);
propertyDescriptorsService = TestBed.inject(PropertyDescriptorsService);
component = fixture.componentInstance;
node = {
aspectNames: [],
Expand All @@ -64,6 +96,9 @@ describe('ContentMetadataCardComponent', () => {
component.editAspectSupported = true;
nodeAspectService = TestBed.inject(NodeAspectService);
spyOn(contentMetadataService, 'getContentTypeProperty').and.returnValue(of([]));
spyOn(tagService, 'getTagsByNodeId').and.returnValue(of());
spyOn(categoryService, 'getCategoryLinksForNode').and.returnValue(of());
spyOn(propertyDescriptorsService, 'load').and.returnValue(of());
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import { By } from '@angular/platform-browser';
import { Category, CategoryPaging, ClassesApi, Node, Tag, TagBody, TagEntry, TagPaging, TagPagingList } from '@alfresco/js-api';
import { ContentMetadataComponent } from './content-metadata.component';
import { ContentMetadataService } from '../../services/content-metadata.service';
import { AppConfigService, CardViewBaseItemModel, CardViewComponent, LogService, UpdateNotification } from '@alfresco/adf-core';
import { AppConfigService, AuthModule, CardViewBaseItemModel, CardViewComponent, LogService, PipeModule, TranslationMock, TranslationService, UpdateNotification } from '@alfresco/adf-core';
import { NodesApiService } from '../../../common/services/nodes-api.service';
import { EMPTY, of, throwError } from 'rxjs';
import { ContentTestingModule } from '../../../testing/content.testing.module';
import { mockGroupProperties } from './mock-data';
import { TranslateModule } from '@ngx-translate/core';
import { CardViewContentUpdateService } from '../../../common/services/card-view-content-update.service';
Expand All @@ -38,6 +37,11 @@ import {
TagsCreatorMode,
TagService
} from '@alfresco/adf-content-services';
import { HttpClientModule } from '@angular/common/http';
import { MatDialogModule } from '@angular/material/dialog';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { MatTooltipModule } from '@angular/material/tooltip';

describe('ContentMetadataComponent', () => {
let component: ContentMetadataComponent;
Expand Down Expand Up @@ -142,8 +146,16 @@ describe('ContentMetadataComponent', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), ContentTestingModule],
imports: [TranslateModule.forRoot(),
NoopAnimationsModule,
AuthModule.forRoot({ useHash: true }),
HttpClientModule,
MatDialogModule,
MatSnackBarModule,
MatTooltipModule,
PipeModule],
providers: [
{ provide: TranslationService, useClass: TranslationMock },
{
provide: LogService,
useValue: {
Expand Down Expand Up @@ -327,6 +339,8 @@ describe('ContentMetadataComponent', () => {
const logService: LogService = TestBed.inject(LogService);
component.editable = true;
const property = { key: 'properties.property-key', value: 'original-value' } as CardViewBaseItemModel;
spyOn(nodesApiService, 'updateNode').and.returnValue(throwError(new Error('My bad')));

updateService.update(property, 'updated-value');
tick(600);

Expand All @@ -337,7 +351,6 @@ describe('ContentMetadataComponent', () => {
sub.unsubscribe();
});

spyOn(nodesApiService, 'updateNode').and.returnValue(throwError(new Error('My bad')));

fixture.detectChanges();
fixture.whenStable().then(() => clickOnSave());
Expand Down Expand Up @@ -1135,6 +1148,7 @@ describe('ContentMetadataComponent', () => {

it('should have assigned true to disabledTagsRemoving after clicking on update button', () => {
tagsCreator.tagsChange.emit([]);
spyOn(nodesApiService, 'updateNode').and.returnValue(of());
fixture.detectChanges();

clickOnSave();
Expand Down Expand Up @@ -1166,6 +1180,7 @@ describe('ContentMetadataComponent', () => {
it('should have assigned false to tagNameControlVisible after clicking on update button', () => {
tagsCreator.tagNameControlVisibleChange.emit(true);
tagsCreator.tagsChange.emit([]);
spyOn(nodesApiService, 'updateNode').and.returnValue(of());
fixture.detectChanges();

clickOnSave();
Expand Down Expand Up @@ -1350,6 +1365,7 @@ describe('ContentMetadataComponent', () => {

it('should disable removal on saving', () => {
categoriesManagementComponent.categoriesChange.emit([]);
spyOn(nodesApiService, 'updateNode').and.returnValue(of());
fixture.detectChanges();

clickOnSave();
Expand Down Expand Up @@ -1381,6 +1397,7 @@ describe('ContentMetadataComponent', () => {
it('should set categoryNameControlVisible to false after saving', () => {
categoriesManagementComponent.categoryNameControlVisibleChange.emit(true);
categoriesManagementComponent.categoriesChange.emit([]);
spyOn(nodesApiService, 'updateNode').and.returnValue(of());
fixture.detectChanges();

clickOnSave();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ describe('PropertyDescriptorLoaderService', () => {
classesApi = service['classesApi'];
});

it('should load the groups passed by paramter', () => {
spyOn(classesApi, 'getClass');
it('should load the groups passed by paramter', (done) => {
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve({}));

service.load(['exif:exif', 'cm:content', 'custom:custom'])
.subscribe(() => {});

expect(classesApi.getClass).toHaveBeenCalledTimes(3);
expect(classesApi.getClass).toHaveBeenCalledWith('exif_exif');
expect(classesApi.getClass).toHaveBeenCalledWith('cm_content');
expect(classesApi.getClass).toHaveBeenCalledWith('custom_custom');
.subscribe(() => {
expect(classesApi.getClass).toHaveBeenCalledTimes(3);
expect(classesApi.getClass).toHaveBeenCalledWith('exif_exif');
expect(classesApi.getClass).toHaveBeenCalledWith('cm_content');
expect(classesApi.getClass).toHaveBeenCalledWith('custom_custom');
done();
});
});

it('should merge the forked values', (done) => {
Expand Down
Loading

0 comments on commit 573f4be

Please sign in to comment.