[ACA-4205] Latest ADF and unit test fixes (#1861)

* upgrade ADF and cleanup test

* unit test stabilisation

* cleanup tests

* unit test stabilisation

* unit test stabilisation

* update ADF libs to latest alphas
This commit is contained in:
Denys Vuika
2020-12-07 18:34:34 +00:00
committed by GitHub
parent 1243e69833
commit 71c2e40db8
26 changed files with 193 additions and 336 deletions

View File

@@ -1,32 +0,0 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { LocationLinkComponent } from './location-link.component';
describe('LocationLinkComponent', () => {
it('should be defined', () => {
expect(LocationLinkComponent).toBeDefined();
});
});

View File

@@ -26,7 +26,7 @@
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router } from '@angular/router';
import { AlfrescoApiService, NodeFavoriteDirective, DataTableComponent, AppConfigPipe, UserPreferencesService } from '@alfresco/adf-core';
import { AlfrescoApiService, NodeFavoriteDirective, DataTableComponent, AppConfigModule, UserPreferencesService } from '@alfresco/adf-core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { FavoriteLibrariesComponent } from './favorite-libraries.component';
import { AppTestingModule } from '../../testing/app-testing.module';
@@ -59,9 +59,8 @@ describe('FavoriteLibrariesComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, EffectsModule.forRoot([RouterEffects, LibraryEffects])],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, FavoriteLibrariesComponent, AppConfigPipe],
providers: [ContentManagementService, UserPreferencesService],
imports: [AppTestingModule, EffectsModule.forRoot([RouterEffects, LibraryEffects]), AppConfigModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, FavoriteLibrariesComponent],
schemas: [NO_ERRORS_SCHEMA]
});

View File

@@ -26,8 +26,8 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router } from '@angular/router';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { AlfrescoApiService, NodeFavoriteDirective, DataTableComponent, AppConfigPipe } from '@alfresco/adf-core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { NodeFavoriteDirective, DataTableComponent, AppConfigModule } from '@alfresco/adf-core';
import { CustomResourcesService, DocumentListComponent } from '@alfresco/adf-content-services';
import { of } from 'rxjs';
import { FavoritesComponent } from './favorites.component';
import { AppTestingModule } from '../../testing/app-testing.module';
@@ -36,18 +36,27 @@ import { ContentApiService } from '@alfresco/aca-shared';
describe('FavoritesComponent', () => {
let fixture: ComponentFixture<FavoritesComponent>;
let component: FavoritesComponent;
let alfrescoApi: AlfrescoApiService;
let contentApi: ContentApiService;
let router: Router;
const mockRouter = {
url: 'favorites',
navigate: () => {}
};
let page;
let node;
beforeEach(() => {
page = {
TestBed.configureTestingModule({
imports: [AppTestingModule, AppConfigModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, FavoritesComponent],
providers: [
{
provide: Router,
useValue: {
url: 'favorites',
navigate: () => {}
}
}
],
schemas: [NO_ERRORS_SCHEMA]
});
const page: any = {
list: {
entries: [{ entry: { id: 1, target: { file: {} } } }, { entry: { id: 2, target: { folder: {} } } }],
pagination: { data: 'data' }
@@ -62,27 +71,12 @@ describe('FavoritesComponent', () => {
elements: []
}
};
});
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, FavoritesComponent, AppConfigPipe],
providers: [
{
provide: Router,
useValue: mockRouter
}
],
schemas: [NO_ERRORS_SCHEMA]
});
fixture = TestBed.createComponent(FavoritesComponent);
component = fixture.componentInstance;
alfrescoApi = TestBed.inject(AlfrescoApiService);
alfrescoApi.reset();
spyOn(alfrescoApi.favoritesApi, 'getFavorites').and.returnValue(Promise.resolve(page));
const customResourcesService = TestBed.inject(CustomResourcesService);
spyOn(customResourcesService, 'loadFavorites').and.returnValue(of(page));
contentApi = TestBed.inject(ContentApiService);
router = TestBed.inject(Router);
@@ -91,7 +85,7 @@ describe('FavoritesComponent', () => {
describe('Node navigation', () => {
beforeEach(() => {
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
spyOn(router, 'navigate');
spyOn(router, 'navigate').and.stub();
fixture.detectChanges();
});
@@ -136,7 +130,7 @@ describe('FavoritesComponent', () => {
component.onNodeDoubleClick(nodeEntity);
expect(component.showPreview).toHaveBeenCalledWith(nodeEntity, {
location: mockRouter.url
location: 'favorites'
});
});
});

View File

@@ -26,16 +26,7 @@
import { TestBed, fakeAsync, tick, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import {
NodeFavoriteDirective,
DataTableComponent,
UploadService,
AppConfigPipe,
AlfrescoApiService,
AlfrescoApiServiceMock,
DataTableModule,
PaginationModule
} from '@alfresco/adf-core';
import { NodeFavoriteDirective, DataTableComponent, UploadService, AppConfigModule, DataTableModule, PaginationModule } from '@alfresco/adf-core';
import { DocumentListComponent, FilterSearch } from '@alfresco/adf-content-services';
import { NodeActionsService } from '../../services/node-actions.service';
import { FilesComponent } from './files.component';
@@ -70,10 +61,9 @@ describe('FilesComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, DataTableModule, PaginationModule, SharedDirectivesModule, DirectivesModule],
declarations: [FilesComponent, DataTableComponent, NodeFavoriteDirective, DocumentListComponent, AppConfigPipe],
imports: [AppTestingModule, DataTableModule, PaginationModule, SharedDirectivesModule, DirectivesModule, AppConfigModule],
declarations: [FilesComponent, DataTableComponent, NodeFavoriteDirective, DocumentListComponent],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{
provide: Router,
useValue: router

View File

@@ -26,31 +26,28 @@
import { CommentsTabComponent } from './comments-tab.component';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { NodePermissionService } from '@alfresco/aca-shared';
import { Node } from '@alfresco/js-api';
describe('CommentsTabComponent', () => {
let component: CommentsTabComponent;
let fixture: ComponentFixture<CommentsTabComponent>;
const permissionsMock = {
check: jasmine.createSpy('check')
};
let checked;
let nodePermissionService: NodePermissionService;
let checked: string[];
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [CommentsTabComponent],
providers: [{ provide: NodePermissionService, useValue: permissionsMock }],
schemas: [NO_ERRORS_SCHEMA]
declarations: [CommentsTabComponent]
});
nodePermissionService = TestBed.inject(NodePermissionService);
fixture = TestBed.createComponent(CommentsTabComponent);
component = fixture.componentInstance;
checked = null;
permissionsMock.check.and.callFake((_source, permissions) => {
spyOn(nodePermissionService, 'check').and.callFake((_source, permissions) => {
checked = permissions;
return true;
});

View File

@@ -29,34 +29,34 @@ import { UpdateLibraryAction } from '@alfresco/aca-shared/store';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Site, SitePaging } from '@alfresco/js-api';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-core';
import { AlfrescoApiService } from '@alfresco/adf-core';
describe('LibraryMetadataFormComponent', () => {
let fixture: ComponentFixture<LibraryMetadataFormComponent>;
let component: LibraryMetadataFormComponent;
let alfrescoApiService: AlfrescoApiService;
const storeMock = {
dispatch: jasmine.createSpy('dispatch')
};
let store: Store<any>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [LibraryMetadataFormComponent],
providers: [
{ provide: Store, useValue: storeMock },
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
{
provide: Store,
useValue: {
dispatch: jasmine.createSpy('dispatch')
}
}
],
schemas: [NO_ERRORS_SCHEMA]
});
store = TestBed.inject(Store);
alfrescoApiService = TestBed.inject(AlfrescoApiService);
fixture = TestBed.createComponent(LibraryMetadataFormComponent);
component = fixture.componentInstance;
alfrescoApiService = TestBed.inject(AlfrescoApiService);
});
afterEach(() => {
storeMock.dispatch.calls.reset();
});
it('should initialize form with node data', () => {
@@ -130,7 +130,7 @@ describe('LibraryMetadataFormComponent', () => {
component.update();
expect(storeMock.dispatch).toHaveBeenCalledWith(new UpdateLibraryAction(siteEntryModel));
expect(store.dispatch).toHaveBeenCalledWith(new UpdateLibraryAction(siteEntryModel));
});
it('should not update library node if it has no permission', () => {
@@ -151,7 +151,7 @@ describe('LibraryMetadataFormComponent', () => {
component.update();
expect(storeMock.dispatch).not.toHaveBeenCalledWith(new UpdateLibraryAction(siteEntryModel));
expect(store.dispatch).not.toHaveBeenCalledWith(new UpdateLibraryAction(siteEntryModel));
});
it('should not update library node if form is invalid', () => {
@@ -174,7 +174,7 @@ describe('LibraryMetadataFormComponent', () => {
component.update();
expect(storeMock.dispatch).not.toHaveBeenCalledWith(new UpdateLibraryAction(siteEntryModel));
expect(store.dispatch).not.toHaveBeenCalledWith(new UpdateLibraryAction(siteEntryModel));
});
it('should toggle edit mode', () => {

View File

@@ -26,7 +26,7 @@
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router } from '@angular/router';
import { AlfrescoApiService, NodeFavoriteDirective, DataTableComponent, AppConfigPipe } from '@alfresco/adf-core';
import { AlfrescoApiService, NodeFavoriteDirective, DataTableComponent, AppConfigModule } from '@alfresco/adf-core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { LibrariesComponent } from './libraries.component';
import { AppTestingModule } from '../../testing/app-testing.module';
@@ -51,8 +51,8 @@ describe('LibrariesComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, EffectsModule.forRoot([LibraryEffects])],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, LibrariesComponent, AppConfigPipe],
imports: [AppTestingModule, EffectsModule.forRoot([LibraryEffects]), AppConfigModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, LibrariesComponent],
schemas: [NO_ERRORS_SCHEMA]
});

View File

@@ -23,10 +23,9 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { TestBed, ComponentFixture, async, fakeAsync, tick } from '@angular/core/testing';
import { UserPreferencesService, AppConfigPipe, NodeFavoriteDirective, UploadService, AlfrescoApiService } from '@alfresco/adf-core';
import { UserPreferencesService, UploadService, AlfrescoApiService } from '@alfresco/adf-core';
import { ClosePreviewAction } from '@alfresco/aca-shared/store';
import { PreviewComponent } from './preview.component';
import { of, throwError } from 'rxjs';
@@ -37,6 +36,7 @@ import { ContentApiService } from '@alfresco/aca-shared';
import { ContentManagementService } from '../../services/content-management.service';
import { Store } from '@ngrx/store';
import { Node, NodePaging, FavoritePaging, SharedLinkPaging, PersonEntry, ResultSetPaging } from '@alfresco/js-api';
import { PreviewModule } from './preview.module';
describe('PreviewComponent', () => {
let fixture: ComponentFixture<PreviewComponent>;
@@ -52,10 +52,7 @@ describe('PreviewComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, EffectsModule.forRoot([NodeEffects])],
providers: [AlfrescoApiService, ContentManagementService],
declarations: [AppConfigPipe, PreviewComponent, NodeFavoriteDirective],
schemas: [NO_ERRORS_SCHEMA]
imports: [EffectsModule.forRoot([NodeEffects]), PreviewModule, AppTestingModule]
});
fixture = TestBed.createComponent(PreviewComponent);

View File

@@ -25,39 +25,27 @@
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { AlfrescoApiService, NodeFavoriteDirective, DataTableComponent, AppConfigPipe } from '@alfresco/adf-core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { NodeFavoriteDirective, DataTableComponent, AppConfigModule } from '@alfresco/adf-core';
import { CustomResourcesService, DocumentListComponent } from '@alfresco/adf-content-services';
import { RecentFilesComponent } from './recent-files.component';
import { AppTestingModule } from '../../testing/app-testing.module';
import { Router } from '@angular/router';
import { PersonEntry } from '@alfresco/js-api';
import { PersonEntry, ResultSetPaging } from '@alfresco/js-api';
describe('RecentFilesComponent', () => {
let fixture: ComponentFixture<RecentFilesComponent>;
let component: RecentFilesComponent;
let alfrescoApi: AlfrescoApiService;
let page;
const mockRouter = {
url: 'recent-files'
};
beforeEach(() => {
page = {
list: {
entries: [{ entry: { id: 1 } }, { entry: { id: 2 } }],
pagination: { data: 'data' }
}
};
});
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, RecentFilesComponent, AppConfigPipe],
imports: [AppTestingModule, AppConfigModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, RecentFilesComponent],
providers: [
{
provide: Router,
useValue: mockRouter
useValue: {
url: 'recent-files'
}
}
],
schemas: [NO_ERRORS_SCHEMA]
@@ -66,16 +54,24 @@ describe('RecentFilesComponent', () => {
fixture = TestBed.createComponent(RecentFilesComponent);
component = fixture.componentInstance;
alfrescoApi = TestBed.inject(AlfrescoApiService);
alfrescoApi.reset();
spyOn(alfrescoApi.peopleApi, 'getPerson').and.returnValue(
const customResourcesService = TestBed.inject(CustomResourcesService);
spyOn(customResourcesService.peopleApi, 'getPerson').and.returnValue(
Promise.resolve({
entry: { id: 'personId' }
} as PersonEntry)
);
spyOn(alfrescoApi.searchApi, 'search').and.returnValue(Promise.resolve(page));
const page: ResultSetPaging = {
list: {
entries: [
{ entry: { id: '1', name: 'node1', nodeType: 'cm:file', isFile: true, isFolder: false } },
{ entry: { id: '2', name: 'node2', nodeType: 'cm:file', isFile: true, isFolder: false } }
],
pagination: { count: 2, totalItems: 2 }
}
};
spyOn(customResourcesService.searchApi, 'search').and.returnValue(Promise.resolve(page));
});
it('should call showPreview method', () => {
@@ -85,7 +81,7 @@ describe('RecentFilesComponent', () => {
component.onNodeDoubleClick(node);
expect(component.showPreview).toHaveBeenCalledWith(node, {
location: mockRouter.url
location: 'recent-files'
});
});
});

View File

@@ -25,7 +25,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { AppConfigPipe, DataTableComponent } from '@alfresco/adf-core';
import { AppConfigModule, DataTableComponent } from '@alfresco/adf-core';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { SearchLibrariesResultsComponent } from './search-libraries-results.component';
import { SearchLibrariesQueryBuilderService } from './search-libraries-query-builder.service';
@@ -39,8 +39,8 @@ describe('SearchLibrariesResultsComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [DataTableComponent, DocumentListComponent, SearchLibrariesResultsComponent, AppConfigPipe],
imports: [AppTestingModule, AppConfigModule],
declarations: [DataTableComponent, DocumentListComponent, SearchLibrariesResultsComponent],
schemas: [NO_ERRORS_SCHEMA],
providers: [SearchLibrariesQueryBuilderService]
});

View File

@@ -27,7 +27,7 @@ import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testin
import { SearchResultsComponent } from './search-results.component';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { AppSearchResultsModule } from '../search-results.module';
import { CoreModule, AppConfigService, AlfrescoApiService, AlfrescoApiServiceMock, TranslationService } from '@alfresco/adf-core';
import { CoreModule, AppConfigService, AlfrescoApiService, TranslationService } from '@alfresco/adf-core';
import { Store } from '@ngrx/store';
import { NavigateToFolder, SnackbarErrorAction } from '@alfresco/aca-shared/store';
import { Pagination, SearchRequest } from '@alfresco/js-api';
@@ -50,10 +50,6 @@ describe('SearchComponent', () => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), CoreModule.forRoot(), AppTestingModule, AppSearchResultsModule],
providers: [
{
provide: AlfrescoApiService,
useClass: AlfrescoApiServiceMock
},
{
provide: ActivatedRoute,
useValue: {

View File

@@ -25,7 +25,7 @@
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { AlfrescoApiService, AlfrescoApiServiceMock, NodeFavoriteDirective, DataTableComponent, AppConfigPipe } from '@alfresco/adf-core';
import { NodeFavoriteDirective, DataTableComponent, AppConfigModule } from '@alfresco/adf-core';
import { CustomResourcesService, DocumentListComponent } from '@alfresco/adf-content-services';
import { SharedFilesComponent } from './shared-files.component';
import { AppTestingModule } from '../../testing/app-testing.module';
@@ -36,42 +36,31 @@ import { SharedLinkPaging } from '@alfresco/js-api';
describe('SharedFilesComponent', () => {
let fixture: ComponentFixture<SharedFilesComponent>;
let alfrescoApi: AlfrescoApiService;
let page: SharedLinkPaging;
let customResourcesService: CustomResourcesService;
const mockRouter = {
url: 'shared-files'
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, AppConfigModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, SharedFilesComponent],
providers: [
{
provide: Router,
useValue: {
url: 'shared-files'
}
}
],
schemas: [NO_ERRORS_SCHEMA]
});
page = {
list: {
entries: [{ entry: { id: '1' } }, { entry: { id: '2' } }],
pagination: { count: 2 }
}
};
});
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, SharedFilesComponent, AppConfigPipe],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{
provide: Router,
useValue: mockRouter
}
],
schemas: [NO_ERRORS_SCHEMA]
});
customResourcesService = TestBed.inject(CustomResourcesService);
alfrescoApi = TestBed.inject(AlfrescoApiService);
alfrescoApi.reset();
spyOn(alfrescoApi.sharedLinksApi, 'findSharedLinks').and.returnValue(Promise.resolve(page));
const customResourcesService = TestBed.inject(CustomResourcesService);
spyOn(customResourcesService, 'loadSharedLinks').and.returnValue(of(page));
fixture = TestBed.createComponent(SharedFilesComponent);

View File

@@ -24,7 +24,7 @@
*/
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { CoreModule, AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-core';
import { CoreModule, AlfrescoApiService } from '@alfresco/adf-core';
import { ToggleFavoriteLibraryComponent } from './toggle-favorite-library.component';
import { LibraryFavoriteDirective } from '../../../directives/library-favorite.directive';
import { NO_ERRORS_SCHEMA } from '@angular/core';
@@ -37,8 +37,9 @@ import { TranslateModule } from '@ngx-translate/core';
describe('ToggleFavoriteLibraryComponent', () => {
let fixture: ComponentFixture<ToggleFavoriteLibraryComponent>;
let component;
let contentManagementService;
let component: ToggleFavoriteLibraryComponent;
let contentManagementService: ContentManagementService;
const selection = { library: { entry: { id: 'libraryId' } } };
const mockRouter = {
url: ''
@@ -53,10 +54,6 @@ describe('ToggleFavoriteLibraryComponent', () => {
provide: Router,
useValue: mockRouter
},
{
provide: AlfrescoApiService,
useClass: AlfrescoApiServiceMock
},
{
provide: Store,
useValue: {

View File

@@ -25,7 +25,7 @@
import { of } from 'rxjs';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-core';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { LibraryMembershipDirective } from '../../../directives/library-membership.directive';
import { Store } from '@ngrx/store';
import { NO_ERRORS_SCHEMA } from '@angular/core';
@@ -39,13 +39,9 @@ describe('ToggleJoinLibraryComponent', () => {
let fixture: ComponentFixture<ToggleJoinLibraryButtonComponent>;
let alfrescoApi: AlfrescoApiService;
let contentManagementService: ContentManagementService;
let store: Store<any>;
let entry;
const storeMock = {
select: () => of({ library: { entry, isLibrary: true } }),
dispatch: jasmine.createSpy('dispatch')
};
beforeEach(() => {
entry = {
id: 'lib-id',
@@ -58,23 +54,29 @@ describe('ToggleJoinLibraryComponent', () => {
imports: [AppTestingModule],
declarations: [ToggleJoinLibraryButtonComponent, LibraryMembershipDirective],
providers: [
{ provide: Store, useValue: storeMock },
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
{
provide: Store,
useValue: {
select: () => of({ library: { entry, isLibrary: true } }),
dispatch: jasmine.createSpy('dispatch')
}
}
],
schemas: [NO_ERRORS_SCHEMA]
});
fixture = TestBed.createComponent(ToggleJoinLibraryButtonComponent);
component = fixture.componentInstance;
store = TestBed.inject(Store);
alfrescoApi = TestBed.inject(AlfrescoApiService);
contentManagementService = TestBed.inject(ContentManagementService);
spyOn(alfrescoApi.peopleApi, 'getSiteMembershipRequest').and.stub();
fixture = TestBed.createComponent(ToggleJoinLibraryButtonComponent);
component = fixture.componentInstance;
});
afterEach(() => {
fixture.destroy();
storeMock.dispatch.calls.reset();
});
it('should get Store selection entry on initialization', (done) => {
@@ -88,21 +90,21 @@ describe('ToggleJoinLibraryComponent', () => {
const event = { error: {}, i18nKey: 'ERROR_i18nKey' };
component.onErrorEvent(event);
expect(storeMock.dispatch).toHaveBeenCalledWith(new SnackbarErrorAction(event.i18nKey));
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarErrorAction(event.i18nKey));
});
it('should dispatch `SnackbarInfoAction` action on onToggleEvent', () => {
const event = { shouldReload: true, i18nKey: 'SOME_i18nKey' };
component.onToggleEvent(event);
expect(storeMock.dispatch).toHaveBeenCalledWith(new SnackbarInfoAction(event.i18nKey));
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarInfoAction(event.i18nKey));
});
it('should dispatch `ReloadLibraryAction` action on onToggleEvent', () => {
const event = { shouldReload: true, i18nKey: 'SOME_i18nKey' };
component.onToggleEvent(event);
expect(storeMock.dispatch).toHaveBeenCalledWith(new ReloadLibraryAction());
expect(store.dispatch).toHaveBeenCalledWith(new ReloadLibraryAction());
});
it('should call libraryJoined.next on contentManagementService onToggleEvent', (done) => {

View File

@@ -24,7 +24,7 @@
*/
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { AlfrescoApiService, NodeFavoriteDirective, DataTableComponent, AppConfigPipe } from '@alfresco/adf-core';
import { AlfrescoApiService, NodeFavoriteDirective, DataTableComponent, AppConfigModule } from '@alfresco/adf-core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { TrashcanComponent } from './trashcan.component';
import { AppTestingModule } from '../../testing/app-testing.module';
@@ -46,8 +46,8 @@ describe('TrashcanComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, TrashcanComponent, AppConfigPipe],
imports: [AppTestingModule, AppConfigModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, TrashcanComponent],
schemas: [NO_ERRORS_SCHEMA]
});