Skip to content

Commit c52042c

Browse files
committed
[ACS-10165] create base component for library pages
1 parent fb4c3d4 commit c52042c

13 files changed

+597
-684
lines changed
Lines changed: 14 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,14 @@
1-
<aca-page-layout>
2-
<div class="aca-page-layout-header">
3-
<h1 class="aca-page-title">
4-
{{ (selectedRowItemsCount < 1 ? 'APP.BROWSE.LIBRARIES.MENU.FAVORITE_LIBRARIES.TITLE' : 'APP.HEADER.SELECTED') | translate: { count: selectedRowItemsCount } }}
5-
</h1>
6-
<aca-toolbar [items]="actions" />
7-
</div>
8-
9-
<div class="aca-page-layout-content">
10-
<div class="aca-main-content">
11-
<adf-document-list
12-
#documentList
13-
acaDocumentList
14-
acaContextActions
15-
[node]="$any(list)"
16-
[loading]="isLoading"
17-
[selectionMode]="'multiple'"
18-
[multiselect]="true"
19-
[navigate]="false"
20-
[sorting]="['title', 'asc']"
21-
[sortingMode]="'client'"
22-
[displayCheckboxesOnHover]="true"
23-
[preselectNodes]="selectedNodesState?.nodes"
24-
(node-dblclick)="handleNodeClick($event)"
25-
[imageResolver]="imageResolver"
26-
(selectedItemsCountChanged)="onSelectedItemsCountChanged($event)"
27-
[isResizingEnabled]="true"
28-
[blurOnResize]="false"
29-
(name-click)="handleNodeClick($event)"
30-
>
31-
<adf-custom-empty-content-template>
32-
<adf-empty-content
33-
icon="library_books"
34-
[title]="'APP.BROWSE.LIBRARIES.EMPTY_STATE.FAVORITE_LIBRARIES.TITLE'"
35-
subtitle="APP.BROWSE.LIBRARIES.EMPTY_STATE.FAVORITE_LIBRARIES.TEXT"
36-
/>
37-
</adf-custom-empty-content-template>
38-
39-
<data-columns>
40-
<ng-container *ngFor="let column of columns; trackBy: trackByColumnId">
41-
<ng-container *ngIf="column.template && !(column.desktopOnly && isSmallScreen)">
42-
<data-column
43-
[id]="column.id"
44-
[draggable]="column.draggable"
45-
[resizable]="column.resizable"
46-
[key]="column.key"
47-
[title]="column.title"
48-
[type]="column.type"
49-
[format]="column.format"
50-
[class]="column.class"
51-
[sortable]="column.sortable"
52-
[isHidden]="column.isHidden"
53-
[sortingKey]="column.sortingKey || column.key"
54-
>
55-
<ng-template let-context>
56-
<adf-dynamic-column [id]="column.template" [context]="context" />
57-
</ng-template>
58-
</data-column>
59-
</ng-container>
60-
61-
<ng-container *ngIf="!column.template && !(column.desktopOnly && isSmallScreen)">
62-
<data-column
63-
[id]="column.id"
64-
[key]="column.key"
65-
[draggable]="column.draggable"
66-
[resizable]="column.resizable"
67-
[title]="column.title"
68-
[type]="column.type"
69-
[format]="column.format"
70-
[class]="column.class"
71-
[sortable]="column.sortable"
72-
[isHidden]="column.isHidden"
73-
[sortingKey]="column.sortingKey || column.key"
74-
/>
75-
</ng-container>
76-
</ng-container>
77-
</data-columns>
78-
</adf-document-list>
79-
80-
<adf-pagination
81-
[target]="documentList"
82-
[pagination]="pagination"
83-
(changePageSize)="onChangePageSize($event)"
84-
(changePageNumber)="onChange($event)"
85-
(nextPage)="onChange($event)"
86-
(prevPage)="onChange($event)"
87-
/>
88-
</div>
89-
90-
<div class="aca-sidebar" *ngIf="infoDrawerOpened$ | async">
91-
<aca-info-drawer [node]="selection.last" />
92-
</div>
93-
</div>
94-
</aca-page-layout>
1+
<aca-libraries-base
2+
[list]="list"
3+
[isLoading]="isLoading"
4+
[pagination]="pagination"
5+
[columns]="columns"
6+
[navigateRoute]="'favorite/libraries'"
7+
[titleKey]="'APP.BROWSE.LIBRARIES.MENU.FAVORITE_LIBRARIES.TITLE'"
8+
[emptyTitleKey]="'APP.BROWSE.LIBRARIES.EMPTY_STATE.FAVORITE_LIBRARIES.TITLE'"
9+
[emptySubtitleKey]="'APP.BROWSE.LIBRARIES.EMPTY_STATE.FAVORITE_LIBRARIES.TEXT'"
10+
(changePageSize)="onChangePageSize($event)"
11+
(changePageNumber)="getList($event)"
12+
(nextPage)="getList($event)"
13+
(prevPage)="getList($event)"
14+
/>

projects/aca-content/src/lib/components/favorite-libraries/favorite-libraries.component.spec.ts

Lines changed: 46 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -23,189 +23,129 @@
2323
*/
2424

2525
import { ComponentFixture, TestBed } from '@angular/core/testing';
26-
import { Router } from '@angular/router';
2726
import { UserPreferencesService } from '@alfresco/adf-core';
28-
import { AlfrescoApiService } from '@alfresco/adf-content-services';
2927
import { FavoriteLibrariesComponent } from './favorite-libraries.component';
3028
import { AppTestingModule } from '../../testing/app-testing.module';
31-
import { AppHookService, ContentApiService } from '@alfresco/aca-shared';
29+
import { AppExtensionService, AppHookService, ContentApiService } from '@alfresco/aca-shared';
3230
import { provideEffects } from '@ngrx/effects';
33-
import { RouterEffects } from '@alfresco/aca-shared/store';
3431
import { of, throwError } from 'rxjs';
3532
import { LibraryEffects } from '../../store/effects';
3633
import { NodeEntry } from '@alfresco/js-api';
37-
import { getTitleElementText } from '../../testing/test-utils';
3834
import { MatSnackBarModule } from '@angular/material/snack-bar';
39-
import { SiteEntry } from '@alfresco/js-api/typings';
35+
import { libraryColumnsPresetMock, favoriteLibrariesMock, libraryPaginationMock } from '../../mock/libraries-mock';
4036

4137
describe('FavoriteLibrariesComponent', () => {
4238
let fixture: ComponentFixture<FavoriteLibrariesComponent>;
4339
let component: FavoriteLibrariesComponent;
44-
let alfrescoApi: AlfrescoApiService;
4540
let userPreference: UserPreferencesService;
4641
let contentApiService: ContentApiService;
47-
let router: Router;
48-
let page;
4942
let appHookService: AppHookService;
50-
51-
beforeEach(() => {
52-
page = {
53-
list: {
54-
entries: [{ entry: { id: 1 } }, { entry: { id: 2 } }],
55-
pagination: { data: 'data' }
56-
}
57-
};
58-
});
43+
let appExtensionService: AppExtensionService;
5944

6045
beforeEach(() => {
6146
TestBed.configureTestingModule({
6247
imports: [AppTestingModule, FavoriteLibrariesComponent, MatSnackBarModule],
63-
providers: [provideEffects([RouterEffects, LibraryEffects])]
48+
providers: [provideEffects([LibraryEffects])]
6449
});
6550

6651
fixture = TestBed.createComponent(FavoriteLibrariesComponent);
6752
component = fixture.componentInstance;
6853

69-
alfrescoApi = TestBed.inject(AlfrescoApiService);
7054
contentApiService = TestBed.inject(ContentApiService);
7155
userPreference = TestBed.inject(UserPreferencesService);
7256
appHookService = TestBed.inject(AppHookService);
73-
alfrescoApi.reset();
74-
router = TestBed.inject(Router);
57+
appExtensionService = TestBed.inject(AppExtensionService);
7558

7659
spyOn(contentApiService, 'getNode').and.returnValue(of({ entry: { id: 'libraryId' } } as NodeEntry));
7760
});
7861

79-
describe('on initialization', () => {
80-
it('should set data', () => {
81-
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page));
82-
fixture.detectChanges();
83-
84-
expect(component.list).toBe(page);
85-
expect(component.pagination).toBe(page.list.pagination);
86-
});
87-
88-
it('should get data with user preference pagination size', () => {
89-
userPreference.paginationSize = 1;
90-
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page));
62+
it('should set data', () => {
63+
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(favoriteLibrariesMock));
64+
fixture.detectChanges();
9165

92-
fixture.detectChanges();
66+
expect(component.list).toBe(favoriteLibrariesMock);
67+
expect(component.pagination).toBe(favoriteLibrariesMock.list.pagination);
68+
});
9369

94-
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalledWith('-me-', {
95-
maxItems: userPreference.paginationSize
96-
});
97-
});
70+
it('should get data with user preference pagination size', () => {
71+
userPreference.paginationSize = 1;
72+
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(favoriteLibrariesMock));
9873

99-
it('should set data on error', () => {
100-
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(throwError('error'));
101-
fixture.detectChanges();
74+
fixture.detectChanges();
10275

103-
expect(component.list).toBe(null);
104-
expect(component.pagination).toBe(null);
105-
expect(component.isLoading).toBe(false);
76+
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalledWith('-me-', {
77+
maxItems: userPreference.paginationSize
10678
});
79+
});
10780

108-
it('should set title based on selectedRowItemsCount', () => {
109-
fixture.detectChanges();
110-
111-
expect(getTitleElementText(fixture)).toBe('APP.BROWSE.LIBRARIES.MENU.FAVORITE_LIBRARIES.TITLE');
81+
it('should set data on error', () => {
82+
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(throwError('error'));
83+
fixture.detectChanges();
11284

113-
component.selectedRowItemsCount = 5;
114-
fixture.detectChanges();
115-
116-
expect(getTitleElementText(fixture)).toBe('APP.HEADER.SELECTED');
117-
});
85+
expect(component.list).toBe(null);
86+
expect(component.pagination).toBe(null);
87+
expect(component.isLoading).toBe(false);
11888
});
11989

120-
describe('Node navigation', () => {
121-
it('does not navigate when id is not passed', () => {
122-
spyOn(router, 'navigate').and.stub();
123-
component.navigateTo(null);
124-
125-
expect(router.navigate).not.toHaveBeenCalled();
126-
});
90+
it('should set columns from extensions on init', () => {
91+
appExtensionService.documentListPresets.libraries = libraryColumnsPresetMock;
92+
fixture.detectChanges();
93+
expect(component.columns).toEqual(appExtensionService.documentListPresets.favoriteLibraries);
94+
});
12795

128-
it('does not navigate when id is not passed', () => {
129-
spyOn(router, 'navigate').and.stub();
130-
component.navigateTo({
131-
entry: {
132-
guid: 'test-guid',
133-
visibility: 'PUBLIC',
134-
role: 'SiteConsumer'
135-
}
136-
} as SiteEntry);
137-
138-
expect(router.navigate).toHaveBeenCalledWith(['favorite/libraries', 'libraryId']);
139-
});
96+
it('should handle no columns preset in extensions', () => {
97+
appExtensionService.documentListPresets.favoriteLibraries = undefined;
98+
component.ngOnInit();
99+
expect(component.columns.length).toBe(0);
140100
});
141101

142-
describe('Reload on actions', () => {
102+
describe('Library hooks', () => {
143103
beforeEach(() => {
144-
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page));
104+
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(favoriteLibrariesMock));
145105
fixture.detectChanges();
146106
});
147107

148-
it('should reload on libraryDeleted action', () => {
108+
it('should reload on libraryDeleted hook', () => {
149109
appHookService.libraryDeleted.next('');
150110
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled();
151111
});
152112

153-
it('should reload on libraryUpdated action', () => {
113+
it('should reload on libraryUpdated hook', () => {
154114
appHookService.libraryUpdated.next({} as any);
155115
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled();
156116
});
157117

158-
it('should reload on favoriteLibraryToggle action', () => {
118+
it('should reload on favoriteLibraryToggle hook', () => {
159119
appHookService.favoriteLibraryToggle.next();
160120
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled();
161121
});
162122

163-
it('should reload on libraryJoined action', () => {
123+
it('should reload on libraryJoined hook', () => {
164124
appHookService.libraryJoined.next();
165125
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled();
166126
});
167127

168-
it('should reload on libraryLeft action', () => {
128+
it('should reload on libraryLeft hook', () => {
169129
appHookService.libraryLeft.next({} as any);
170130
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalled();
171131
});
172132
});
173133

174134
describe('Pagination', () => {
175-
let pagination;
176-
177-
beforeEach(() => {
178-
pagination = {
179-
count: 100,
180-
hasMoreItems: true,
181-
totalItems: 300,
182-
skipCount: 25,
183-
maxItems: 25
184-
};
185-
});
186-
187-
it('should get list with pagination data onChange event', () => {
188-
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page));
189-
190-
component.onChange(pagination);
191-
192-
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalledWith('-me-', pagination);
193-
});
194-
195135
it('should get list with pagination data onChangePageSize event', () => {
196-
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page));
136+
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(favoriteLibrariesMock));
197137

198-
component.onChangePageSize(pagination);
138+
component.onChangePageSize(libraryPaginationMock);
199139

200-
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalledWith('-me-', pagination);
140+
expect(contentApiService.getFavoriteLibraries).toHaveBeenCalledWith('-me-', libraryPaginationMock);
201141
});
202142

203143
it('should set preference page size onChangePageSize event', () => {
204-
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(page));
144+
spyOn(contentApiService, 'getFavoriteLibraries').and.returnValue(of(favoriteLibrariesMock));
205145

206-
component.onChangePageSize(pagination);
146+
component.onChangePageSize(libraryPaginationMock);
207147

208-
expect(userPreference.paginationSize).toBe(pagination.maxItems);
148+
expect(userPreference.paginationSize).toBe(libraryPaginationMock.maxItems);
209149
});
210150
});
211151
});

0 commit comments

Comments
 (0)