mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[AAE-10319] unit test fixes for content-services lib
This commit is contained in:
parent
a535af667b
commit
2207156f3f
@ -21,7 +21,7 @@ module.exports = function (config) {
|
|||||||
served: true,
|
served: true,
|
||||||
watched: false
|
watched: false
|
||||||
},
|
},
|
||||||
{pattern: 'lib/core/src/lib/assets/images/ft_ic_folder.svg', included: false, served: true, watched: false},
|
{pattern: 'lib/core/src/lib/assets/**/*.svg', included: false, served: true, watched: false},
|
||||||
{pattern: 'lib/core/src/lib/i18n/**/en.json', included: false, served: true, watched: false},
|
{pattern: 'lib/core/src/lib/i18n/**/en.json', included: false, served: true, watched: false},
|
||||||
{pattern: 'lib/content-services/**/*.ts', included: false, served: true, watched: false},
|
{pattern: 'lib/content-services/**/*.ts', included: false, served: true, watched: false},
|
||||||
{pattern: 'lib/config/app.config.json', included: false, served: true, watched: false}
|
{pattern: 'lib/config/app.config.json', included: false, served: true, watched: false}
|
||||||
@ -30,8 +30,8 @@ module.exports = function (config) {
|
|||||||
frameworks: ['jasmine-ajax', 'jasmine', '@angular-devkit/build-angular'],
|
frameworks: ['jasmine-ajax', 'jasmine', '@angular-devkit/build-angular'],
|
||||||
|
|
||||||
proxies: {
|
proxies: {
|
||||||
|
'/assets/images/': '/base/lib/core/src/lib/assets/images/',
|
||||||
'/base/assets/': '/base/lib/content-services/src/lib/assets/',
|
'/base/assets/': '/base/lib/content-services/src/lib/assets/',
|
||||||
'/base/lib/content-services/assets/images/ft_ic_folder.svg': '/base/lib/core/src/lib/assets/images/ft_ic_folder.svg',
|
|
||||||
'/assets/': '/base/lib/content-services/src/lib/assets/',
|
'/assets/': '/base/lib/content-services/src/lib/assets/',
|
||||||
'/assets/adf-content-services/i18n/en.json': '/base/lib/content-services/src/lib/i18n/en.json',
|
'/assets/adf-content-services/i18n/en.json': '/base/lib/content-services/src/lib/i18n/en.json',
|
||||||
'/assets/adf-core/i18n/en.json': '/base/lib/core/src/lib/i18n/en.json',
|
'/assets/adf-core/i18n/en.json': '/base/lib/core/src/lib/i18n/en.json',
|
||||||
|
@ -139,13 +139,13 @@ describe('Rating component', () => {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const deleteSpy = spyOn(service, 'deleteRating');
|
spyOn(service, 'deleteRating').and.returnValue(of({}));
|
||||||
|
|
||||||
component.ngOnChanges();
|
component.ngOnChanges();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const starThree: any = element.querySelector('#adf-colored-star-2');
|
const starThree: any = element.querySelector('#adf-colored-star-2');
|
||||||
starThree.click();
|
starThree.click();
|
||||||
expect(element.querySelectorAll('.adf-colored-star').length).toBe(3);
|
expect(element.querySelectorAll('.adf-colored-star').length).toBe(3);
|
||||||
expect(deleteSpy).toHaveBeenCalled();
|
expect(service.deleteRating).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -33,6 +33,7 @@ import { ContentModule } from '../content.module';
|
|||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { versionCompatibilityFactory } from '../version-compatibility/version-compatibility-factory';
|
import { versionCompatibilityFactory } from '../version-compatibility/version-compatibility-factory';
|
||||||
import { VersionCompatibilityService } from '../version-compatibility/version-compatibility.service';
|
import { VersionCompatibilityService } from '../version-compatibility/version-compatibility.service';
|
||||||
|
import { MatIconTestingModule } from '@angular/material/icon/testing';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@ -40,7 +41,8 @@ import { VersionCompatibilityService } from '../version-compatibility/version-co
|
|||||||
RouterTestingModule,
|
RouterTestingModule,
|
||||||
TranslateModule,
|
TranslateModule,
|
||||||
CoreModule,
|
CoreModule,
|
||||||
ContentModule
|
ContentModule,
|
||||||
|
MatIconTestingModule
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
|
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
|
||||||
|
@ -63,7 +63,7 @@ describe('VersionListComponent', () => {
|
|||||||
component.node = { id: nodeId, allowableOperations: ['update'] } as Node;
|
component.node = { id: nodeId, allowableOperations: ['update'] } as Node;
|
||||||
|
|
||||||
spyOn(component, 'downloadContent').and.stub();
|
spyOn(component, 'downloadContent').and.stub();
|
||||||
spyOn(component['nodesApi'], 'getNode').and.returnValue(Promise.resolve(new NodeEntry({ entry: { id: 'nodeInfoId' } })));
|
spyOn(component.nodesApi, 'getNode').and.returnValue(Promise.resolve(new NodeEntry({ entry: { id: 'nodeInfoId' } })));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should raise confirmation dialog on delete', () => {
|
it('should raise confirmation dialog on delete', () => {
|
||||||
@ -86,12 +86,12 @@ describe('VersionListComponent', () => {
|
|||||||
afterClosed: () => of(true)
|
afterClosed: () => of(true)
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
spyOn(component['versionsApi'], 'deleteVersion').and.returnValue(Promise.resolve(true));
|
spyOn(component.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true));
|
||||||
|
|
||||||
component.deleteVersion(versionId);
|
component.deleteVersion(versionId);
|
||||||
|
|
||||||
expect(dialog.open).toHaveBeenCalled();
|
expect(dialog.open).toHaveBeenCalled();
|
||||||
expect(component['versionsApi'].deleteVersion).toHaveBeenCalledWith(nodeId, versionId);
|
expect(component.versionsApi.deleteVersion).toHaveBeenCalledWith(nodeId, versionId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not delete version if user rejects', () => {
|
it('should not delete version if user rejects', () => {
|
||||||
@ -101,12 +101,12 @@ describe('VersionListComponent', () => {
|
|||||||
afterClosed: () => of(false)
|
afterClosed: () => of(false)
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
spyOn(component['versionsApi'], 'deleteVersion').and.returnValue(Promise.resolve(true));
|
spyOn(component.versionsApi, 'deleteVersion').and.returnValue(Promise.resolve(true));
|
||||||
|
|
||||||
component.deleteVersion(versionId);
|
component.deleteVersion(versionId);
|
||||||
|
|
||||||
expect(dialog.open).toHaveBeenCalled();
|
expect(dialog.open).toHaveBeenCalled();
|
||||||
expect(component['versionsApi'].deleteVersion).not.toHaveBeenCalled();
|
expect(component.versionsApi.deleteVersion).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reload and raise deleted event', (done) => {
|
it('should reload and raise deleted event', (done) => {
|
||||||
@ -122,7 +122,7 @@ describe('VersionListComponent', () => {
|
|||||||
describe('Version history fetching', () => {
|
describe('Version history fetching', () => {
|
||||||
|
|
||||||
it('should use loading bar', () => {
|
it('should use loading bar', () => {
|
||||||
spyOn(component['versionsApi'], 'listVersionHistory').and
|
spyOn(component.versionsApi, 'listVersionHistory').and
|
||||||
.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
|
.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
|
||||||
|
|
||||||
let loadingProgressBar = fixture.debugElement.query(By.css('[data-automation-id="version-history-loading-bar"]'));
|
let loadingProgressBar = fixture.debugElement.query(By.css('[data-automation-id="version-history-loading-bar"]'));
|
||||||
@ -136,18 +136,18 @@ describe('VersionListComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should load the versions for a given id', () => {
|
it('should load the versions for a given id', () => {
|
||||||
spyOn(component['versionsApi'], 'listVersionHistory').and
|
spyOn(component.versionsApi, 'listVersionHistory').and
|
||||||
.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
|
.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
|
||||||
|
|
||||||
component.ngOnChanges();
|
component.ngOnChanges();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component['versionsApi'].listVersionHistory).toHaveBeenCalledWith(nodeId);
|
expect(component.versionsApi.listVersionHistory).toHaveBeenCalledWith(nodeId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show the versions after loading', (done) => {
|
it('should show the versions after loading', (done) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
spyOn(component['versionsApi'], 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
||||||
list: {
|
list: {
|
||||||
entries: [
|
entries: [
|
||||||
{
|
{
|
||||||
@ -173,7 +173,7 @@ describe('VersionListComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT show the versions comments if input property is set not to show them', (done) => {
|
it('should NOT show the versions comments if input property is set not to show them', (done) => {
|
||||||
spyOn(component['versionsApi'], 'listVersionHistory').and
|
spyOn(component.versionsApi, 'listVersionHistory').and
|
||||||
.callFake(() => Promise.resolve(
|
.callFake(() => Promise.resolve(
|
||||||
new VersionPaging({
|
new VersionPaging({
|
||||||
list: {
|
list: {
|
||||||
@ -208,7 +208,7 @@ describe('VersionListComponent', () => {
|
|||||||
versionComment: 'test-version-comment'
|
versionComment: 'test-version-comment'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
spyOn(component['versionsApi'], 'listVersionHistory').and.returnValue(Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } })));
|
spyOn(component.versionsApi, 'listVersionHistory').and.returnValue(Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } })));
|
||||||
spyOn(contentVersionService.contentApi, 'getContentUrl').and.returnValue('the/download/url');
|
spyOn(contentVersionService.contentApi, 'getContentUrl').and.returnValue('the/download/url');
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@ -232,9 +232,9 @@ describe('VersionListComponent', () => {
|
|||||||
versionComment: 'test-version-comment'
|
versionComment: 'test-version-comment'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
spyOn(component['versionsApi'], 'listVersionHistory').and
|
spyOn(component.versionsApi, 'listVersionHistory').and
|
||||||
.callFake(() => Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } })));
|
.callFake(() => Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } })));
|
||||||
const spyOnDownload = spyOn(component['contentApi'], 'getContentUrl').and.stub();
|
const spyOnDownload = spyOn(component.contentApi, 'getContentUrl').and.stub();
|
||||||
|
|
||||||
component.allowDownload = false;
|
component.allowDownload = false;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@ -248,16 +248,16 @@ describe('VersionListComponent', () => {
|
|||||||
|
|
||||||
it('should restore version only when restore allowed', () => {
|
it('should restore version only when restore allowed', () => {
|
||||||
component.node.allowableOperations = [];
|
component.node.allowableOperations = [];
|
||||||
spyOn(component['versionsApi'], 'revertVersion').and.stub();
|
spyOn(component.versionsApi, 'revertVersion').and.stub();
|
||||||
component.restore('1');
|
component.restore('1');
|
||||||
expect(component['versionsApi'].revertVersion).not.toHaveBeenCalled();
|
expect(component.versionsApi.revertVersion).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should load the versions for a given id', () => {
|
it('should load the versions for a given id', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.versions = versionTest;
|
component.versions = versionTest;
|
||||||
|
|
||||||
const spyOnRevertVersion = spyOn(component['versionsApi'], 'revertVersion').and
|
const spyOnRevertVersion = spyOn(component.versionsApi, 'revertVersion').and
|
||||||
.callFake(() => Promise.resolve(new VersionEntry(
|
.callFake(() => Promise.resolve(new VersionEntry(
|
||||||
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } })));
|
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } })));
|
||||||
|
|
||||||
@ -269,10 +269,10 @@ describe('VersionListComponent', () => {
|
|||||||
it('should get node info after restoring the node', fakeAsync(() => {
|
it('should get node info after restoring the node', fakeAsync(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.versions = versionTest;
|
component.versions = versionTest;
|
||||||
spyOn(component['versionsApi'], 'listVersionHistory')
|
spyOn(component.versionsApi, 'listVersionHistory')
|
||||||
.and.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
|
.and.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
|
||||||
|
|
||||||
spyOn(component['versionsApi'], 'revertVersion')
|
spyOn(component.versionsApi, 'revertVersion')
|
||||||
.and.callFake(() => Promise.resolve(new VersionEntry(
|
.and.callFake(() => Promise.resolve(new VersionEntry(
|
||||||
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } })));
|
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } })));
|
||||||
|
|
||||||
@ -280,16 +280,16 @@ describe('VersionListComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(component['nodesApi'].getNode).toHaveBeenCalled();
|
expect(component.nodesApi.getNode).toHaveBeenCalled();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should emit with node info data', fakeAsync(() => {
|
it('should emit with node info data', fakeAsync(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.versions = versionTest;
|
component.versions = versionTest;
|
||||||
spyOn(component['versionsApi'], 'listVersionHistory')
|
spyOn(component.versionsApi, 'listVersionHistory')
|
||||||
.and.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
|
.and.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
|
||||||
|
|
||||||
spyOn(component['versionsApi'], 'revertVersion')
|
spyOn(component.versionsApi, 'revertVersion')
|
||||||
.and.callFake(() => Promise.resolve(new VersionEntry(
|
.and.callFake(() => Promise.resolve(new VersionEntry(
|
||||||
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } })));
|
{ entry: { name: 'test-file-name', id: '1.0', versionComment: 'test-version-comment' } })));
|
||||||
|
|
||||||
@ -306,9 +306,9 @@ describe('VersionListComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.versions = versionTest;
|
component.versions = versionTest;
|
||||||
|
|
||||||
const spyOnListVersionHistory = spyOn(component['versionsApi'], 'listVersionHistory').and
|
const spyOnListVersionHistory = spyOn(component.versionsApi, 'listVersionHistory').and
|
||||||
.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
|
.callFake(() => Promise.resolve({ list: { entries: versionTest } }));
|
||||||
spyOn(component['versionsApi'], 'revertVersion').and.callFake(() => Promise.resolve(null));
|
spyOn(component.versionsApi, 'revertVersion').and.callFake(() => Promise.resolve(null));
|
||||||
|
|
||||||
component.restore(versionId);
|
component.restore(versionId);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@ -325,7 +325,7 @@ describe('VersionListComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.node = new Node({ id: nodeId });
|
component.node = new Node({ id: nodeId });
|
||||||
spyOn(component['versionsApi'], 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
||||||
list: {
|
list: {
|
||||||
entries: [
|
entries: [
|
||||||
{
|
{
|
||||||
@ -372,7 +372,7 @@ describe('VersionListComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.node = { id: nodeId } as Node;
|
component.node = { id: nodeId } as Node;
|
||||||
spyOn(component['versionsApi'], 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
||||||
list: {
|
list: {
|
||||||
entries: [
|
entries: [
|
||||||
{
|
{
|
||||||
@ -420,7 +420,7 @@ describe('VersionListComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.node = { id: nodeId, allowableOperations: ['update', 'delete'] } as Node;
|
component.node = { id: nodeId, allowableOperations: ['update', 'delete'] } as Node;
|
||||||
spyOn(component['versionsApi'], 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
spyOn(component.versionsApi, 'listVersionHistory').and.callFake(() => Promise.resolve(new VersionPaging({
|
||||||
list: {
|
list: {
|
||||||
entries: [
|
entries: [
|
||||||
{
|
{
|
||||||
|
@ -31,19 +31,19 @@ import { ContentVersionService } from './content-version.service';
|
|||||||
})
|
})
|
||||||
export class VersionListComponent implements OnChanges {
|
export class VersionListComponent implements OnChanges {
|
||||||
|
|
||||||
_contentApi: ContentApi;
|
private _contentApi: ContentApi;
|
||||||
get contentApi(): ContentApi {
|
get contentApi(): ContentApi {
|
||||||
this._contentApi = this._contentApi ?? new ContentApi(this.alfrescoApi.getInstance());
|
this._contentApi = this._contentApi ?? new ContentApi(this.alfrescoApi.getInstance());
|
||||||
return this._contentApi;
|
return this._contentApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
_versionsApi: VersionsApi;
|
private _versionsApi: VersionsApi;
|
||||||
get versionsApi(): VersionsApi {
|
get versionsApi(): VersionsApi {
|
||||||
this._versionsApi = this._versionsApi ?? new VersionsApi(this.alfrescoApi.getInstance());
|
this._versionsApi = this._versionsApi ?? new VersionsApi(this.alfrescoApi.getInstance());
|
||||||
return this._versionsApi;
|
return this._versionsApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
_nodesApi: NodesApi;
|
private _nodesApi: NodesApi;
|
||||||
get nodesApi(): NodesApi {
|
get nodesApi(): NodesApi {
|
||||||
this._nodesApi = this._nodesApi ?? new NodesApi(this.alfrescoApi.getInstance());
|
this._nodesApi = this._nodesApi ?? new NodesApi(this.alfrescoApi.getInstance());
|
||||||
return this._nodesApi;
|
return this._nodesApi;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user